From 5f66fde2290032d67e77e0144f311ac0c0d1f775 Mon Sep 17 00:00:00 2001 From: "florian.azizian" <florian.azizian@maarch.org> Date: Thu, 14 Nov 2019 17:22:44 +0100 Subject: [PATCH] FEAT #12162 TIME 0:30 remove reset user password in administration --- rest/index.php | 1 - src/app/user/controllers/UserController.php | 31 +------------------ src/app/user/models/UserModelAbstract.php | 9 +++--- .../user/user-administration.component.html | 6 ---- .../user/user-administration.component.ts | 13 -------- src/frontend/lang/lang-en.ts | 2 -- src/frontend/lang/lang-fr.ts | 2 -- src/frontend/lang/lang-nl.ts | 2 -- 8 files changed, 6 insertions(+), 60 deletions(-) diff --git a/rest/index.php b/rest/index.php index 23ece3109ec..50d89efec82 100755 --- a/rest/index.php +++ b/rest/index.php @@ -401,7 +401,6 @@ $app->delete('/users/{id}', \User\controllers\UserController::class . ':delete') $app->put('/users/{id}/suspend', \User\controllers\UserController::class . ':suspend'); $app->get('/users/{id}/isDeletable', \User\controllers\UserController::class . ':isDeletable'); $app->get('/users/{id}/details', \User\controllers\UserController::class . ':getDetailledById'); -$app->post('/users/{id}/password', \User\controllers\UserController::class . ':resetPassword'); $app->put('/users/{id}/password', \User\controllers\UserController::class . ':updatePassword'); $app->get('/users/{userId}/status', \User\controllers\UserController::class . ':getStatusByUserId'); $app->put('/users/{id}/status', \User\controllers\UserController::class . ':updateStatus'); diff --git a/src/app/user/controllers/UserController.php b/src/app/user/controllers/UserController.php index 50b104d5372..1e2dae2b861 100755 --- a/src/app/user/controllers/UserController.php +++ b/src/app/user/controllers/UserController.php @@ -124,13 +124,8 @@ class UserController $user['redirectedBaskets'] = RedirectBasketModel::getRedirectedBasketsByUserId(['userId' => $user['id']]); $user['history'] = HistoryModel::getByUserId(['userId' => $user['user_id'], 'select' => ['event_type', 'event_date', 'info', 'remote_ip']]); $user['canModifyPassword'] = false; - $user['canResetPassword'] = true; $user['canCreateMaarchParapheurUser'] = false; - $loggingMethod = CoreConfigModel::getLoggingMethod(); - if (in_array($loggingMethod['id'], self::ALTERNATIVES_CONNECTIONS_METHODS) && $user['loginmode'] != 'restMode') { - $user['canResetPassword'] = false; - } if ($user['loginmode'] == 'restMode') { $user['canModifyPassword'] = true; } @@ -549,22 +544,6 @@ class UserController return $response->withJson(['success' => 'success']); } - public function resetPassword(Request $request, Response $response, array $aArgs) - { - if (!PrivilegeController::hasPrivilege(['privilegeId' => 'manage_personal_data', 'userId' => $GLOBALS['id']])) { - return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); - } - - $error = $this->hasUsersRights(['id' => $aArgs['id']]); - if (!empty($error['error'])) { - return $response->withStatus($error['status'])->withJson(['errors' => $error['error']]); - } - - UserModel::resetPassword(['id' => $aArgs['id']]); - - return $response->withJson(['success' => 'success']); - } - public function updatePassword(Request $request, Response $response, array $aArgs) { $error = $this->hasUsersRights(['id' => $aArgs['id'], 'himself' => true]); @@ -1616,15 +1595,7 @@ class UserController return $response->withStatus(400)->withJson(['errors' => 'Password does not match security criteria']); } - UserModel::update([ - 'set' => [ - 'password' => AuthenticationModel::getPasswordHash($body['password']), - 'password_modification_date' => 'CURRENT_TIMESTAMP', - 'reset_token' => null - ], - 'where' => ['id = ?'], - 'data' => [$user['id']] - ]); + UserModel::resetPassword(['password' => $body['password'], 'id' => $user['id']]); $GLOBALS['id'] = $user['id']; diff --git a/src/app/user/models/UserModelAbstract.php b/src/app/user/models/UserModelAbstract.php index 234516f5c82..2cec649bfe7 100755 --- a/src/app/user/models/UserModelAbstract.php +++ b/src/app/user/models/UserModelAbstract.php @@ -242,15 +242,16 @@ abstract class UserModelAbstract public static function resetPassword(array $aArgs) { - ValidatorModel::notEmpty($aArgs, ['id']); + ValidatorModel::notEmpty($aArgs, ['id', 'password']); ValidatorModel::intVal($aArgs, ['id']); DatabaseModel::update([ 'table' => 'users', 'set' => [ - 'password' => AuthenticationModel::getPasswordHash('maarch'), - 'change_password' => 'Y', - 'password_modification_date' => 'CURRENT_TIMESTAMP' + 'password' => AuthenticationModel::getPasswordHash($aArgs['password']), + 'change_password' => 'N', + 'password_modification_date' => 'CURRENT_TIMESTAMP', + 'reset_token' => null ], 'where' => ['id = ?'], 'data' => [$aArgs['id']] diff --git a/src/frontend/app/administration/user/user-administration.component.html b/src/frontend/app/administration/user/user-administration.component.html index 4abd4025819..835a01c9c45 100755 --- a/src/frontend/app/administration/user/user-administration.component.html +++ b/src/frontend/app/administration/user/user-administration.component.html @@ -18,12 +18,6 @@ {{lang.desactivateAbsence}} </p> </a> - <a mat-list-item *ngIf="user.canResetPassword" (click)="resetPassword()"> - <mat-icon color="primary" mat-list-icon class="fa fa-key"></mat-icon> - <p mat-line> - {{lang.reinitPassword}} - </p> - </a> <a *ngIf="user.canModifyPassword" mat-list-item (click)="changePasswd();"> <mat-icon color="primary" mat-list-icon class="fa fa-key"></mat-icon> <p mat-line> diff --git a/src/frontend/app/administration/user/user-administration.component.ts b/src/frontend/app/administration/user/user-administration.component.ts index 819dd24ad2a..74b340d251d 100755 --- a/src/frontend/app/administration/user/user-administration.component.ts +++ b/src/frontend/app/administration/user/user-administration.component.ts @@ -350,19 +350,6 @@ export class UserAdministrationComponent implements OnInit { this.selectedSignatureLabel = this.user.signatures[index].signature_label; } - resetPassword(user: any) { - let r = confirm(this.lang.confirmAction + ' ' + this.lang.resetPsw); - - if (r) { - this.http.post("../../rest/users/" + this.serialId + "/password", {}) - .subscribe((data: any) => { - this.notify.success(this.lang.pswReseted); - }, (err) => { - this.notify.error(err.error.errors); - }); - } - } - toggleGroup(group: any) { if ($j('#' + group.group_id + '-input').is(':checked') == true) { var groupReq = { diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts index 3611b0e47b6..7282880a14c 100755 --- a/src/frontend/lang/lang-en.ts +++ b/src/frontend/lang/lang-en.ts @@ -760,7 +760,6 @@ export const LANG_EN = { "redirectUserListInstances" : "Change of recipient for mail being processed", "redirectWhenAbscence" : "Redirect the basket to a user when bascence activation", "reference" : "Reference", - "reinitPassword" : "Reset password", "relatedBaskets" : "Related basket(s)", "relatedContactNumber" : "Number of contacts related", "relatedContacts" : "Related contacts", @@ -772,7 +771,6 @@ export const LANG_EN = { "reports" : "Reports", "requiredField" : "Required field", "resetColor" : "Reset color", - "resetPsw" : "Reset password", "resId" : "Res Identifier", "restrictedEntity" : "Restricted entity", "resultPage" : "Result page", diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts index 031afebd1b0..958d9f13641 100755 --- a/src/frontend/lang/lang-fr.ts +++ b/src/frontend/lang/lang-fr.ts @@ -792,7 +792,6 @@ export const LANG_FR = { "redirectUserListInstances" : "Changement de destinataire pour les courriers en cours de traitement", "redirectWhenAbscence" : "Rediriger la bannette à une personne", "reference" : "Référence", - "reinitPassword" : "Réinitialiser le mot de passe", "relatedBaskets" : "Bannette(s) associée(s)", "relatedContactNumber" : "Contact(s) associé(s)", "relatedContacts" : "Contact(s) associé(s)", @@ -804,7 +803,6 @@ export const LANG_FR = { "reports" : "Statistiques", "requiredField" : "Champ requis", "resetColor" : "Réinitialiser la couleur", - "resetPsw" : "Réinitialiser le mot de passe", "resId" : "Identifiant GED", "restrictedEntity" : "Entité restreinte", "resultPage" : "Liste de résultats", diff --git a/src/frontend/lang/lang-nl.ts b/src/frontend/lang/lang-nl.ts index 4b40d3a0994..2a7253ebf12 100755 --- a/src/frontend/lang/lang-nl.ts +++ b/src/frontend/lang/lang-nl.ts @@ -788,7 +788,6 @@ export const LANG_NL = { "redirectUserListInstances" : "Change of recipient for mail being processed", //_TO_TRANSLATE_ "redirectWhenAbscence" : "Het bakje aan een persoon doorsturen", "reference" : "_TO_TRANSLATE", - "reinitPassword" : "Wachtwoord opnieuw instellen", "relatedBaskets" : "Gekoppeld(e) bakje(s)", "relatedContactNumber" : "Gekoppeld(e) contact(en)", "relatedContacts" : "Gekoppeld(e) contact(en)", @@ -800,7 +799,6 @@ export const LANG_NL = { "reports" : "Statistieken", "requiredField" : "Vereist veld", "resetColor" : "De kleur resetten", - "resetPsw" : "Wachtwoord opnieuw instellen", "resId" : "GED gebruikersnaam", "restrictedEntity" : "Restricted entity", //_TO_TRANSLATE "resultPage" : "Resultaatpagina", -- GitLab