mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-10 17:04:49 +08:00
converted email updating
This commit is contained in:
parent
0be16ac467
commit
674316784a
4 changed files with 19 additions and 9 deletions
|
@ -65,6 +65,17 @@ class UserController {
|
|||
}
|
||||
}
|
||||
|
||||
static async updateEmail(req, res, next) {
|
||||
try {
|
||||
const { uid } = req.decodedToken;
|
||||
const { newEmail } = req.body;
|
||||
await UsersDAO.updateEmail(uid, newEmail);
|
||||
return res.sendStatus(200);
|
||||
} catch (e) {
|
||||
return next(e);
|
||||
}
|
||||
}
|
||||
|
||||
static async getUser(req, res, next) {
|
||||
try {
|
||||
const { uid } = req.decodedToken;
|
||||
|
|
|
@ -12,6 +12,8 @@ router.post("/delete", UserController.deleteUser);
|
|||
|
||||
router.post("/updateName", authenticateRequest, UserController.updateName);
|
||||
|
||||
router.post("/updateEmail", authenticateRequest, UserController.updateEmail);
|
||||
|
||||
router.get("/", authenticateRequest, UserController.getUser);
|
||||
|
||||
router.post("/tags/add", authenticateRequest, UserController.addTag);
|
||||
|
|
|
@ -37,7 +37,9 @@ class UsersDAO {
|
|||
static async updateEmail(uid, email) {
|
||||
const user = await mongoDB().collection("users").findOne({ uid });
|
||||
if (!user) throw new MonkeyError(404, "User not found");
|
||||
return await updateAuthEmail(uid, email);
|
||||
await updateAuthEmail(uid, email);
|
||||
await mongoDB().collection("users").updateOne({ uid }, { $set: { email } });
|
||||
return true;
|
||||
}
|
||||
|
||||
static async getUser(uid) {
|
||||
|
|
|
@ -172,25 +172,20 @@ list.updateEmail = new SimplePopup(
|
|||
.reauthenticateWithCredential(credential)
|
||||
.then(() => {
|
||||
axiosInstance
|
||||
.post("/updateEmail", {
|
||||
.post("/user/updateEmail", {
|
||||
uid: user.uid,
|
||||
previousEmail: previousEmail,
|
||||
newEmail: newEmail,
|
||||
})
|
||||
.then((data) => {
|
||||
Loader.hide();
|
||||
if (data.data.resultCode === 1) {
|
||||
if (data.status === 200) {
|
||||
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(data.message);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue