From ccda2a968b6a58dafd1ff5dc4459a0bd579069d3 Mon Sep 17 00:00:00 2001 From: zharding Date: Sun, 9 Jul 2017 12:28:53 -0700 Subject: [PATCH 1/7] Refactored 'user-set-password.html.twig' Refactored the modal 'user-set-password.html.twig'. Created 'forms/user-set-password.html.twig' and included it in the modal. Also created 'forms/partials/user-set-password.html.twig' to seperate the controls for setting the users password for reuse elsewhere. --- .../partials/user-set-password.html.twig | 37 ++++++++++++ .../forms/user-set-password.html.twig | 21 +++++++ .../modals/user-set-password.html.twig | 57 +------------------ 3 files changed, 59 insertions(+), 56 deletions(-) create mode 100644 app/sprinkles/admin/templates/forms/partials/user-set-password.html.twig create mode 100644 app/sprinkles/admin/templates/forms/user-set-password.html.twig diff --git a/app/sprinkles/admin/templates/forms/partials/user-set-password.html.twig b/app/sprinkles/admin/templates/forms/partials/user-set-password.html.twig new file mode 100644 index 000000000..b618a525f --- /dev/null +++ b/app/sprinkles/admin/templates/forms/partials/user-set-password.html.twig @@ -0,0 +1,37 @@ + + + +
+
+ +
+
+
+
+ +
+
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+
\ No newline at end of file diff --git a/app/sprinkles/admin/templates/forms/user-set-password.html.twig b/app/sprinkles/admin/templates/forms/user-set-password.html.twig new file mode 100644 index 000000000..0299f32d7 --- /dev/null +++ b/app/sprinkles/admin/templates/forms/user-set-password.html.twig @@ -0,0 +1,21 @@ +
+ {% include "forms/csrf.html.twig" %} +
+
+
+ {% include "forms/partials/user-set-password.html.twig" %} +
+
+
+
+ +
+
+ +
+
+
+ + \ No newline at end of file diff --git a/app/sprinkles/admin/templates/modals/user-set-password.html.twig b/app/sprinkles/admin/templates/modals/user-set-password.html.twig index 922d4e268..78552d6f8 100644 --- a/app/sprinkles/admin/templates/modals/user-set-password.html.twig +++ b/app/sprinkles/admin/templates/modals/user-set-password.html.twig @@ -3,60 +3,5 @@ {% block modal_title %}{{translate("USER.ADMIN.CHANGE_PASSWORD")}}{% endblock %} {% block modal_body %} -
- {% include "forms/csrf.html.twig" %} - - - -
-
-
-
-
- -
-
-
-
- -
-
-
-
- -
- - -
-
-
- -
- - -
-
-
-
-
-

-
-
- -
-
- -
-
-
- - + {% include "forms/user-set-password.html.twig" %} {% endblock %} From 6fda9bab81c0226b2525da9456f607e875cbf0da Mon Sep 17 00:00:00 2001 From: zharding Date: Sun, 9 Jul 2017 13:56:31 -0700 Subject: [PATCH 2/7] Admin Ability to Set pass for new user When creating a user you can now set the password manually or force the user to create one. Previously an email was the only option and hindered the creation of a user if the email settings were not configured at all or incorrectly. --- .../assets/userfrosting/js/widgets/users.js | 40 +++++++++++++++++- .../admin/schema/requests/user/create.yaml | 29 +++++++++++++ .../admin/src/Controller/UserController.php | 41 +++++++++++-------- .../admin/templates/forms/user.html.twig | 3 ++ 4 files changed, 95 insertions(+), 18 deletions(-) diff --git a/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js b/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js index 2e153e51a..eb777abd5 100644 --- a/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js +++ b/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js @@ -20,13 +20,51 @@ function attachUserForm() { validators: page.validators }).on("submitSuccess.ufForm", function() { // Reload page on success - window.location.reload(); + //window.location.reload(); + }); + + toggleSetPasswordMode(modal, 'link'); + + // On submission, submit either the PUT request, or POST for a password reset, depending on the toggle state + modal.find("input[name='change_password_mode']").click(function() { + var changePasswordMode = $(this).val(); + toggleSetPasswordMode(modal, changePasswordMode); }); }); } /** * Enable/disable password fields when switch is toggled + * Applies to 'creating' a user + */ +function toggleSetPasswordMode(el, changePasswordMode) { + var form = el.find("form"); + if (changePasswordMode == 'link') { + $(".controls-password").find("input[type='password']").prop('disabled', true); + // Form submits password reset request + + var validator = form.validate(); + if (validator) { + //Iterate through named elements inside of the form, and mark them as error free + el.find("input[type='password']").each(function() { + validator.successList.push(this); //mark as error free + }); + validator.resetForm();//remove error class on name elements and clear history + validator.reset();//remove all error and success data + } + el.find("input[type='password']").closest('.form-group') + .removeClass('has-error has-success'); + el.find('.form-control-feedback').each(function () { + $(this).remove(); + }); + } else { + $(".controls-password").find("input[type='password']").prop('disabled', false); + } +} + +/** + * Enable/disable password fields when switch is toggled + * Applies to 'reseting' a users password */ function toggleChangePasswordMode(el, userName, changePasswordMode) { var form = el.find("form"); diff --git a/app/sprinkles/admin/schema/requests/user/create.yaml b/app/sprinkles/admin/schema/requests/user/create.yaml index 7e575bc69..9094a765f 100644 --- a/app/sprinkles/admin/schema/requests/user/create.yaml +++ b/app/sprinkles/admin/schema/requests/user/create.yaml @@ -70,3 +70,32 @@ group_id: label: "&GROUP" domain: server message: VALIDATE.INTEGER +value: + validators: + required: + domain: client + label: "&PASSWORD" + message: VALIDATE.REQUIRED + length: + domain: client + label: "&PASSWORD" + min: 12 + max: 100 + message: VALIDATE.LENGTH_RANGE +passwordc: + validators: + required: + domain: client + label: "&PASSWORD.CONFIRM" + message: VALIDATE.REQUIRED + matches: + domain: client + field: value + label: "&PASSWORD.CONFIRM" + message: VALIDATE.PASSWORD_MISMATCH + length: + domain: client + label: "&PASSWORD.CONFIRM" + min: 12 + max: 100 + message: VALIDATE.LENGTH_RANGE diff --git a/app/sprinkles/admin/src/Controller/UserController.php b/app/sprinkles/admin/src/Controller/UserController.php index 76ca90245..f36cf75a3 100644 --- a/app/sprinkles/admin/src/Controller/UserController.php +++ b/app/sprinkles/admin/src/Controller/UserController.php @@ -118,9 +118,13 @@ public function create($request, $response, $args) } $data['flag_verified'] = 1; - // Set password as empty on initial creation. We will then send email so new user can set it themselves via a verification token - $data['password'] = ''; - + if(!isset($data['value'])){ + // Set password as empty on initial creation. We will then send email so new user can set it themselves via a verification token + $data['password'] = ''; + }else{ + $data['password'] = Password::hash($data['value']); + } + // All checks passed! log events/activities, create user, and send verification email (if required) // Begin transaction - DB will be rolled back if an exception occurs Capsule::transaction( function() use ($classMapper, $data, $ms, $config, $currentUser) { @@ -135,7 +139,7 @@ public function create($request, $response, $args) 'type' => 'account_create', 'user_id' => $currentUser->id ]); - + // Load default roles $defaultRoleSlugs = $classMapper->staticMethod('role', 'getDefaultSlugs'); $defaultRoles = $classMapper->staticMethod('role', 'whereIn', 'slug', $defaultRoleSlugs)->get(); @@ -147,19 +151,22 @@ public function create($request, $response, $args) // Try to generate a new password request $passwordRequest = $this->ci->repoPasswordReset->create($user, $config['password_reset.timeouts.create']); - // Create and send welcome email with password set link - $message = new TwigMailMessage($this->ci->view, 'mail/password-create.html.twig'); - - $message->from($config['address_book.admin']) - ->addEmailRecipient(new EmailRecipient($user->email, $user->full_name)) - ->addParams([ - 'user' => $user, - 'create_password_expiration' => $config['password_reset.timeouts.create'] / 3600 . ' hours', - 'token' => $passwordRequest->getToken() - ]); - - $this->ci->mailer->send($message); - + // If the password_mode is manual, do not send an email to set it. Else, send the email. + if(!isset($data['value'])){ + // Create and send welcome email with password set link + $message = new TwigMailMessage($this->ci->view, 'mail/password-create.html.twig'); + + $message->from($config['address_book.admin']) + ->addEmailRecipient(new EmailRecipient($user->email, $user->full_name)) + ->addParams([ + 'user' => $user, + 'create_password_expiration' => $config['password_reset.timeouts.create'] / 3600 . ' hours', + 'token' => $passwordRequest->getToken() + ]); + + $this->ci->mailer->send($message); + } + $ms->addMessageTranslated('success', 'USER.CREATED', $data); }); diff --git a/app/sprinkles/admin/templates/forms/user.html.twig b/app/sprinkles/admin/templates/forms/user.html.twig index 471c87ccc..bc338a482 100644 --- a/app/sprinkles/admin/templates/forms/user.html.twig +++ b/app/sprinkles/admin/templates/forms/user.html.twig @@ -108,6 +108,9 @@ {% endif %} + {% if 'password' not in form.fields.hidden %} + {% include "forms/partials/user-set-password.html.twig" %} + {% endif %} {% endblock %}
From dc668d8403467782f3ce6c60be9f92640b2bfe97 Mon Sep 17 00:00:00 2001 From: zharding Date: Sun, 9 Jul 2017 13:59:28 -0700 Subject: [PATCH 3/7] Fix commenting out 'window.location.reload();' --- app/sprinkles/admin/assets/userfrosting/js/widgets/users.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js b/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js index eb777abd5..7027b22d8 100644 --- a/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js +++ b/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js @@ -20,7 +20,7 @@ function attachUserForm() { validators: page.validators }).on("submitSuccess.ufForm", function() { // Reload page on success - //window.location.reload(); + window.location.reload(); }); toggleSetPasswordMode(modal, 'link'); From 420c10b49fc46980368fda11bed835c178433ff3 Mon Sep 17 00:00:00 2001 From: zharding Date: Sun, 9 Jul 2017 14:12:49 -0700 Subject: [PATCH 4/7] Update Style - PSR-1/2 --- .../assets/userfrosting/js/widgets/users.js | 8 ++-- .../admin/src/Controller/UserController.php | 48 +++++++++---------- .../admin/templates/forms/user.html.twig | 2 +- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js b/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js index 7027b22d8..fa0ede746 100644 --- a/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js +++ b/app/sprinkles/admin/assets/userfrosting/js/widgets/users.js @@ -22,8 +22,8 @@ function attachUserForm() { // Reload page on success window.location.reload(); }); - - toggleSetPasswordMode(modal, 'link'); + + toggleSetPasswordMode(modal, 'link'); // On submission, submit either the PUT request, or POST for a password reset, depending on the toggle state modal.find("input[name='change_password_mode']").click(function() { @@ -104,7 +104,7 @@ function toggleChangePasswordMode(el, userName, changePasswordMode) { * Update user field(s) */ function updateUser(userName, fieldName, fieldValue) { - var data = { + var data = { 'value': fieldValue }; @@ -136,7 +136,7 @@ function updateUser(userName, fieldName, fieldValue) { } } } - }).fail(function (jqXHR) { + }).fail(function (jqXHR) { // Error messages if (debugAjax && jqXHR.responseText) { document.write(jqXHR.responseText); diff --git a/app/sprinkles/admin/src/Controller/UserController.php b/app/sprinkles/admin/src/Controller/UserController.php index f36cf75a3..7617179db 100644 --- a/app/sprinkles/admin/src/Controller/UserController.php +++ b/app/sprinkles/admin/src/Controller/UserController.php @@ -118,13 +118,13 @@ public function create($request, $response, $args) } $data['flag_verified'] = 1; - if(!isset($data['value'])){ - // Set password as empty on initial creation. We will then send email so new user can set it themselves via a verification token - $data['password'] = ''; - }else{ - $data['password'] = Password::hash($data['value']); - } - + if(!isset($data['value'])){ + // Set password as empty on initial creation. We will then send email so new user can set it themselves via a verification token + $data['password'] = ''; + }else{ + $data['password'] = Password::hash($data['value']); + } + // All checks passed! log events/activities, create user, and send verification email (if required) // Begin transaction - DB will be rolled back if an exception occurs Capsule::transaction( function() use ($classMapper, $data, $ms, $config, $currentUser) { @@ -139,7 +139,7 @@ public function create($request, $response, $args) 'type' => 'account_create', 'user_id' => $currentUser->id ]); - + // Load default roles $defaultRoleSlugs = $classMapper->staticMethod('role', 'getDefaultSlugs'); $defaultRoles = $classMapper->staticMethod('role', 'whereIn', 'slug', $defaultRoleSlugs)->get(); @@ -151,22 +151,22 @@ public function create($request, $response, $args) // Try to generate a new password request $passwordRequest = $this->ci->repoPasswordReset->create($user, $config['password_reset.timeouts.create']); - // If the password_mode is manual, do not send an email to set it. Else, send the email. - if(!isset($data['value'])){ - // Create and send welcome email with password set link - $message = new TwigMailMessage($this->ci->view, 'mail/password-create.html.twig'); - - $message->from($config['address_book.admin']) - ->addEmailRecipient(new EmailRecipient($user->email, $user->full_name)) - ->addParams([ - 'user' => $user, - 'create_password_expiration' => $config['password_reset.timeouts.create'] / 3600 . ' hours', - 'token' => $passwordRequest->getToken() - ]); - - $this->ci->mailer->send($message); - } - + // If the password_mode is manual, do not send an email to set it. Else, send the email. + if(!isset($data['value'])){ + // Create and send welcome email with password set link + $message = new TwigMailMessage($this->ci->view, 'mail/password-create.html.twig'); + + $message->from($config['address_book.admin']) + ->addEmailRecipient(new EmailRecipient($user->email, $user->full_name)) + ->addParams([ + 'user' => $user, + 'create_password_expiration' => $config['password_reset.timeouts.create'] / 3600 . ' hours', + 'token' => $passwordRequest->getToken() + ]); + + $this->ci->mailer->send($message); + } + $ms->addMessageTranslated('success', 'USER.CREATED', $data); }); diff --git a/app/sprinkles/admin/templates/forms/user.html.twig b/app/sprinkles/admin/templates/forms/user.html.twig index bc338a482..7a02aa489 100644 --- a/app/sprinkles/admin/templates/forms/user.html.twig +++ b/app/sprinkles/admin/templates/forms/user.html.twig @@ -109,7 +109,7 @@
{% endif %} {% if 'password' not in form.fields.hidden %} - {% include "forms/partials/user-set-password.html.twig" %} + {% include "forms/partials/user-set-password.html.twig" %} {% endif %} {% endblock %}
From a07a7683555a2e9c0c2f90a361d4e66dddfd1774 Mon Sep 17 00:00:00 2001 From: zharding Date: Sun, 9 Jul 2017 14:49:06 -0700 Subject: [PATCH 5/7] Hide the password field when editing a user --- app/sprinkles/admin/src/Controller/UserController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/sprinkles/admin/src/Controller/UserController.php b/app/sprinkles/admin/src/Controller/UserController.php index 7617179db..1a6734c03 100644 --- a/app/sprinkles/admin/src/Controller/UserController.php +++ b/app/sprinkles/admin/src/Controller/UserController.php @@ -623,7 +623,7 @@ public function getModalEdit($request, $response, $args) // Generate form $fields = [ - 'hidden' => ['theme'], + 'hidden' => ['theme', 'password'], 'disabled' => ['user_name'] ]; From acf4d600b535e08fad462c70cbebc627ba0754c8 Mon Sep 17 00:00:00 2001 From: amosfolz <33728190+amosfolz@users.noreply.github.com> Date: Fri, 19 Jul 2019 13:28:06 -0400 Subject: [PATCH 6/7] allow admin to set user password on creation --- app/sprinkles/admin/schema/requests/user/create.yaml | 2 +- app/sprinkles/admin/src/Controller/UserController.php | 4 ++-- .../templates/forms/partials/user-set-password.html.twig | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/sprinkles/admin/schema/requests/user/create.yaml b/app/sprinkles/admin/schema/requests/user/create.yaml index 9094a765f..821482001 100644 --- a/app/sprinkles/admin/schema/requests/user/create.yaml +++ b/app/sprinkles/admin/schema/requests/user/create.yaml @@ -70,7 +70,7 @@ group_id: label: "&GROUP" domain: server message: VALIDATE.INTEGER -value: +password: validators: required: domain: client diff --git a/app/sprinkles/admin/src/Controller/UserController.php b/app/sprinkles/admin/src/Controller/UserController.php index c46bd0934..4c6cfa4a9 100644 --- a/app/sprinkles/admin/src/Controller/UserController.php +++ b/app/sprinkles/admin/src/Controller/UserController.php @@ -133,11 +133,11 @@ public function create(Request $request, Response $response, $args) } $data['flag_verified'] = 1; - if (!isset($data['value'])) { + if (!isset($data['password'])) { // Set password as empty on initial creation. We will then send email so new user can set it themselves via a verification token $data['password'] = ''; } else { - $data['password'] = Password::hash($data['value']); + $data['password'] = Password::hash($data['password']); } // All checks passed! log events/activities, create user, and send verification email (if required) diff --git a/app/sprinkles/admin/templates/forms/partials/user-set-password.html.twig b/app/sprinkles/admin/templates/forms/partials/user-set-password.html.twig index b618a525f..36a3b653f 100644 --- a/app/sprinkles/admin/templates/forms/partials/user-set-password.html.twig +++ b/app/sprinkles/admin/templates/forms/partials/user-set-password.html.twig @@ -22,7 +22,7 @@
- +
@@ -34,4 +34,4 @@
- \ No newline at end of file + From 657aa0ecc5915ed23b7ec50fe19af44e53b400b3 Mon Sep 17 00:00:00 2001 From: amosfolz <33728190+amosfolz@users.noreply.github.com> Date: Fri, 19 Jul 2019 13:38:12 -0400 Subject: [PATCH 7/7] Font Awesome 5 updates for user-set-password-html.twig --- .../templates/forms/partials/user-set-password.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/sprinkles/admin/templates/forms/partials/user-set-password.html.twig b/app/sprinkles/admin/templates/forms/partials/user-set-password.html.twig index 36a3b653f..cb6c1502b 100644 --- a/app/sprinkles/admin/templates/forms/partials/user-set-password.html.twig +++ b/app/sprinkles/admin/templates/forms/partials/user-set-password.html.twig @@ -21,14 +21,14 @@
- +
- +