update
This commit is contained in:
@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
|
||||
import { AuthService } from './../../services/auth.service';
|
||||
import { MatchingValidator } from './../../utils/matching.validator';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
var openpgp = require('openpgp');
|
||||
@Component({
|
||||
@@ -16,37 +16,39 @@ export class PasswordComponent implements OnInit {
|
||||
public working: boolean;
|
||||
form: FormGroup;
|
||||
|
||||
constructor(private formBuilder: FormBuilder, private authService: AuthService) { }
|
||||
constructor(private formBuilder: FormBuilder, private authService: AuthService, private router: Router) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.form = this.formBuilder.group({
|
||||
username: ['', Validators.required],
|
||||
privateKey: ['', Validators.required]
|
||||
privateKey: ['']
|
||||
});
|
||||
}
|
||||
|
||||
async passwordReset() {
|
||||
async passwordRequest() {
|
||||
this.working = true;
|
||||
const { keys: [privateKey] } = await openpgp.key.readArmored(this.model.privateKey);
|
||||
|
||||
|
||||
console.log(privateKey.isPrivate());
|
||||
|
||||
const model = {
|
||||
username: this.model.username
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
const message = await openpgp.message.readArmored(encrypted);
|
||||
|
||||
const decrypted = await openpgp.decrypt({
|
||||
message: message,
|
||||
privateKeys: [privateKey]
|
||||
});
|
||||
|
||||
console.log(decrypted);
|
||||
// this.authService.passwordReset(model).subscribe(async response => { })
|
||||
*/
|
||||
this.authService.passwordRequest(this.model.username).subscribe(async response => {
|
||||
|
||||
if (privateKey) {
|
||||
const message = await openpgp.message.readArmored(response);
|
||||
|
||||
const decrypted = await openpgp.decrypt({
|
||||
message: message,
|
||||
privateKeys: [privateKey]
|
||||
});
|
||||
this.working = false;
|
||||
this.router.navigate(['/password-reset'], { queryParams: { token: decrypted.data.trim() } });
|
||||
} else {
|
||||
this.working = false;
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user