From e3e4e9ddaf5cd7f7699e8f7cd3be1a9290fb1433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20K=C3=A4sler?= <tom.kaesler@mni.thm.de> Date: Wed, 18 Sep 2019 23:27:30 +0200 Subject: [PATCH] Add button for account activation reset --- .../user-activation.component.html | 7 ++++- .../user-activation.component.scss | 4 +++ .../user-activation.component.ts | 10 +++++++ src/app/services/http/user.service.ts | 26 ++++++++++++++++++- src/assets/i18n/home/de.json | 3 +++ src/assets/i18n/home/en.json | 3 +++ 6 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/app/components/home/_dialogs/user-activation/user-activation.component.html b/src/app/components/home/_dialogs/user-activation/user-activation.component.html index 4521821bb..85f8b6e96 100644 --- a/src/app/components/home/_dialogs/user-activation/user-activation.component.html +++ b/src/app/components/home/_dialogs/user-activation/user-activation.component.html @@ -8,7 +8,12 @@ <mat-placeholder class="placeholder">{{ 'login.activation-key' | translate }}</mat-placeholder> <mat-error *ngIf="activationKeyFormControl.hasError('required')">{{ 'login.activation-key-required' | translate }}</mat-error> </mat-form-field> -</form> +</form><div fxLayout="column" fxLayoutAlign="space-around"> + <button (click)="resetActivation()" mat-flat-button type="button" + matTooltip="{{'login.restart-account-activation-tooltip' | translate}}"> + {{ 'login.restart-account-activation-button' | translate }} + </button> +</div> <app-dialog-action-buttons buttonsLabelSection="login" confirmButtonLabel="activate" diff --git a/src/app/components/home/_dialogs/user-activation/user-activation.component.scss b/src/app/components/home/_dialogs/user-activation/user-activation.component.scss index e69de29bb..ff8a21f92 100644 --- a/src/app/components/home/_dialogs/user-activation/user-activation.component.scss +++ b/src/app/components/home/_dialogs/user-activation/user-activation.component.scss @@ -0,0 +1,4 @@ +.mat-flat-button { + color: var(--on-primary); + background-color: var(--primary); +} diff --git a/src/app/components/home/_dialogs/user-activation/user-activation.component.ts b/src/app/components/home/_dialogs/user-activation/user-activation.component.ts index 8c8a2d371..0186f7dc5 100644 --- a/src/app/components/home/_dialogs/user-activation/user-activation.component.ts +++ b/src/app/components/home/_dialogs/user-activation/user-activation.component.ts @@ -50,6 +50,16 @@ export class UserActivationComponent implements OnInit { return () => this.dialogRef.close(); } + resetActivation(): void { + this.userService.resetActivation(this.data.name.trim()).subscribe( + ret => { + this.translationService.get('login.restart-account-activation-correct').subscribe(message => { + this.notificationService.show(message); + }); + } + ); + } + /** * Returns a lambda which executes the dialog dedicated action on call. diff --git a/src/app/services/http/user.service.ts b/src/app/services/http/user.service.ts index 12d1abf33..59801a022 100644 --- a/src/app/services/http/user.service.ts +++ b/src/app/services/http/user.service.ts @@ -14,7 +14,9 @@ export class UserService extends BaseHttpService { private apiUrl = { base: '/api', user: '/user', - activate: '/activate' + activate: '/activate', + resetActivation: '/resetactivation', + find: '/find' }; constructor(private http: HttpClient) { @@ -29,6 +31,17 @@ export class UserService extends BaseHttpService { }, httpOptions); } + resetActivation(username: string): Observable<User> { + const connectionUrl: string = this.apiUrl.base + + this.apiUrl.user + + '/~' + encodeURIComponent(username) + + this.apiUrl.resetActivation; + return this.http.post<any>(connectionUrl, httpOptions).pipe( + tap(_ => ''), + catchError(this.handleError<User>('resetActivation')) + ); + } + delete(id: string): Observable<User> { const connectionUrl: string = this.apiUrl.base + this.apiUrl.user + '/' + id; return this.http.delete<User>(connectionUrl, httpOptions).pipe( @@ -36,4 +49,15 @@ export class UserService extends BaseHttpService { catchError(this.handleError<User>('deleteUser')) ); } + + getIdByLoginId(loginId: string): Observable<User[]> { + const url = `${this.apiUrl.base + this.apiUrl.user + this.apiUrl.find}`; + return this.http.post<User[]>(url, { + properties: { loginId: loginId }, + externalFilters: {} + }).pipe( + tap(() => ''), + catchError(this.handleError('getUserId', [])) + ); + } } diff --git a/src/assets/i18n/home/de.json b/src/assets/i18n/home/de.json index 7b851b202..4220fcc1f 100644 --- a/src/assets/i18n/home/de.json +++ b/src/assets/i18n/home/de.json @@ -129,6 +129,9 @@ "password-required": "Passwort erforderlich", "password-reset": "Passwort vergessen?", "register": "Registrieren", + "restart-account-activation-button": "Erneut senden", + "restart-account-activation-correct": "Ein neuer Schlüssel wurde gesendet!", + "restart-account-activation-tooltop": "Sendet einen neuen Aktivierungsschlüssel an die angegebene Adresse", "welcome": "Online fragen & Fragen bewerten" }, "password-reset": { diff --git a/src/assets/i18n/home/en.json b/src/assets/i18n/home/en.json index 1f5aab5bc..dda7e59ff 100644 --- a/src/assets/i18n/home/en.json +++ b/src/assets/i18n/home/en.json @@ -131,6 +131,9 @@ "password-required": "Password required", "password-reset": "Forgot your password?", "register": "Register", + "restart-account-activation-button": "Resend", + "restart-account-activation-correct": "New mail got send!", + "restart-account-activation-tooltop": "Sends a new activation key", "welcome": "Ask online & vote questions" }, "password-reset": { -- GitLab