auto fill sms

This commit is contained in:
nikolay 2023-06-20 10:12:32 +04:00
parent d66f72dc2e
commit 7b5200d9f8
4 changed files with 47 additions and 3 deletions

View File

@ -25,6 +25,7 @@
"@fortawesome/free-brands-svg-icons": "^6.2.0",
"@fortawesome/free-solid-svg-icons": "^6.2.0",
"@types/uuid": "^8.3.4",
"@types/web": "^0.0.99",
"angular-moment-timezone": "^1.7.1",
"barcode-2-svg": "^0.3.3",
"firebase": "^9.9.3",
@ -5313,6 +5314,11 @@
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz",
"integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw=="
},
"node_modules/@types/web": {
"version": "0.0.99",
"resolved": "https://registry.npmjs.org/@types/web/-/web-0.0.99.tgz",
"integrity": "sha512-xMz3tOvtkZzc7RpQrDNiLe5sfMmP+fz8bOxHIZ/U8qXyvzDX4L4Ss1HCjor/O9DSelba+1iXK1VM7lruX28hiQ=="
},
"node_modules/@types/ws": {
"version": "8.5.4",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.4.tgz",
@ -18540,6 +18546,11 @@
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz",
"integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw=="
},
"@types/web": {
"version": "0.0.99",
"resolved": "https://registry.npmjs.org/@types/web/-/web-0.0.99.tgz",
"integrity": "sha512-xMz3tOvtkZzc7RpQrDNiLe5sfMmP+fz8bOxHIZ/U8qXyvzDX4L4Ss1HCjor/O9DSelba+1iXK1VM7lruX28hiQ=="
},
"@types/ws": {
"version": "8.5.4",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.4.tgz",

View File

@ -27,6 +27,7 @@
"@fortawesome/free-brands-svg-icons": "^6.2.0",
"@fortawesome/free-solid-svg-icons": "^6.2.0",
"@types/uuid": "^8.3.4",
"@types/web": "^0.0.99",
"angular-moment-timezone": "^1.7.1",
"barcode-2-svg": "^0.3.3",
"firebase": "^9.9.3",

View File

@ -45,9 +45,9 @@
</form>
<ng-template #smsCode>
<h2>Введите код из SMS</h2>
<h2>Введите код из SMS</h2>
<form class="code-form" [formGroup]="codeForm" (ngSubmit)="submitCode()">
<div class="inputs-container">
<div class="inputs-container">
<label class="box"
><input
class="field"

View File

@ -1,3 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import {
AfterViewInit,
Component,
@ -41,7 +43,37 @@ export class LoginComponent implements OnInit, AfterViewInit {
private jsonRpcService: JsonrpcService
) {}
ngOnInit(): void {}
ngOnInit(): void {
if ('OTPCredential' in window) {
console.log('have otp credential');
window.addEventListener('DOMContentLoaded', e => {
const form = document.querySelector('.code-form');
const ac = new AbortController();
if (form) {
form.addEventListener('submit', e => {
ac.abort();
});
}
navigator.credentials.get({
otp: { transport:['sms'] },
signal: ac.signal
}).then(otp => {
console.log(otp)
const input1 = document.getById("field");
const input2 = document.getById("field1");
const input3 = document.getById("field2");
const input4 = document.getById("field3");
input1.value = otp.code[0];
input2.value = otp.code[1];
input3.value = otp.code[2];
input4.value = otp.code[3];
if (form) form.submit();
}).catch(err => {
console.log(err);
});
});
}
}
ngAfterViewInit() {
setTimeout(() => {