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