mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-07 20:23:05 +08:00
added update email button
This commit is contained in:
parent
cccb670948
commit
6bbc66175f
4 changed files with 76 additions and 14 deletions
|
@ -1170,6 +1170,30 @@ exports.testCompleted = functions
|
|||
}
|
||||
});
|
||||
|
||||
exports.updateEmail = functions.https.onCall(async (request, response) => {
|
||||
try {
|
||||
let previousEmail = await admin.auth().getUser(request.uid);
|
||||
|
||||
if (previousEmail.email !== request.previousEmail) {
|
||||
return { resultCode: -1 };
|
||||
} else {
|
||||
await admin.auth().updateUser(request.uid, {
|
||||
email: request.newEmail,
|
||||
emailVerified: false,
|
||||
});
|
||||
return {
|
||||
resultCode: 1,
|
||||
};
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`error updating email for ${request.uid} - ${e}`);
|
||||
return {
|
||||
resultCode: -999,
|
||||
message: e.message,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
function updateDiscordRole(discordId, wpm) {
|
||||
db.collection("bot-commands").add({
|
||||
command: "updateRole",
|
||||
|
|
|
@ -2791,7 +2791,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section updateAccountEmail hidden">
|
||||
<div class="section updateAccountEmail">
|
||||
<h1>update account email</h1>
|
||||
<div class="text">
|
||||
In case you misspell it or get a new address.
|
||||
|
@ -2801,7 +2801,7 @@
|
|||
class="button off danger"
|
||||
id="updateAccountEmail"
|
||||
tabindex="0"
|
||||
onclick="this.blur();"
|
||||
onclick="this.blur();simplePopups.updateEmail.show();"
|
||||
>
|
||||
update email
|
||||
</div>
|
||||
|
|
|
@ -531,7 +531,12 @@ class SimplePopup {
|
|||
el.find("input").removeClass("hidden");
|
||||
el.find("input").attr("placeholder", this.inputPlaceholder);
|
||||
el.find("input").attr("min", 1);
|
||||
el.find("input").attr("type", "number");
|
||||
el.find("input").val(this.inputVal);
|
||||
} else if (this.type === "text") {
|
||||
el.find("input").removeClass("hidden");
|
||||
el.find("input").attr("placeholder", this.inputPlaceholder);
|
||||
el.find("input").attr("type", "text");
|
||||
} else {
|
||||
el.find("input").addClass("hidden");
|
||||
}
|
||||
|
@ -551,7 +556,9 @@ class SimplePopup {
|
|||
.stop(true, true)
|
||||
.css("opacity", 0)
|
||||
.removeClass("hidden")
|
||||
.animate({ opacity: 1 }, 125);
|
||||
.animate({ opacity: 1 }, 125, () => {
|
||||
$("#simplePopup").find("input").focus();
|
||||
});
|
||||
}
|
||||
|
||||
hide() {
|
||||
|
@ -582,14 +589,44 @@ $(document).on("click", "#simplePopupWrapper .button", (e) => {
|
|||
simplePopups[id].exec();
|
||||
});
|
||||
|
||||
// simplePopups.testPop = new SimplePopup(
|
||||
// 'testPop',
|
||||
// 'number',
|
||||
// 'This is a test',
|
||||
// 'Number',
|
||||
// 1,
|
||||
// 'Test popup that i made to test the class',
|
||||
// 'Go',
|
||||
// (a) => {
|
||||
// console.log(a);
|
||||
// });
|
||||
$(document).on("keyup", "#simplePopupWrapper input", (e) => {
|
||||
if (e.key === "Enter") {
|
||||
let id = $("#simplePopup").attr("popupId");
|
||||
simplePopups[id].exec();
|
||||
}
|
||||
});
|
||||
|
||||
simplePopups.updateEmail = new SimplePopup(
|
||||
"updateEmail",
|
||||
"text",
|
||||
"Update Email",
|
||||
"New email",
|
||||
"",
|
||||
"Don't mess this one up or you won't be able to login!",
|
||||
"Update",
|
||||
(input) => {
|
||||
try {
|
||||
showBackgroundLoader();
|
||||
let currentUser = firebase.auth().currentUser;
|
||||
updateEmail({
|
||||
uid: currentUser.uid,
|
||||
previousEmail: currentUser.email,
|
||||
newEmail: input,
|
||||
}).then((data) => {
|
||||
hideBackgroundLoader();
|
||||
if (data.data.resultCode === 1) {
|
||||
showNotification("Email updated", 2000);
|
||||
} else if (data.data.resultCode === -1) {
|
||||
showNotification("Previous email doesn't match", 2000);
|
||||
} else {
|
||||
showNotification(
|
||||
"Something went wrong: " + JSON.stringify(data.data),
|
||||
7000
|
||||
);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
showNotification("Something went wrong: " + e, 5000);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -215,6 +215,7 @@ const saveLbMemory = firebase.functions().httpsCallable("saveLbMemory");
|
|||
const unlinkDiscord = firebase.functions().httpsCallable("unlinkDiscord");
|
||||
const verifyUser = firebase.functions().httpsCallable("verifyUser");
|
||||
const reserveName = firebase.functions().httpsCallable("reserveDisplayName");
|
||||
const updateEmail = firebase.functions().httpsCallable("updateEmail");
|
||||
|
||||
function refreshThemeColorObject() {
|
||||
let st = getComputedStyle(document.body);
|
||||
|
|
Loading…
Reference in a new issue