add user status
This commit is contained in:
@@ -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>
|
||||
@@ -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<SecurityTotpDialog>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any
|
||||
) { }
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.code = new FormControl('', [Validators.required, Validators.pattern("[0-9]{6}")]);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user