diff --git a/src/js/settings.js b/src/js/settings.js index 866e7ea75..57aced329 100644 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -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) => { diff --git a/src/js/simple-popups.js b/src/js/simple-popups.js index 3d7e0527b..8c67f74e6 100644 --- a/src/js/simple-popups.js +++ b/src/js/simple-popups.js @@ -59,14 +59,20 @@ class SimplePopup { if (this.type === "number") { this.inputs.forEach((input) => { el.find(".inputs").append(` - + `); }); } else if (this.type === "text") { this.inputs.forEach((input) => { - el.find(".inputs").append(` - - `); + if(input.type){ + el.find(".inputs").append(` + + `); + }else{ + el.find(".inputs").append(` + + `); + } }); } 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", diff --git a/static/index.html b/static/index.html index ecda759f7..61ae925ee 100644 --- a/static/index.html +++ b/static/index.html @@ -3784,6 +3784,22 @@ +
+

update account password

+
+ Change the password you use to sign in. +
+
+
+ update password +
+
+