Fixing some small registration and login isues
This commit is contained in:
parent
5aa2feff7b
commit
9ed5089508
8 changed files with 66 additions and 44 deletions
|
|
@ -39,6 +39,6 @@ Template.login.events({
|
|||
},
|
||||
'click #reg' (event) {
|
||||
event.preventDefault();
|
||||
FlowRouter.go('/reg');
|
||||
Session.set("loginOrReg", "reg");
|
||||
},
|
||||
});
|
||||
|
|
@ -96,12 +96,17 @@ Template.reg.events({
|
|||
let userId = Meteor.userId();
|
||||
// console.log("User ID: " + userId);
|
||||
const addRole = async() => {
|
||||
let result = await Meteor.callAsync("addToRole", "user");
|
||||
if (!result) {
|
||||
console.log(" ERROR: ROLES - Error adding user to role: ");
|
||||
} else {
|
||||
// console.log("User should be added to role - teacher.");
|
||||
FlowRouter.go('/dashboard');
|
||||
try {
|
||||
let result = await Meteor.callAsync("addToRole", "user");
|
||||
if (!result) {
|
||||
throw Meteor.error("Failed to create role.", error.message);
|
||||
} else {
|
||||
console.log("Result is: " + result)
|
||||
FlowRouter.go('/home');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log(" ERROR: ROLES - Error adding user to role: ", error.message);
|
||||
}
|
||||
}
|
||||
addRole();
|
||||
|
|
@ -132,6 +137,6 @@ Template.reg.events({
|
|||
},
|
||||
'click #login' (event) {
|
||||
event.preventDefault();
|
||||
FlowRouter.go('/login');
|
||||
Session.set("loginOrReg", "login");
|
||||
},
|
||||
});
|
||||
|
|
@ -1,3 +1,11 @@
|
|||
<template name="home">
|
||||
<h1>This is Home.</h1>
|
||||
{{#if currentUser}}
|
||||
<h1>This is Home.</h1>
|
||||
{{else}}
|
||||
{{#if $eq loginOrReg 'login'}}
|
||||
{{> login}}
|
||||
{{else}}
|
||||
{{> reg}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</template>
|
||||
|
|
@ -1,5 +1,11 @@
|
|||
import { FlowRouter } from 'meteor/ostrio:flow-router-extra';
|
||||
|
||||
Template.home.helpers({
|
||||
loginOrReg: function() {
|
||||
return Session.get("loginOrReg");
|
||||
},
|
||||
});
|
||||
|
||||
Template.home.events({
|
||||
|
||||
});
|
||||
|
|
@ -13,7 +13,11 @@
|
|||
<li><a href="#!"><i class="material-icons" id='dashboard'>notifications</i></a></li>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<li><a href="#!" id="login" class="navBtn">Login</a></li>
|
||||
{{#if $eq loginOrReg 'login'}}
|
||||
<li><a href="#!" id="reg" class="navBtn">Register</a></li>
|
||||
{{else}}
|
||||
<li><a href="#!" id="login" class="navBtn">Sign In</a></li>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</ul>
|
||||
</nav>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ Template.headerBar.onCreated(function() {
|
|||
});
|
||||
|
||||
Template.headerBar.onRendered(function() {
|
||||
|
||||
Session.set("loginOrReg", "login");
|
||||
});
|
||||
|
||||
Template.headerBar.helpers({
|
||||
|
|
@ -26,15 +26,22 @@ Template.headerBar.helpers({
|
|||
return false;
|
||||
}
|
||||
},
|
||||
loginOrReg: function() {
|
||||
return Session.get("loginOrReg");
|
||||
},
|
||||
});
|
||||
|
||||
Template.headerBar.events({
|
||||
'click .navBtn' (event) {
|
||||
event.preventDefault();
|
||||
var clickedTarget = event.target.id;
|
||||
// console.log("clicked " + clickedTarget);
|
||||
console.log("clicked " + clickedTarget);
|
||||
if (clickedTarget == 'mainMenu') {
|
||||
FlowRouter.go('/');
|
||||
} else if (clickedTarget == 'login') {
|
||||
Session.set("loginOrReg", "login");
|
||||
} else if (clickedTarget == 'reg') {
|
||||
Session.set("loginOrReg", "reg");
|
||||
} else {
|
||||
// console.log("should be going to /" + clickedTarget);
|
||||
FlowRouter.go('/' + clickedTarget);
|
||||
|
|
|
|||
|
|
@ -2,11 +2,8 @@
|
|||
{{#if Template.subscriptionsReady}}
|
||||
<div class="container">
|
||||
{{> headerBar}}
|
||||
{{#if currentUser}}
|
||||
{{> Template.dynamic template=main}}
|
||||
{{else}}
|
||||
{{> Template.dynamic template=notLoggedIn}}
|
||||
{{/if}}
|
||||
{{> Template.dynamic template=main}}
|
||||
|
||||
</div>
|
||||
{{/if}}
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -4,28 +4,25 @@ import { check } from 'meteor/check';
|
|||
import { Roles } from 'meteor/roles';
|
||||
|
||||
Meteor.methods({
|
||||
'addToRole' (role) {
|
||||
const getUserInfo = async() => {
|
||||
try {
|
||||
let countOfUsers = await Meteor.users.find().countAsync();
|
||||
const user = await Meteor.userAsync();
|
||||
if (user) {
|
||||
let userId = user._id;
|
||||
if (countOfUsers > 1) {
|
||||
Roles.addUsersToRolesAysnc(userId, role);
|
||||
} else if (countOfUsers == 1) {
|
||||
Roles.addUsersToRolesAsync(userId, "systemadmin");
|
||||
} else {
|
||||
console.log("The count of users didn't seem to work when adding a new user.");
|
||||
}
|
||||
async 'addToRole' (role) {
|
||||
try {
|
||||
const user = await Meteor.userAsync();
|
||||
let countOfUsers = await Meteor.users.find().countAsync();
|
||||
if (user) {
|
||||
let userId = user._id;
|
||||
if (countOfUsers > 1) {
|
||||
await Roles.addUsersToRolesAsync(userId, role);
|
||||
} else if (countOfUsers == 1) {
|
||||
await Roles.addUsersToRolesAsync(userId, "systemadmin");
|
||||
} else {
|
||||
console.log(" ---- No user info found.")
|
||||
console.log("The count of users didn't seem to work when adding a new user.");
|
||||
}
|
||||
} catch(error) {
|
||||
console.log(" ERROR getting user info on server: " + error);
|
||||
} else {
|
||||
console.log(" ---- No user info found.")
|
||||
}
|
||||
}
|
||||
getUserInfo();
|
||||
} catch(error) {
|
||||
console.log(" ERROR getting user info on server: " + error);
|
||||
}
|
||||
},
|
||||
'edit.userPass' (userId, newPassword) {
|
||||
check(userId, String);
|
||||
|
|
@ -44,28 +41,26 @@ Meteor.methods({
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
'delete.userFromSys' (userId) {
|
||||
async 'delete.userFromSys' (userId) {
|
||||
check(userId, String);
|
||||
|
||||
return Meteor.users.remove({ _id: userId });
|
||||
return await Meteor.users.removeAsync({ _id: userId });
|
||||
},
|
||||
'update.userEmail' (userId, email) {
|
||||
async 'update.userEmail' (userId, email) {
|
||||
check(userId, String);
|
||||
check(email, String);
|
||||
|
||||
return Meteor.users.update({ _id: userId }, {
|
||||
return await Meteor.users.updateAsync({ _id: userId }, {
|
||||
$set: {
|
||||
'emails.0.address': email,
|
||||
}
|
||||
});
|
||||
},
|
||||
'edit.userRole' (userId, role) {
|
||||
async 'edit.userRole' (userId, role) {
|
||||
check(userId, String);
|
||||
check(role, String);
|
||||
|
||||
return Roles.setUserRoles(userId, role);
|
||||
return await Roles.setUserRolesAsync(userId, role);
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue