From 196f891bae9d3b622315f386f2096adc245f3937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Fri, 11 Nov 2022 11:49:25 +0000 Subject: [PATCH] Fixes (#31) * fix: update form registration type * feat: implement registration delete * feat: send welcome email --- plugins/genuineq/user/lang/en/lang.php | 5 +++ plugins/genuineq/user/lang/ro/lang.php | 5 +++ .../user/reportwidgets/RegRequestsTable.php | 39 +++++++++++++++++-- .../partials/_preview_request.htm | 13 +++++-- .../pages/authentification/register-form.htm | 1 + 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/plugins/genuineq/user/lang/en/lang.php b/plugins/genuineq/user/lang/en/lang.php index 0fa4c3b4..f66f01d1 100644 --- a/plugins/genuineq/user/lang/en/lang.php +++ b/plugins/genuineq/user/lang/en/lang.php @@ -398,6 +398,11 @@ 'fail' => 'Failed to activate that account', ], + 'flash_delete' => [ + 'success' => 'Account was successfully deleted', + 'fail' => 'Failed to delete that account', + ], + 'columns' => [ 'id' => 'Id', 'name' => 'Name', diff --git a/plugins/genuineq/user/lang/ro/lang.php b/plugins/genuineq/user/lang/ro/lang.php index cfea98c1..89f5e9cd 100644 --- a/plugins/genuineq/user/lang/ro/lang.php +++ b/plugins/genuineq/user/lang/ro/lang.php @@ -398,6 +398,11 @@ 'fail' => 'Nu s-a activat contul respectiv', ], + 'flash_delete' => [ + 'success' => 'Contul a fost șters cu succes', + 'fail' => 'Nu s-a șters contul respectiv', + ], + 'columns' => [ 'id' => 'Id', 'name' => 'Prenume', diff --git a/plugins/genuineq/user/reportwidgets/RegRequestsTable.php b/plugins/genuineq/user/reportwidgets/RegRequestsTable.php index 9456fa79..12af00b5 100644 --- a/plugins/genuineq/user/reportwidgets/RegRequestsTable.php +++ b/plugins/genuineq/user/reportwidgets/RegRequestsTable.php @@ -6,6 +6,7 @@ use Redirect; use Exception; use Backend\Classes\ReportWidgetBase; +use Genuineq\User\Helpers\EmailHelper; use Genuineq\User\Models\User as UserModel; /** @@ -24,7 +25,6 @@ public function render() /** Get no of inactive user accounts (== user requests) from database */ $this->vars['userRequests'] = UserModel::where('is_activated', 0)->orderBy('created_at', 'DESC')->get(); - } catch (Exception $ex) { $this->vars['error'] = $ex->getMessage(); } @@ -97,8 +97,41 @@ public function onRequest() private function activateUser($accountId) { $userModel = UserModel::find($accountId); - $userModel->is_activated = 1; - $userModel->save(); + + $userModel->attemptActivation($userModel->getActivationCode()); + + /** Inform user via email of account activation. */ + EmailHelper::sendWelcomeEmail($userModel); } + public function onDelete() + { + if ([] != post('record_id')) { + $this->deleteUser(post('record_id')); + } elseif ([] != post('checked')) { + /** Iterate IDs and get the corresponding user, then activate it */ + foreach (post('checked') as $accountId) { + $this->deleteUser($accountId); + } + } else { + Flash::error(Lang::get('genuineq.user::lang.reportwidgets.reg_requests_table.flash_delete.fail')); + + return; + } + + Flash::success(Lang::get('genuineq.user::lang.reportwidgets.reg_requests_table.flash_delete.success')); + + /* Refreshing the page */ + return Redirect::refresh(); + } + + + private function deleteUser($accountId) + { + $userModel = UserModel::find($accountId); + + if (!is_null($userModel)) { + $userModel->delete(); + } + } } diff --git a/plugins/genuineq/user/reportwidgets/regrequeststable/partials/_preview_request.htm b/plugins/genuineq/user/reportwidgets/regrequeststable/partials/_preview_request.htm index f14b62c6..a4d07dbd 100644 --- a/plugins/genuineq/user/reportwidgets/regrequeststable/partials/_preview_request.htm +++ b/plugins/genuineq/user/reportwidgets/regrequeststable/partials/_preview_request.htm @@ -100,10 +100,15 @@

$('#teacherForm').toggleClass('d-none', isSchoolForm); $('#schoolForm').toggleClass('d-none', !isSchoolForm); + $('#type').val(target); } $(document).ready(function () {