let username = template.find('#login-username').value;
let user = Users.findOne({ username: username });
// Short circuit this mamma-jamma, the user is not activated.
if (!user.activated) { return; }
Meteor.loginWithPassword(username, password, function(error) {
}
i think @sergiotapia provide a good answer, you can further modify it
var profile = Users.findOne({ username: username },{profile:1, _id:0});
if (profile.actived){
Meteor.loginWithPassword(username, password, function(error) {
}
Template.signup.helpers({
//add you helpers here
});
Template.signup.events({
//add your events here
"submit #signup-form": function(event, template) {
event.preventDefault();
Accounts.createUser({
username: template.find("#signup-staffid").value,
password: template.find("#signup-password").value,
profile: {
firstname: template.find("#signup-firstname").value,
lastname: template.find("#signup-lastname").value,
phonenumber: template.find("#signup-phone").value,
user: 'Staff',
AccountStatus: 'Not Activated'
// Other required field values can go here
}
}, function(error) {
if (error) {
// Display the user creation error to the user however you want
alert(error.reason);
} else{
alert("Registered Successfully");
}
});
},
"submit #regstudent-form": function(event, template) {
event.preventDefault();
Accounts.createUser({
username: template.find("#regstudent-regno").value,
password: template.find("#regstudent-password").value,
profile: {
firstname: template.find("#regstudent-firstname").value,
lastname: template.find("#regstudent-lastname").value,
phonenumber: template.find("#regstudent-phone").value,
user: 'Student',
AccountStatus: 'Not Activated'
// Other required field values can go here
}
}, function(error) {
if (error) {
// Display the user creation error to the user however you want
alert(error.reason);
} else{
alert("Registered Successfully");
}
});
}
});
}
Template.login.helpers({
//add you helpers here
});
Template.login.events({
//add your events here
'click .regStaff' : function () {
Modal.show('signup');
},
"submit #login": function(event, template) {
event.preventDefault();
var username = template.find('#login-username').value,
password = template.find('#login-password').value;
// profile = Meteor.users.findOne({ username: username }, {'profile.AccountStatus': 'Activated'});
// Short circuit this mamma-jamma, the user is not activated.
//if (profile.Activated) { //return; }
Meteor.loginWithPassword(username, password, function(error) {
// function(error)
if (error) {
alert(error.reason);
// Display the login error to the user however you want
} else {
Router.go('/');
}
}
);
}
});
this is my login.js code tried your method and it’s still not working
Accounts.onLogin(function(){
if(Meteor.user().profile && Meteor.user().profile.AccountStatus === "Activated"){
//all well, route to home
} else {show error and sign out user}
}
I would suggest to use a boolean ‘isActive’ though, rather than testing strings
Thank you all for your assistance, the problem i have now is if the user is not deactivated. the dialog error box pops up and doesnt close until i click close multiple times.
"submit #login": function(event, template) {
event.preventDefault();
var username = template.find('#login-username').value,
password = template.find('#login-password').value;
Accounts.onLogin(function() {
if (Meteor.user().profile && Meteor.user().profile.AccountStatus === "Activated") {
//all well, route to home
Router.go('/');
} else
{
alert("Account is inactive, Please contact Admin");
}
})
}
);
}