The administrator of this system has disabled registration. If you believe you should be allowed to register to use this system, please contact the system administrator for assistance.
+ {{/if}} + {{/if}} + {{> snackbar}} + \ No newline at end of file diff --git a/client/Accounts/Login/reg.js b/client/Accounts/Login/reg.js new file mode 100644 index 0000000..e6be5d5 --- /dev/null +++ b/client/Accounts/Login/reg.js @@ -0,0 +1,142 @@ +import { Meteor } from 'meteor/meteor'; +import { FlowRouter } from 'meteor/ostrio:flow-router-extra'; +import { SysConfig } from '../../../imports/api/systemConfig'; + +Template.reg.onCreated(function() { + this.subscribe("SystemConfig"); +}); + +Template.reg.onRendered(function() { + Session.set("canReg", false); + Session.set("missingReq", false); + Session.set("missingName", false); + Session.set("missingEmail", false); + Session.set("missingPassword", false); + Session.set("passMatch", true); +}); + +Template.reg.helpers({ + canReg: function() { + return Session.get("canReg"); + }, + misName: function() { + return Session.get("missingName"); + }, + misEmail: function() { + return Session.get("missingEmail"); + }, + misPass: function() { + return Session.get("missingPassword"); + }, + misReq: function() { + return Session.get("missingReq"); + }, + passMatch: function() { + return Session.get("passMatch"); + }, + allowReg: async() => { + const conf = await SysConfig.findOneAsync(); + try { + if (typeof conf != 'undefined') { + return conf.allowReg; + } else { + return true + } + } catch(error) { + console.log(" ERROR getting registration allowed info: " + error); + } + + } +}); + +Template.reg.events({ + 'click #registerMe' (event) { + event.preventDefault(); + if (Session.get("canreg") == false) { + // console.log("reg disabled."); + } else { + // console.log("Clicked"); + let missingName = false; + let missingEmail = false; + let missingPassword = false; + + let email = $("#email").val(); + let password = $("#password").val(); + let name = $("#name").val(); + + if (name == "" || name == null) { + missingName = true; + Session.set("missingName", true); + } + + if (email == "" || email == null) { + missingEmail = true; + Session.set("missingEmail", true); + } + + if (password == "" || password == null) { + missingPassword = true; + Session.set("missingPassword", true); + } + + let userId; + + if (missingName == true || missingEmail == true || missingPassword == true) { + Session.set("missingReq", true); + } else { + Session.set("missingReq", false); + Accounts.createUser({ + email: email, + password: password, + profile: { + fullname: name, + } + }); + + let userId = Meteor.userId(); + // console.log("User ID: " + userId); + const addRole = async() => { + 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(); + } + } + }, + 'keyup #passwordConfirm' (event) { + let pwd = $("#password").val(); + let pwdconf = $("#passwordConfirm").val(); + + if (pwd == pwdconf) { + // console.log("passwords match"); + Session.set("canreg", true); + } else { + // console.log("passwords don't match"); + Session.set("canreg", false); + } + }, + 'change #email' (event) { + let email = $("#email").val(); + var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; + let isEmail = regex.test(email); + if (isEmail == false) { + Session.set("missingEmail", true); + } else { + Session.set("missingEmail", false); + } + }, + 'click #login' (event) { + event.preventDefault(); + Session.set("loginOrReg", "login"); + }, +}); \ No newline at end of file diff --git a/client/Accounts/UserMgmt/userInfoModal.html b/client/Accounts/UserMgmt/userInfoModal.html new file mode 100644 index 0000000..e25fda3 --- /dev/null +++ b/client/Accounts/UserMgmt/userInfoModal.html @@ -0,0 +1,45 @@ + + + {{> snackbar}} + \ No newline at end of file diff --git a/client/Accounts/UserMgmt/userInfoModal.js b/client/Accounts/UserMgmt/userInfoModal.js new file mode 100644 index 0000000..e1bfc4f --- /dev/null +++ b/client/Accounts/UserMgmt/userInfoModal.js @@ -0,0 +1,145 @@ + + +Template.userInfoModal.onCreated(function() { + this.subscribe("rolesAvailable"); +}); + +Template.userInfoModal.onRendered(function() { + Session.set("passMatch", true); + Session.set("passErr", false); + Session.set("userEmailErr", false); + Session.set("userRoleErr", false); +}); + +Template.userInfoModal.helpers({ + passMatch: function() { + return Session.get("passMatch"); + }, + emailEmpty: function() { + return Session.get("userEmailErr"); + }, + roleEmpty: function() { + return Session.get("userRoleErr"); + }, + userInfo: function() { + let usersId = Session.get("usersId"); + if (usersId != "" && usersId != null) { + let usersInfo = Meteor.users.findOne({ _id: usersId }); + // console.dir(usersInfo); + Session.set("usersInfo", usersInfo); + return usersInfo; + } else { + return; + } + }, + userRole: function() { + let userRole = Roles.getRolesForUser( Session.get("usersId")); + Session.set("usersRole", userRole); + console.log(userRole); + return userRole; + }, + rolesOptions: function() { + return Roles.find(); + } +}); + +Template.userInfoModal.events({ + "click #saveChanges" (event) { + event.preventDefault(); + let usersId = Session.get("usersId"); + let passwd = $("#newPass").val(); + let usersEmail = $("#usersEmail").val(); + let userRole = $("#userRole").val(); + let userInfo = Session.get("usersInfo"); + + let currEmail = userInfo.emails[0].address; + let userDbRole = Session.get("usersRole"); + + let currRole = userDbRole[0]; + + let passMatch = Session.get("passMatch"); + if (passMatch == false) { + Session.set("passErr", true); + return; + } else { + Session.set("passErr", false); + } + + if (usersEmail == null || usersEmail == "") { + Session.set("userEmailErr", true); + return; + } else { + Session.set("userEmailErr", false); + } + + if (userRole == null || userRole == "") { + Session.set("userRoleErr", true); + return; + } else { + Session.set("userRoleErr", false); + } + + if (passMatch == true || passMatch == "NA") { + if (passwd != "" && passwd != null) { + // need to account for the admin changing passwords and userRole or Email + changePassword(usersId, passwd); + } + + if (usersEmail != null && usersEmail != "" && usersEmail != currEmail) { + changeUserEmail(usersId, usersEmail); + } + + if (userRole != null && userRole != "" && userRole != currRole) { + changeUserRole(usersId, userRole); + } + } + }, + "click #closePass" (event) {; + + }, + "keyup #newPassConf" (event) { + let newPass = $("#newPass").val(); + let newPassConf = $("#newPassConf").val(); + if (newPassConf.length > 2 && (newPass != null || newPass != "")) { + if (newPass != newPassConf) { + Session.set("passMatch", false); + } else { + Session.set("passMatch", true); + } + } + } +}); + +changePassword = function(userId, passwd) { + console.log("would change password."); + Meteor.call('edit.userPass', userId, passwd, function(err, result) { + if (err) { + console.log(" ERROR changing user passwrod:" + err); + } else { + showSnackbar("Successfully Saved Changes!", "green"); + console.log(" Password changed successfully!"); + } + }); +} + +changeUserEmail = function(usersId, usersEmail) { + console.log("Would change user email"); + Meteor.call('update.userEmail', usersId, usersEmail, function(err, result) { + if (err) { + console.log(" ERROR updating user email: " + err); + } else { + showSnackbar("Email updated successfully!", "green"); + } + }); +} + +changeUserRole = function(userId, role) { + console.log("Would change user Role."); + Meteor.call('edit.userRole', userId, role, function(err, result) { + if (err) { + console.log(" ERROR updating user role: " + err); + } else { + showSnackbar("Role Successfully Updated!", "green"); + } + }); +} \ No newline at end of file diff --git a/client/Accounts/UserMgmt/userMgmt.html b/client/Accounts/UserMgmt/userMgmt.html new file mode 100644 index 0000000..83314de --- /dev/null +++ b/client/Accounts/UserMgmt/userMgmt.html @@ -0,0 +1,36 @@ + + {{#if isInRole 'systemadmin'}} +| Name | +Role | +Actions | +|
|---|---|---|---|
| {{userName}} | +{{userEmail}} | +{{userRole}} | +
+
+ delete
+ edit
+
+ |
+
This option requires the seerver to have an internet connection.
+