добавил обновление имени и даты рождения(заглшка, чтобы работал костыль в СА) при авторизации
This commit is contained in:
gofnnp 2023-05-15 12:08:22 +04:00
parent 4a492f16e8
commit 37ad910e75

View File

@ -3,7 +3,7 @@ import {
Component, Component,
EventEmitter, EventEmitter,
HostListener, HostListener,
OnInit OnInit,
} from '@angular/core'; } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms'; import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MatSnackBar } from '@angular/material/snack-bar'; import { MatSnackBar } from '@angular/material/snack-bar';
@ -37,7 +37,8 @@ export class LoginComponent implements OnInit, AfterViewInit {
private router: Router, private router: Router,
private jsonrpc: JsonrpcService, private jsonrpc: JsonrpcService,
private messageService: MessageService, private messageService: MessageService,
private _snackBar: MatSnackBar private _snackBar: MatSnackBar,
private jsonRpcService: JsonrpcService
) {} ) {}
ngOnInit(): void {} ngOnInit(): void {}
@ -45,7 +46,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
ngAfterViewInit() { ngAfterViewInit() {
setTimeout(() => { setTimeout(() => {
this.inputFocusEmitter.emit(`#${this.inputIds[0]}`); this.inputFocusEmitter.emit(`#${this.inputIds[0]}`);
}, 1000) }, 1000);
} }
public inputFocusEmitter = new EventEmitter<string>(); public inputFocusEmitter = new EventEmitter<string>();
@ -72,7 +73,6 @@ export class LoginComponent implements OnInit, AfterViewInit {
const nextInputIndex = index + 1; const nextInputIndex = index + 1;
if (event.target.value.length > 1) { if (event.target.value.length > 1) {
event.target.value = event.target.value.slice(-1); event.target.value = event.target.value.slice(-1);
} }
if (nextInputIndex > 0 && nextInputIndex <= this.inputIds.length) { if (nextInputIndex > 0 && nextInputIndex <= this.inputIds.length) {
this.inputFocusEmitter.emit(`#${this.inputIds[nextInputIndex]}`); this.inputFocusEmitter.emit(`#${this.inputIds[nextInputIndex]}`);
@ -91,68 +91,95 @@ export class LoginComponent implements OnInit, AfterViewInit {
}); });
return; return;
} }
this.jsonrpc.rpc({ this.jsonrpc
method: 'sendVerifyByPhone', .rpc(
params: [data.phone] {
}, RpcService.authService, false).subscribe({ method: 'sendVerifyByPhone',
params: [data.phone],
},
RpcService.authService,
false
)
.subscribe({
next: (result) => { next: (result) => {
if (result.code !== 0) { if (result.code !== 0) {
this._snackBar.open('Произошла ошибка! Попробуйте позже', '', { this._snackBar.open('Произошла ошибка! Попробуйте позже', '', {
duration: 3000 duration: 3000,
}) });
} }
if (result.code === 0) { if (result.code === 0) {
this.timeLeft = 60; this.timeLeft = 60;
const interval = setInterval(() => { const interval = setInterval(() => {
if(this.timeLeft > 0) { if (this.timeLeft > 0) {
this.timeLeft--; this.timeLeft--;
} else { } else {
clearInterval(interval); clearInterval(interval);
} }
},1000) }, 1000);
} }
this.isShowNumber = false; this.isShowNumber = false;
}, },
error: (error) => { error: (error) => {
console.error('Error: ', error); console.error('Error: ', error);
},
} });
}
);
setTimeout(() => { setTimeout(() => {
this.inputFocusEmitter.emit(`#${this.inputIds[0]}`); this.inputFocusEmitter.emit(`#${this.inputIds[0]}`);
}, 0) }, 0);
} }
submitCode() { submitCode() {
const data = this.codeForm.value; const data = this.codeForm.value;
this.jsonrpc.rpc({ this.jsonrpc
method: 'getTokenByPhone', .rpc(
params: [this.phoneForm.value.phone, Object.values(data).join('')] {
}, RpcService.authService, false).subscribe({ method: 'getTokenByPhone',
params: [this.phoneForm.value.phone, Object.values(data).join('')],
},
RpcService.authService,
false
)
.subscribe({
next: (result) => { next: (result) => {
if (result.code === 0) { if (result.code === 0) {
this.cookiesService.setCookie('token', result?.data?.token); this.cookiesService.setCookie('token', result?.data?.token);
this.router.navigate(['/'], { this.jsonRpcService.rpc(
queryParams: { {
token: result?.data?.token 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); // this.phoneConfirmed.emit(null);
} else if (result.code === 230) { } else if (result.code === 230) {
this._snackBar.open('Неверный код!', '', { this._snackBar.open('Неверный код!', '', {
duration: 3000 duration: 3000,
}) });
// this.errorConfirmCode = true; // this.errorConfirmCode = true;
} }
}, },
error: (error) => { error: (error) => {
console.error(error); console.error(error);
},
} });
}
);
} }
backToPhoneForm() { backToPhoneForm() {
@ -160,8 +187,8 @@ export class LoginComponent implements OnInit, AfterViewInit {
code: '', code: '',
code1: '', code1: '',
code2: '', code2: '',
code3: '' code3: '',
}) });
this.isShowNumber = true this.isShowNumber = true;
} }
} }