core: add support for changing account email

This commit is contained in:
Abdullah Atta
2023-01-09 15:04:44 +05:00
committed by Abdullah Atta
parent 1b471a2fda
commit b439571e17
2 changed files with 33 additions and 3 deletions

View File

@@ -322,16 +322,42 @@ class UserManager {
}
}
async sendVerificationEmail() {
async sendVerificationEmail(newEmail) {
let token = await this.tokenManager.getAccessToken();
if (!token) return;
await http.post(
`${constants.AUTH_HOST}${ENDPOINTS.verifyUser}`,
null,
{ newEmail },
token
);
}
async changeEmail(newEmail, password, code) {
const token = await this.tokenManager.getAccessToken();
if (!token) return;
const user = await this.getUser();
if (!user) return;
const email = newEmail.toLowerCase();
await http.patch(
`${constants.AUTH_HOST}${ENDPOINTS.patchUser}`,
{
type: "change_email",
new_email: newEmail,
password: await this._storage.hash(password, email),
verification_code: code
},
token
);
await this._storage.deriveCryptoKey(`_uk_@${newEmail}`, {
password,
salt: user.salt
});
}
recoverAccount(email) {
return http.post(`${constants.AUTH_HOST}${ENDPOINTS.recoverAccount}`, {
email,