mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 06:29:29 +01:00
core: add support for changing account email
This commit is contained in:
committed by
Abdullah Atta
parent
1b471a2fda
commit
b439571e17
@@ -256,8 +256,12 @@ class Database {
|
|||||||
await this.user.logout(false, "Account Deleted");
|
await this.user.logout(false, "Account Deleted");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "userEmailChanged": {
|
||||||
|
await this.user.logout(true, "Email changed");
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "userPasswordChanged": {
|
case "userPasswordChanged": {
|
||||||
await this.user.logout(true, "Password Changed");
|
await this.user.logout(true, "Password changed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "emailConfirmed": {
|
case "emailConfirmed": {
|
||||||
|
|||||||
@@ -322,16 +322,42 @@ class UserManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendVerificationEmail() {
|
async sendVerificationEmail(newEmail) {
|
||||||
let token = await this.tokenManager.getAccessToken();
|
let token = await this.tokenManager.getAccessToken();
|
||||||
if (!token) return;
|
if (!token) return;
|
||||||
await http.post(
|
await http.post(
|
||||||
`${constants.AUTH_HOST}${ENDPOINTS.verifyUser}`,
|
`${constants.AUTH_HOST}${ENDPOINTS.verifyUser}`,
|
||||||
null,
|
{ newEmail },
|
||||||
token
|
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) {
|
recoverAccount(email) {
|
||||||
return http.post(`${constants.AUTH_HOST}${ENDPOINTS.recoverAccount}`, {
|
return http.post(`${constants.AUTH_HOST}${ENDPOINTS.recoverAccount}`, {
|
||||||
email,
|
email,
|
||||||
|
|||||||
Reference in New Issue
Block a user