-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReset.ts
More file actions
36 lines (28 loc) · 1.09 KB
/
Reset.ts
File metadata and controls
36 lines (28 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { RemoteService } from "./RemoteService";
import { User } from "./User";
import { JWT } from "./JWT";
let remoteService: RemoteService;
export class ResetManager {
public static init (stage: "dev"|"beta"|"prod") {
remoteService = new RemoteService(stage, "reset");
}
static allegedRemainingMinutes (unverifiedJWTString: string): number {
if (!unverifiedJWTString) {
return 0;
}
const unverifiedJWT = JWT.parse(unverifiedJWTString);
if (!unverifiedJWT || !unverifiedJWT.sub || !unverifiedJWT.exp) {
return 0;
}
return Math.floor((unverifiedJWT.exp - Date.now()) / 60000);
}
static async resetUser (email: string, unverifiedJWTString: string, hashedMasterKey: ArrayBuffer) {
if (!remoteService) {
return false;
}
const userOrFalse = await User.fromResetProcess(email, unverifiedJWTString, hashedMasterKey, payload => {
return remoteService.postRequest("resetPasswordConfirm", payload, unverifiedJWTString);
});
return userOrFalse;
}
}