From 607f42531e010bd589ea2ab980c980f25787a7e5 Mon Sep 17 00:00:00 2001 From: Suhas P R Date: Sun, 2 Oct 2022 10:03:45 +0000 Subject: [PATCH 1/3] Added "Send password reset email" button to backend users update page --- modules/backend/controllers/Users.php | 29 +++++++++++++++++++ .../controllers/users/_btn_password_reset.php | 12 ++++++++ modules/backend/lang/en/lang.php | 4 +++ modules/backend/models/user/fields.yaml | 8 +++-- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 modules/backend/controllers/users/_btn_password_reset.php diff --git a/modules/backend/controllers/Users.php b/modules/backend/controllers/Users.php index 1dc885f4c9..9d9a557777 100644 --- a/modules/backend/controllers/Users.php +++ b/modules/backend/controllers/Users.php @@ -1,5 +1,6 @@ formFindModelObject($recordId); + + //@todo::Force Trusted Host verification + + if ($user) { + $code = $user->getResetPasswordCode(); + $link = Backend::url('backend/auth/reset/' . $user->id . '/' . $code); + + $data = [ + 'name' => $user->full_name, + 'link' => $link, + ]; + + Mail::send('backend::mail.restore', $data, function ($message) use ($user) { + $message->to($user->email, $user->full_name)->subject(trans('backend::lang.account.password_reset')); + }); + } + + Flash::success(Lang::get('backend::lang.account.manual_password_reset_success')); + + return Redirect::refresh(); + } } diff --git a/modules/backend/controllers/users/_btn_password_reset.php b/modules/backend/controllers/users/_btn_password_reset.php new file mode 100644 index 0000000000..8d41a93c5c --- /dev/null +++ b/modules/backend/controllers/users/_btn_password_reset.php @@ -0,0 +1,12 @@ +
+ +
\ No newline at end of file diff --git a/modules/backend/lang/en/lang.php b/modules/backend/lang/en/lang.php index 9dc854fe4e..9a69be2d93 100644 --- a/modules/backend/lang/en/lang.php +++ b/modules/backend/lang/en/lang.php @@ -75,6 +75,10 @@ 'cancel' => 'Cancel', 'delete' => 'Delete', 'ok' => 'OK', + 'working' => 'Working...', + 'password_reset_email' => 'Send password reset email', + 'manual_password_reset_confirm' => 'Are you sure you want to send password reset mail for this user?', + 'manual_password_reset_success' => 'An email has been sent to user with reset instructions.', ], 'dashboard' => [ 'menu_label' => 'Dashboard', diff --git a/modules/backend/models/user/fields.yaml b/modules/backend/models/user/fields.yaml index bbfbae286f..8b34fb476d 100644 --- a/modules/backend/models/user/fields.yaml +++ b/modules/backend/models/user/fields.yaml @@ -68,11 +68,15 @@ tabs: secondaryTabs: fields: btn_impersonate: - label: '' + label: "" context: [update] type: partial btn_unsuspend: - label: '' + label: "" + context: [update] + type: partial + btn_password_reset: + label: "" context: [update] type: partial avatar: From c6d5a0075e9625b568940d0cb703e80dc802531d Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Sun, 2 Oct 2022 14:40:19 -0600 Subject: [PATCH 2/3] Apply suggestions from code review --- modules/backend/controllers/Users.php | 2 -- modules/backend/controllers/users/_btn_password_reset.php | 4 ++-- modules/backend/lang/en/lang.php | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/backend/controllers/Users.php b/modules/backend/controllers/Users.php index 9d9a557777..9151933e76 100644 --- a/modules/backend/controllers/Users.php +++ b/modules/backend/controllers/Users.php @@ -242,8 +242,6 @@ public function update_onManualPasswordReset($recordId) { $user = $this->formFindModelObject($recordId); - //@todo::Force Trusted Host verification - if ($user) { $code = $user->getResetPasswordCode(); $link = Backend::url('backend/auth/reset/' . $user->id . '/' . $code); diff --git a/modules/backend/controllers/users/_btn_password_reset.php b/modules/backend/controllers/users/_btn_password_reset.php index 8d41a93c5c..b52c337ebc 100644 --- a/modules/backend/controllers/users/_btn_password_reset.php +++ b/modules/backend/controllers/users/_btn_password_reset.php @@ -2,11 +2,11 @@ - \ No newline at end of file + diff --git a/modules/backend/lang/en/lang.php b/modules/backend/lang/en/lang.php index 9a69be2d93..318517f5a2 100644 --- a/modules/backend/lang/en/lang.php +++ b/modules/backend/lang/en/lang.php @@ -75,10 +75,10 @@ 'cancel' => 'Cancel', 'delete' => 'Delete', 'ok' => 'OK', - 'working' => 'Working...', + 'sending' => 'Sending...', 'password_reset_email' => 'Send password reset email', - 'manual_password_reset_confirm' => 'Are you sure you want to send password reset mail for this user?', - 'manual_password_reset_success' => 'An email has been sent to user with reset instructions.', + 'manual_password_reset_confirm' => 'Are you sure you want to send a password reset email to this user?', + 'manual_password_reset_success' => 'An email has been sent to the user with instructions to reset their password.', ], 'dashboard' => [ 'menu_label' => 'Dashboard', From 63ccc7642048dc0e1cc77d0abb1e0df81e489a25 Mon Sep 17 00:00:00 2001 From: Suhas P R Date: Mon, 3 Oct 2022 04:26:43 +0000 Subject: [PATCH 3/3] Review changes --- modules/backend/controllers/Users.php | 2 -- modules/backend/controllers/users/_btn_password_reset.php | 6 +++--- modules/backend/lang/en/lang.php | 6 +++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/backend/controllers/Users.php b/modules/backend/controllers/Users.php index 9d9a557777..9151933e76 100644 --- a/modules/backend/controllers/Users.php +++ b/modules/backend/controllers/Users.php @@ -242,8 +242,6 @@ public function update_onManualPasswordReset($recordId) { $user = $this->formFindModelObject($recordId); - //@todo::Force Trusted Host verification - if ($user) { $code = $user->getResetPasswordCode(); $link = Backend::url('backend/auth/reset/' . $user->id . '/' . $code); diff --git a/modules/backend/controllers/users/_btn_password_reset.php b/modules/backend/controllers/users/_btn_password_reset.php index 8d41a93c5c..78dc211c60 100644 --- a/modules/backend/controllers/users/_btn_password_reset.php +++ b/modules/backend/controllers/users/_btn_password_reset.php @@ -2,11 +2,11 @@ - \ No newline at end of file + diff --git a/modules/backend/lang/en/lang.php b/modules/backend/lang/en/lang.php index 9a69be2d93..318517f5a2 100644 --- a/modules/backend/lang/en/lang.php +++ b/modules/backend/lang/en/lang.php @@ -75,10 +75,10 @@ 'cancel' => 'Cancel', 'delete' => 'Delete', 'ok' => 'OK', - 'working' => 'Working...', + 'sending' => 'Sending...', 'password_reset_email' => 'Send password reset email', - 'manual_password_reset_confirm' => 'Are you sure you want to send password reset mail for this user?', - 'manual_password_reset_success' => 'An email has been sent to user with reset instructions.', + 'manual_password_reset_confirm' => 'Are you sure you want to send a password reset email to this user?', + 'manual_password_reset_success' => 'An email has been sent to the user with instructions to reset their password.', ], 'dashboard' => [ 'menu_label' => 'Dashboard',