добавил обновление имени и даты рождения(заглшка, чтобы работал костыль в СА) при авторизации
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,
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<string>();
@ -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;
}
}