added update password popup

update email now requires password
This commit is contained in:
Miodec 2021-06-17 16:43:07 +01:00
parent 2e4826a6a6
commit 67ef58ba4d
3 changed files with 116 additions and 26 deletions

View file

@ -793,6 +793,10 @@ $(".pageSettings #updateAccountEmail").on("click", (e) => {
SimplePopups.list.updateEmail.show();
});
$(".pageSettings #updateAccountPassword").on("click", (e) => {
SimplePopups.list.updatePassword.show();
});
$(".pageSettings .section.customBackgroundSize .inputAndButton .save").on(
"click",
(e) => {

View file

@ -59,14 +59,20 @@ class SimplePopup {
if (this.type === "number") {
this.inputs.forEach((input) => {
el.find(".inputs").append(`
<input type="number" min="1" val="${input.initVal}" placeholder="${input.placeholder}" required>
<input type="number" min="1" val="${input.initVal}" placeholder="${input.placeholder}" required autocomplete="off">
`);
});
} else if (this.type === "text") {
this.inputs.forEach((input) => {
el.find(".inputs").append(`
<input type="text" val="${input.initVal}" placeholder="${input.placeholder}" required>
`);
if(input.type){
el.find(".inputs").append(`
<input type="${input.type}" val="${input.initVal}" placeholder="${input.placeholder}" required autocomplete="off">
`);
}else{
el.find(".inputs").append(`
<input type="text" val="${input.initVal}" placeholder="${input.placeholder}" required autocomplete="off">
`);
}
});
}
el.find(".inputs").removeClass("hidden");
@ -108,7 +114,7 @@ class SimplePopup {
}
}
$("#simplePopupWrapper").click((e) => {
$("#simplePopupWrapper").mousedown((e) => {
if ($(e.target).attr("id") === "simplePopupWrapper") {
$("#simplePopupWrapper")
.stop(true, true)
@ -138,6 +144,11 @@ list.updateEmail = new SimplePopup(
"text",
"Update Email",
[
{
placeholder: "Password",
type: "password",
initVal: "",
},
{
placeholder: "Current email",
initVal: "",
@ -147,31 +158,41 @@ list.updateEmail = new SimplePopup(
initVal: "",
},
],
"Don't mess this one up or you won't be able to login!",
"",
"Update",
(previousEmail, newEmail) => {
(pass,previousEmail, newEmail) => {
try {
const user = firebase.auth().currentUser;
const credential = firebase.auth.EmailAuthProvider.credential(
user.email,
pass
);
Loader.show();
CloudFunctions.updateEmail({
uid: firebase.auth().currentUser.uid,
previousEmail: previousEmail,
newEmail: newEmail,
}).then((data) => {
user.reauthenticateWithCredential(pass).then(() => {
CloudFunctions.updateEmail({
uid: user.uid,
previousEmail: previousEmail,
newEmail: newEmail,
}).then((data) => {
Loader.hide();
if (data.data.resultCode === 1) {
Notifications.add("Email updated", 0);
setTimeout(() => {
AccountController.signOut();
}, 1000);
} else if (data.data.resultCode === -1) {
Notifications.add("Current email doesn't match", 0);
} else {
Notifications.add(
"Something went wrong: " + JSON.stringify(data.data),
-1
);
}
});
}).catch(e => {
Loader.hide();
if (data.data.resultCode === 1) {
Notifications.add("Email updated", 0);
setTimeout(() => {
AccountController.signOut();
}, 1000);
} else if (data.data.resultCode === -1) {
Notifications.add("Current email doesn't match", 0);
} else {
Notifications.add(
"Something went wrong: " + JSON.stringify(data.data),
-1
);
}
});
Notifications.add("Incorrect current password", -1);
})
} catch (e) {
Notifications.add("Something went wrong: " + e, -1);
}
@ -179,6 +200,55 @@ list.updateEmail = new SimplePopup(
() => {}
);
list.updatePassword = new SimplePopup(
"updatePassword",
"text",
"Update Password",
[
{
placeholder: "Current password",
type: "password",
initVal: "",
},
{
placeholder: "New password",
type: "password",
initVal: "",
},
{
placeholder: "Confirm new password",
type: "password",
initVal: "",
},
],
"",
"Update",
async (previousPass, newPass, newPassConfirm) => {
try {
const user = firebase.auth().currentUser;
const credential = firebase.auth.EmailAuthProvider.credential(
user.email,
previousPass
);
if(newPass !== newPassConfirm){
Notifications.add("New passwords don't match",0);
return;
}
Loader.show();
await user.reauthenticateWithCredential(credential);
await user.updatePassword(newPass);
Loader.hide();
Notifications.add("Password updated", 1);
} catch (e) {
Loader.hide();
Notifications.add(e, -1);
}
},
() => {}
);
list.clearTagPb = new SimplePopup(
"clearTagPb",
"text",

View file

@ -3784,6 +3784,22 @@
</div>
</div>
</div>
<div class="section updateAccountPassword">
<h1>update account password</h1>
<div class="text">
Change the password you use to sign in.
</div>
<div class="buttons">
<div
class="button off danger"
id="updateAccountPassword"
tabindex="0"
onclick="this.blur();"
>
update password
</div>
</div>
</div>
<div class="section deleteAccount hidden">
<h1>delete account</h1>
<div class="text">