add user status

This commit is contained in:
_Bastler 2021-03-27 13:30:23 +01:00
parent b3f77eb721
commit 2cbfd628a2
5 changed files with 133 additions and 24 deletions

View File

@ -2,15 +2,15 @@
<mat-card>
<mat-card-content>
<h2>{{'password.change' | i18n}}</h2>
<mat-hint *ngIf="success">
{{'password.changed' | i18n}}
</mat-hint>
<mat-form-field>
<input matInput type="password" placeholder="{{'password.current' | i18n}}"
formControlName="oldPassword" [(ngModel)]="model.old">
<mat-error *ngFor="let error of passwordForm.get('oldPassword').errors | keyvalue">
{{error.key}}
</mat-error>
<mat-hint *ngIf="success">
{{'password.changed' | i18n}}
</mat-hint>
</mat-form-field>
<mat-form-field>
<input matInput type="password" placeholder="{{'password' | i18n}}" formControlName="password"
@ -36,13 +36,41 @@
</mat-card>
</form>
<form [formGroup]="statusForm" (ngSubmit)="changeStatus()" #statusFormDirective="ngForm">
<mat-card>
<mat-card-content>
<h2>{{'security.status' | i18n}}</h2>
<p> {{'security.status.hint' | i18n}}</p>
<mat-form-field>
<mat-select [(ngModel)]="model.status" formControlName="status" placeholder="{{'security.status' | i18n}}">
<mat-option *ngFor="let status of statuses" [value]="status">
{{'security.status.' + status | i18n}}
</mat-option>
</mat-select>
<mat-hint *ngIf="successStatus">
{{'security.status.success' | i18n}}
</mat-hint>
</mat-form-field>
<mat-label>{{'security.status.' + model.status + '.hint' | i18n}}</mat-label>
</mat-card-content>
<mat-card-actions>
<mat-progress-bar *ngIf="working" mode="indeterminate"></mat-progress-bar>
<button *ngIf="!working" mat-raised-button color="primary" [disabled]="statusForm.invalid">
{{'security.status.change' | i18n}}
</button>
</mat-card-actions>
</mat-card>
</form>
<mat-card>
<mat-card-content>
<h2>{{'security.2fa' | i18n}}</h2>
<p>{{'security.2fa.info' | i18n}}</p>
</mat-card-content>
<mat-card-actions>
<button *ngIf="!totp" (click)="createTotp()" mat-raised-button color="accent">{{'security.2fa.totp.create' | i18n}}</button>
<button *ngIf="totp" (click)="removeTotp()" mat-raised-button color="warn">{{'security.2fa.totp.remove' | i18n}}</button>
<button *ngIf="!totp" (click)="createTotp()" mat-raised-button color="accent">{{'security.2fa.totp.create' |
i18n}}</button>
<button *ngIf="totp" (click)="removeTotp()" mat-raised-button color="warn">{{'security.2fa.totp.remove' |
i18n}}</button>
</mat-card-actions>
</mat-card>

View File

@ -17,10 +17,15 @@ 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,
@ -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 => {
@ -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, {

View File

@ -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);
}

View File

@ -174,6 +174,24 @@
"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": {
@ -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.",

View File

@ -174,6 +174,24 @@
"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": {
@ -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": {