From 45b78101c87ba0fdf3968edde3538ca886dae0e9 Mon Sep 17 00:00:00 2001 From: Brian McGonagill Date: Fri, 9 Jun 2023 13:38:10 -0500 Subject: [PATCH] Adding edit and delete users from system. --- client/Accounts/UserMgmt/userInfoModal.html | 25 +++++++++++ client/Accounts/UserMgmt/userInfoModal.js | 50 +++++++++++++++++++++ client/Accounts/UserMgmt/userMgmt.html | 4 +- client/Accounts/UserMgmt/userMgmt.js | 8 ++-- imports/api/userConfigOptions.js | 6 +++ 5 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 client/Accounts/UserMgmt/userInfoModal.html create mode 100644 client/Accounts/UserMgmt/userInfoModal.js diff --git a/client/Accounts/UserMgmt/userInfoModal.html b/client/Accounts/UserMgmt/userInfoModal.html new file mode 100644 index 0000000..0ef88a5 --- /dev/null +++ b/client/Accounts/UserMgmt/userInfoModal.html @@ -0,0 +1,25 @@ + \ 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..5fac19d --- /dev/null +++ b/client/Accounts/UserMgmt/userInfoModal.js @@ -0,0 +1,50 @@ +Template.userInfoModal.onCreated(function() { + +}); + +Template.userInfoModal.onRendered(function() { + Session.set("passMatch", true); + Session.set("passErr", false); + $('.modal').modal(); +}); + +Template.userInfoModal.helpers({ + passMatch: function() { + return Session.get("passMatch"); + } +}); + +Template.userInfoModal.events({ + "click #chPass" (event) { + event.preventDefault(); + let usersId = Session.get("usersId"); + let passwd = $("#newPass").val(); + let passMatch = Session.get("passMatch"); + if (passwd == null || passwd == "" || passMatch == false) { + Session.set("passErr", true); + return; + } else { + Meteor.call('change.userPass', usersId, passwd, function(err, result) { + if (err) { + console.log(" ERROR changing user passwrod:" + err); + } else { + console.log(" Password changed successfully!"); + } + }); + } + }, + "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); + } + } + } +}); \ No newline at end of file diff --git a/client/Accounts/UserMgmt/userMgmt.html b/client/Accounts/UserMgmt/userMgmt.html index 9bbd86f..9cd438a 100644 --- a/client/Accounts/UserMgmt/userMgmt.html +++ b/client/Accounts/UserMgmt/userMgmt.html @@ -20,7 +20,7 @@ {{userRole}}
- delete + delete edit
@@ -31,4 +31,6 @@ {{/if}} + {{> deleteConfirmationModal}} + {{> userInfoModal}} \ No newline at end of file diff --git a/client/Accounts/UserMgmt/userMgmt.js b/client/Accounts/UserMgmt/userMgmt.js index 7472ce5..3052211 100644 --- a/client/Accounts/UserMgmt/userMgmt.js +++ b/client/Accounts/UserMgmt/userMgmt.js @@ -6,6 +6,7 @@ Template.userMgmt.onCreated(function() { Template.userMgmt.onRendered(function() { $('select').formSelect(); + $('.modal').modal(); }); Template.userMgmt.helpers({ @@ -29,7 +30,8 @@ Template.userMgmt.events({ let userId = this._id; // take action - console.log("Edit called on: " + userId); + Session.set("usersId", userId); + $("#userInfoModal").modal('open'); }, "click .deleteUser" (event) { event.preventDefault(); @@ -41,8 +43,6 @@ Template.userMgmt.events({ Session.set("item", "User"); Session.set("view", "Users"); Session.set("method", "delete.userFromSys"); - Meteor.setTimeout(function() { - $('.modal').open('modalDelete'); - }, 150); + $('#modalDelete').modal('open'); } }); \ No newline at end of file diff --git a/imports/api/userConfigOptions.js b/imports/api/userConfigOptions.js index 9198d9c..f20d37b 100644 --- a/imports/api/userConfigOptions.js +++ b/imports/api/userConfigOptions.js @@ -29,4 +29,10 @@ Meteor.methods({ } }); }, + 'change.userPass' (usersId, password) { + check(usersId, String); + check(password, String); + + return Accounts.setPassword(usersId, password); + }, }); \ No newline at end of file