From 136b3dd7986fb405d47f04128cf1b7c015210c3e Mon Sep 17 00:00:00 2001 From: Miodec Date: Tue, 25 Jan 2022 15:33:06 +0100 Subject: [PATCH] allowing email and pass update if password auth is enabled, added add password auth popup --- src/js/simple-popups.js | 56 +++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/src/js/simple-popups.js b/src/js/simple-popups.js index edd6cfedb..9362028c5 100644 --- a/src/js/simple-popups.js +++ b/src/js/simple-popups.js @@ -232,12 +232,10 @@ list.updateEmail = new SimplePopup( }, () => { const user = firebase.auth().currentUser; - if (user.providerData[0].providerId === "google.com") { + if (!user.providerData.find((p) => p.providerId === "password")) { eval(`this.inputs = []`); eval(`this.buttonText = undefined`); - eval( - `this.text = "You can't change your email when using Google Authentication";` - ); + eval(`this.text = "Password authentication is not enabled";`); } } ); @@ -377,16 +375,58 @@ list.updatePassword = new SimplePopup( }, () => { const user = firebase.auth().currentUser; - if (user.providerData[0].providerId === "google.com") { + if (!user.providerData.find((p) => p.providerId === "password")) { eval(`this.inputs = []`); eval(`this.buttonText = undefined`); - eval( - `this.text = "You can't change your password when using Google Authentication";` - ); + eval(`this.text = "Password authentication is not enabled";`); } } ); +list.addPasswordAuth = new SimplePopup( + "addPasswordAuth", + "text", + "Add Password Authentication", + [ + { + placeholder: "email", + type: "email", + initVal: "", + }, + { + placeholder: "confirm email", + type: "email", + initVal: "", + }, + { + placeholder: "new password", + type: "password", + initVal: "", + }, + { + placeholder: "confirm new password", + type: "password", + initVal: "", + }, + ], + "", + "Add", + async (email, emailConfirm, pass, passConfirm) => { + if (email !== emailConfirm) { + Notifications.add("Emails don't match", 0); + return; + } + + if (pass !== passConfirm) { + Notifications.add("Passwords don't match", 0); + return; + } + + AccountController.addPasswordAuth(email, pass); + }, + () => {} +); + list.deleteAccount = new SimplePopup( "deleteAccount", "text",