diff --git a/src/app/pages/account/security/security.component.html b/src/app/pages/account/security/security.component.html index 16c93d5..fcf56de 100644 --- a/src/app/pages/account/security/security.component.html +++ b/src/app/pages/account/security/security.component.html @@ -2,15 +2,15 @@

{{'password.change' | i18n}}

- - {{'password.changed' | i18n}} - {{error.key}} + + {{'password.changed' | i18n}} + +
+ + +

{{'security.status' | i18n}}

+

{{'security.status.hint' | i18n}}

+ + + + {{'security.status.' + status | i18n}} + + + + {{'security.status.success' | i18n}} + + + {{'security.status.' + model.status + '.hint' | i18n}} +
+ + + + +
+
+

{{'security.2fa' | i18n}}

{{'security.2fa.info' | i18n}}

- - + +
\ No newline at end of file diff --git a/src/app/pages/account/security/security.component.ts b/src/app/pages/account/security/security.component.ts index 15845f5..5e47aa4 100644 --- a/src/app/pages/account/security/security.component.ts +++ b/src/app/pages/account/security/security.component.ts @@ -1,10 +1,10 @@ -import { Component, OnInit, ViewChild, Inject } from '@angular/core'; -import { FormBuilder, FormGroup, FormControl, Validators, NgForm } from '@angular/forms'; -import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import {Component, OnInit, ViewChild, Inject} from '@angular/core'; +import {FormBuilder, FormGroup, FormControl, Validators, NgForm} from '@angular/forms'; +import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog'; -import { AuthService } from './../../../services/auth.service'; -import { UserService } from './../../../services/user.service'; -import { MatchingValidator } from './../../../utils/matching.validator'; +import {AuthService} from './../../../services/auth.service'; +import {UserService} from './../../../services/user.service'; +import {MatchingValidator} from './../../../utils/matching.validator'; @Component({ selector: 'app-account-security', @@ -17,16 +17,21 @@ export class SecurityComponent implements OnInit { model: any = {}; public working: boolean; public success: boolean; + public successStatus: boolean; public totp: boolean = false; + statuses = ["NORMAL", "SLEEP", "PURGE"]; + passwordForm: FormGroup; + statusForm: FormGroup; @ViewChild('passwordFormDirective') private passwordFormDirective: NgForm; + @ViewChild('statusFormDirective') private statusFormDirective: NgForm; constructor( private formBuilder: FormBuilder, private userService: UserService, private authService: AuthService, - public dialog: MatDialog) { } + public dialog: MatDialog) {} ngOnInit(): void { this.passwordForm = this.formBuilder.group({ @@ -37,6 +42,17 @@ export class SecurityComponent implements OnInit { validator: MatchingValidator('password', 'password2') }); + + this.statusForm = this.formBuilder.group({ + status: ['', Validators.required] + }); + + this.userService.get().subscribe((response: any) => { + this.model.status = response.status; + }, error => { + + }) + this.authService.isTotpEnabled().subscribe(response => { this.totp = true; }, error => { @@ -45,7 +61,7 @@ export class SecurityComponent implements OnInit { } changePassword() { - if (this.passwordForm.valid && !this.working) { + if(this.passwordForm.valid && !this.working) { this.working = true; this.userService.password(this.model).subscribe((result: any) => { @@ -54,14 +70,14 @@ export class SecurityComponent implements OnInit { this.working = false; }, (error) => { this.working = false; - if (error.status == 409) { + if(error.status == 409) { let errors = {}; - for (let code of error.error) { + for(let code of error.error) { errors[code.field] = errors[code.field] || {}; errors[code.field][code.code] = true; } - for (let code in errors) { + for(let code in errors) { this.passwordForm.get(code).setErrors(errors[code]); } } @@ -69,6 +85,20 @@ export class SecurityComponent implements OnInit { } } + + changeStatus() { + if(this.statusForm.valid && !this.working) { + this.working = true; + + this.userService.update({status : this.model.status}).subscribe((result: any) => { + this.successStatus = true; + this.working = false; + }, (error) => { + this.working = false; + }) + } + } + createTotp() { this.authService.createTotp().subscribe((result: any) => { const dialogRef = this.dialog.open(SecurityTotpDialog, { @@ -78,7 +108,7 @@ export class SecurityComponent implements OnInit { }); dialogRef.afterClosed().subscribe(result => { - if (result) { + if(result) { this.authService.enableTotp(result).subscribe((result: any) => { this.totp = true; }) @@ -121,7 +151,7 @@ export class SecurityTotpDialog { constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any - ) { } + ) {} ngOnInit(): void { this.code = new FormControl('', [Validators.required, Validators.pattern("[0-9]{6}")]); diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index e45a1aa..925845d 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -11,6 +11,10 @@ export class UserService { constructor(private http: HttpClient) { } + get() { + return this.http.get(environment.apiUrl + "/users"); + } + register(userModel) { return this.http.post(environment.apiUrl + "/users", userModel); } diff --git a/src/assets/i18n/de-informal.json b/src/assets/i18n/de-informal.json index 7ee84e5..4d88069 100644 --- a/src/assets/i18n/de-informal.json +++ b/src/assets/i18n/de-informal.json @@ -174,12 +174,30 @@ "missing": "Bitte TOTP Code eingeben", "remove": "2FA (TOTP) deaktivieren" } + }, + "status": { + ".": "Status", + "change" : "Status ändern", + "hint": "Dein User Status gibt an, wie mit deinen Account Daten umgegangen wird wenn deine Berechtigungen ausgelaufen sind.", + "NORMAL": { + ".": "Normal", + "hint": "Dein Account sowie alle gespeicherten Daten werden vier (4) Wochen nach Ablauf gelöscht. Du hast also vier Wochen Zeit deinen Account wieder zu reaktivieren." + }, + "PURGE": { + ".": "Löschen", + "hint": "Dein Account sowie alle gespeicherten Daten werden umgehend(!) nach Ablauf gelöscht. Du kannst deinen Account nicht(!) mehr reaktivieren." + }, + "SLEEP": { + ".": "Schlafen", + "hint": "Dein Account sowie alle gespeicherten Daten werden nicht(!) gelöscht. Du kannst deinen Account also jederzeit wieder reaktivieren." + }, + "success" : "Status erfolgreich geändert" } }, "service-unavailable": { ".": "Dienst nicht erreichbar", - "retry" : "Seite neu laden", - "support" : "Support", + "retry": "Seite neu laden", + "support": "Support", "text": "Zurzeit scheint der Dienst nicht erreichbar zu sein. Wenn diese Meldung länger besteht, melde dich beim Support!" }, "services": { @@ -227,6 +245,12 @@ "text": "Administrator Rechte für die API von we.bstly", "title": "Administrator" }, + "ROLE_GUEST": { + "icon": "schedule_send", + "subtitle": "Gast Account von we.bstly", + "text": "Gast Account Einladung", + "title": "Gast Account" + }, "ROLE_MEMBER": { "icon": "loyalty", "subtitle": "Mitgliedschaft im Bastelei e. V.", diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 7c202eb..101b073 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -174,12 +174,30 @@ "missing": "Please enter TOTP code", "remove": "Disable 2FA (TOTP)" } + }, + "status": { + ".": "Status", + "change" : "Change status", + "hint": "You Account Status controls the handling of your account data after all permissions expired.", + "NORMAL": { + ".": "Normal", + "hint": "Your account and all your data will be deleted after four (4) weeks. So you have 4 weeks left to reactivate your account." + }, + "PURGE": { + ".": "Purge", + "hint": "Your account and all your data will be deleted immediately after expiry. So you can not(!) reactivate your account." + }, + "SLEEP": { + ".": "Sleep", + "hint": "Your account and all your data will not(!) be deleted. So you have reactivate your account anytime." + }, + "success" : "Status successfully changed" } }, "service-unavailable": { ".": "Service unavailable", - "retry" : "Reload page", - "support" : "Support", + "retry": "Reload page", + "support": "Support", "text": "The service seems currently unavailable. If this message appears over a longer period, please contact our support!" }, "services": { @@ -227,6 +245,12 @@ "text": "Administrator privileges for we.bstly API", "title": "Administrator" }, + "ROLE_GUEST": { + "icon": "schedule_send", + "subtitle": "Guest Account of we.bstly", + "text": "Guest Account Invite", + "title": "Guest Account" + }, "ROLE_MEMBER": { "icon": "loyalty", "subtitle": "Membership of Bastelei e. V.", @@ -276,8 +300,7 @@ "info": "Generate vouchers for Add-Ons and registration.", "registration": "Registration", "stored-safely": { - ".": - "Please store the provided voucher code securely, since we do not store any relation of vouchers to your account. If you leave page or reload the code won't be shown up again!", + ".": "Please store the provided voucher code securely, since we do not store any relation of vouchers to your account. If you leave page or reload the code won't be shown up again!", "confirm": "I securely stored the given voucher!" }, "temp": {