From 37ad910e759eda557e9ab16c0c08007c54eff4ae Mon Sep 17 00:00:00 2001 From: gofnnp Date: Mon, 15 May 2023 12:08:22 +0400 Subject: [PATCH] =?UTF-8?q?dev=20#13995=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=B0=D1=82=D1=8B=20=D1=80=D0=BE=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F(=D0=B7=D0=B0=D0=B3=D0=BB=D1=88=D0=BA=D0=B0,=20=D1=87?= =?UTF-8?q?=D1=82=D0=BE=D0=B1=D1=8B=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=BA=D0=BE=D1=81=D1=82=D1=8B=D0=BB=D1=8C=20=D0=B2=20?= =?UTF-8?q?=D0=A1=D0=90)=20=D0=BF=D1=80=D0=B8=20=D0=B0=D0=B2=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/login/login.component.ts | 97 ++++++++++++------- 1 file changed, 62 insertions(+), 35 deletions(-) diff --git a/angular/src/app/presentation-options/default-option/pages/login/login.component.ts b/angular/src/app/presentation-options/default-option/pages/login/login.component.ts index 0a60904..e848f34 100644 --- a/angular/src/app/presentation-options/default-option/pages/login/login.component.ts +++ b/angular/src/app/presentation-options/default-option/pages/login/login.component.ts @@ -3,7 +3,7 @@ import { Component, EventEmitter, HostListener, - OnInit + OnInit, } from '@angular/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; import { MatSnackBar } from '@angular/material/snack-bar'; @@ -37,7 +37,8 @@ export class LoginComponent implements OnInit, AfterViewInit { private router: Router, private jsonrpc: JsonrpcService, private messageService: MessageService, - private _snackBar: MatSnackBar + private _snackBar: MatSnackBar, + private jsonRpcService: JsonrpcService ) {} ngOnInit(): void {} @@ -45,7 +46,7 @@ export class LoginComponent implements OnInit, AfterViewInit { ngAfterViewInit() { setTimeout(() => { this.inputFocusEmitter.emit(`#${this.inputIds[0]}`); - }, 1000) + }, 1000); } public inputFocusEmitter = new EventEmitter(); @@ -72,7 +73,6 @@ export class LoginComponent implements OnInit, AfterViewInit { const nextInputIndex = index + 1; if (event.target.value.length > 1) { event.target.value = event.target.value.slice(-1); - } if (nextInputIndex > 0 && nextInputIndex <= this.inputIds.length) { this.inputFocusEmitter.emit(`#${this.inputIds[nextInputIndex]}`); @@ -91,68 +91,95 @@ export class LoginComponent implements OnInit, AfterViewInit { }); return; } - this.jsonrpc.rpc({ - method: 'sendVerifyByPhone', - params: [data.phone] - }, RpcService.authService, false).subscribe({ + this.jsonrpc + .rpc( + { + method: 'sendVerifyByPhone', + params: [data.phone], + }, + RpcService.authService, + false + ) + .subscribe({ next: (result) => { if (result.code !== 0) { this._snackBar.open('Произошла ошибка! Попробуйте позже', '', { - duration: 3000 - }) + duration: 3000, + }); } if (result.code === 0) { this.timeLeft = 60; const interval = setInterval(() => { - if(this.timeLeft > 0) { + if (this.timeLeft > 0) { this.timeLeft--; } else { clearInterval(interval); } - },1000) + }, 1000); } this.isShowNumber = false; }, error: (error) => { console.error('Error: ', error); - - } - } - ); + }, + }); setTimeout(() => { this.inputFocusEmitter.emit(`#${this.inputIds[0]}`); - }, 0) + }, 0); } submitCode() { const data = this.codeForm.value; - this.jsonrpc.rpc({ - method: 'getTokenByPhone', - params: [this.phoneForm.value.phone, Object.values(data).join('')] - }, RpcService.authService, false).subscribe({ + this.jsonrpc + .rpc( + { + method: 'getTokenByPhone', + params: [this.phoneForm.value.phone, Object.values(data).join('')], + }, + RpcService.authService, + false + ) + .subscribe({ next: (result) => { if (result.code === 0) { this.cookiesService.setCookie('token', result?.data?.token); - this.router.navigate(['/'], { - queryParams: { - token: result?.data?.token + this.jsonRpcService.rpc( + { + method: 'updateAdditionalInfo', + params: [ + { + first_name: this.phoneForm.value.name, + birth_day: '01.01.1999' + }, + ], }, - }); + RpcService.authService, + true + ).subscribe({ + next: (value) => { + this.router.navigate(['/'], { + queryParams: { + token: result?.data?.token, + }, + }); + }, + error: (err) => { + console.error(err); + + } + }) // this.phoneConfirmed.emit(null); } else if (result.code === 230) { this._snackBar.open('Неверный код!', '', { - duration: 3000 - }) + duration: 3000, + }); // this.errorConfirmCode = true; - } }, error: (error) => { console.error(error); - - } - } - ); + }, + }); } backToPhoneForm() { @@ -160,8 +187,8 @@ export class LoginComponent implements OnInit, AfterViewInit { code: '', code1: '', code2: '', - code3: '' - }) - this.isShowNumber = true + code3: '', + }); + this.isShowNumber = true; } }