|
|
|
@ -12,6 +12,7 @@ import {MatDialog, MatDialogRef} from "@angular/material/dialog"; |
|
|
|
import {FormControl} from "@angular/forms"; |
|
|
|
import {NodeMiniDTO} from "../entities/NodeMiniDTO"; |
|
|
|
import {MatSnackBar} from "@angular/material/snack-bar"; |
|
|
|
import {D} from "@angular/cdk/keycodes"; |
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
@ -22,7 +23,7 @@ import {MatSnackBar} from "@angular/material/snack-bar"; |
|
|
|
<mat-tab-group> |
|
|
|
<mat-tab label="Через поиск"> |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<div style="border-radius: 1px; border: 1px solid black"> |
|
|
|
<mat-form-field appearance="fill" style="width: 100%"> |
|
|
|
<mat-label>Имя ноды</mat-label> |
|
|
|
<input |
|
|
|
@ -38,15 +39,14 @@ import {MatSnackBar} from "@angular/material/snack-bar"; |
|
|
|
</mat-autocomplete> |
|
|
|
</mat-form-field> |
|
|
|
|
|
|
|
<button mat-button mat-raised-button (click)="sendCodeToNode()">Отправить код на ноду</button> |
|
|
|
<button mat-button mat-stroked-button-button (click)="sendCodeToNode()" style="width: 100%;">Отправить код на ноду</button> |
|
|
|
</div> |
|
|
|
<mat-divider></mat-divider> |
|
|
|
<div> |
|
|
|
<mat-form-field class="example-full-width" appearance="fill"> |
|
|
|
<div [hidden]="!showAcceptCode" style="border-radius: 1px; border: 1px solid black; margin-top: 5px"> |
|
|
|
<mat-form-field style="width: 100%" appearance="fill"> |
|
|
|
<mat-label>Код из сообщения</mat-label> |
|
|
|
<input [(ngModel)]="code" matInput maxlength="4" placeholder="Код из сообщения"> |
|
|
|
</mat-form-field> |
|
|
|
<button mat-button (click)="acceptCode()">Проверить код</button> |
|
|
|
<button mat-button (click)="acceptCode()" style="width: 100%">Проверить код</button> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</mat-tab> |
|
|
|
@ -74,6 +74,8 @@ export class AuthDialog implements OnInit { |
|
|
|
myControl = new FormControl(); |
|
|
|
foundedNodes: Observable<NodeMiniDTO[]> = new Observable<NodeMiniDTO[]>() |
|
|
|
code!: number |
|
|
|
showAcceptCode: boolean = false; |
|
|
|
lastCodeSend: number = 0; |
|
|
|
|
|
|
|
acceptCode() { |
|
|
|
this.http.get(`api/auth/code/check?code=${this.code}`) |
|
|
|
@ -81,6 +83,7 @@ export class AuthDialog implements OnInit { |
|
|
|
.subscribe((res:{status:boolean}) => { |
|
|
|
if (res.status) { |
|
|
|
this.dialogRef.close() |
|
|
|
location.reload() |
|
|
|
} else { |
|
|
|
this.snack.open("Неправильный код") |
|
|
|
} |
|
|
|
@ -94,8 +97,19 @@ export class AuthDialog implements OnInit { |
|
|
|
|
|
|
|
sendCodeToNode() { |
|
|
|
let node:NodeMiniDTO = this.myControl.value as NodeMiniDTO |
|
|
|
if (node == null) { |
|
|
|
this.snack.open("Сначала надо выбрать свою ноду"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
this.http.get(`api/auth/code?num=${node.num}`).subscribe( |
|
|
|
(res) => this.snack.open(`Код отправлен на ноду ${node.long_name}`) |
|
|
|
(res) => { |
|
|
|
this.lastCodeSend = new Date().getTime()/1000; |
|
|
|
this.snack.open(`Код отправлен на ноду ${node.long_name}`); |
|
|
|
this.showAcceptCode = true; |
|
|
|
}, (err) => { |
|
|
|
this.snack.open("Возможно стоит подождать перд отправкой следующего кода") |
|
|
|
} |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -109,7 +123,7 @@ export class AuthInterceptor implements HttpInterceptor { |
|
|
|
return next.handle(req).pipe( |
|
|
|
catchError((error: HttpErrorResponse) => { |
|
|
|
if (error.status === 401 && !this.dialogOpened) { |
|
|
|
const ref = this.dialog.open(AuthDialog, {disableClose: true, width:"50%"}) |
|
|
|
const ref = this.dialog.open(AuthDialog, {disableClose: true, width:"30%"}) |
|
|
|
ref.afterClosed().subscribe((res:any) => this.dialogOpened = false) |
|
|
|
} |
|
|
|
return throwError(() => error); |
|
|
|
|