update
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<form [formGroup]="form" (ngSubmit)="passwordReset()">
|
||||
<form [formGroup]="form" (ngSubmit)="passwordRequest()">
|
||||
<mat-card>
|
||||
<mat-card-content>
|
||||
<h2>{{'password.request' | i18n}}</h2>
|
||||
@@ -10,15 +10,17 @@
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>{{'pgp-key.private' | i18n}}</mat-label>
|
||||
<mat-label>{{'pgp.privateKey' | i18n}}</mat-label>
|
||||
<textarea matInput formControlName="privateKey" placeholder="Private Key"
|
||||
[(ngModel)]="model.privateKey"></textarea>
|
||||
</mat-form-field>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button *ngIf="!working" mat-raised-button color="primary" [disabled]="form.invalid">
|
||||
{{'password.reset' | i18n}}
|
||||
{{'password.request' | i18n}}
|
||||
</button>
|
||||
|
||||
<mat-progress-bar *ngIf="working" mode="indeterminate"></mat-progress-bar>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</form>
|
||||
@@ -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