Commit 74d92482 authored by David Burke's avatar David Burke

Change password gives user their backup code

parent e2bb912c
Pipeline #39350797 passed with stage
in 5 minutes and 44 seconds
This diff is collapsed.
......@@ -139,4 +139,4 @@
"version": "5.0.0"
}
}
}
\ No newline at end of file
}
......@@ -29,15 +29,7 @@ export class ChangePasswordEffects {
this.userService
.changePassword(formValue.oldPassword, formValue.newPassword)
.pipe(
exhaustMap(() =>
this.userService.makeAndSetBackupCode(formValue.newPassword).pipe(
// change to backupCode once login functionality is added
map(backupCode => new SubmitFormSuccess(backupCode)),
catchError(err =>
of(new SubmitFormFailure(["Unexpected backup code error."]))
)
)
),
map(resp => new SubmitFormSuccess(resp.backupCode)),
catchError(err => {
if (err.res.status === 400) {
return of(new SubmitFormFailure(["Incorrect password"]));
......
......@@ -176,7 +176,7 @@ export default class Api {
public changePassword(
changePassword: IChangePassword
): Promise<{ success: boolean }> {
): Promise<{ success: boolean, token: string }> {
return this.post("change-password/", changePassword);
}
......
......@@ -610,12 +610,10 @@ export default class PassitSDK {
*
* @param oldPassword - existing password
* @param newPassword - new password to use
* @returns { privateKeyBackup, token }
*/
@authRequired
public async change_password(
oldPassword: string,
newPassword: string
): Promise<void> {
public async change_password(oldPassword: string, newPassword: string) {
// Hash old password
const user = await this.api.getUser();
const oldHash = hashPassword(oldPassword, user.client_salt).hash;
......@@ -636,7 +634,7 @@ export default class PassitSDK {
newUserKeyPair.privateKey
).string;
await this.api.changePassword({
const response = await this.api.changePassword({
old_password: oldHash,
user: {
client_salt: salt,
......@@ -648,6 +646,11 @@ export default class PassitSDK {
secret_through_set: secretThroughSet,
group_user_set: groupUserSet
});
return {
backupCode,
token: response.token
};
}
/** Encrypt all user secrets with supplied user key pair.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment