mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-13 07:23:39 +08:00
first attempt to rewrite axios to use new endpoints
This commit is contained in:
parent
29dfcd93d3
commit
35de40dda1
1 changed files with 116 additions and 111 deletions
|
@ -121,7 +121,7 @@ export function signOut() {
|
|||
});
|
||||
}
|
||||
|
||||
function signUp() {
|
||||
async function signUp() {
|
||||
$(".pageLogin .register .button").addClass("disabled");
|
||||
$(".pageLogin .preloader").removeClass("hidden");
|
||||
let nname = $(".pageLogin .register input")[0].value;
|
||||
|
@ -135,116 +135,121 @@ function signUp() {
|
|||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
return;
|
||||
}
|
||||
axiosInstance.get(`/nameCheck/${nname}`).then((d) => {
|
||||
console.log(d.data);
|
||||
if (d.data.resultCode === -1) {
|
||||
Notifications.add("Name unavailable", -1);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
return;
|
||||
} else if (d.data.resultCode === -2) {
|
||||
Notifications.add(
|
||||
"Name cannot contain special characters or contain more than 14 characters. Can include _ . and -",
|
||||
-1
|
||||
);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
return;
|
||||
} else if (d.data.resultCode === 1) {
|
||||
firebase
|
||||
.auth()
|
||||
.createUserWithEmailAndPassword(email, password)
|
||||
.then((user) => {
|
||||
// Account has been created here.
|
||||
// dontCheckUserName = true;
|
||||
let usr = user.user;
|
||||
//maybe there's a better place for the api call
|
||||
axiosInstance.post("/signUp", {
|
||||
name: nname,
|
||||
uid: usr.uid,
|
||||
email: email,
|
||||
});
|
||||
usr
|
||||
.updateProfile({
|
||||
displayName: nname,
|
||||
})
|
||||
.then(async function () {
|
||||
// Update successful.
|
||||
usr.sendEmailVerification();
|
||||
AllTimeStats.clear();
|
||||
Notifications.add("Account created", 1, 3);
|
||||
$("#menu .icon-button.account .text").text(nname);
|
||||
try {
|
||||
firebase.analytics().logEvent("accountCreated", usr.uid);
|
||||
} catch (e) {
|
||||
console.log("Analytics unavailable");
|
||||
}
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
DB.setSnapshot({
|
||||
results: [],
|
||||
personalBests: {},
|
||||
tags: [],
|
||||
globalStats: {
|
||||
time: undefined,
|
||||
started: undefined,
|
||||
completed: undefined,
|
||||
},
|
||||
});
|
||||
if (TestLogic.notSignedInLastResult !== null) {
|
||||
TestLogic.setNotSignedInUid(usr.uid);
|
||||
axiosInstance
|
||||
.post("/testCompleted", {
|
||||
obj: TestLogic.notSignedInLastResult,
|
||||
})
|
||||
.then(() => {
|
||||
DB.getSnapshot().results.push(
|
||||
TestLogic.notSignedInLastResult
|
||||
);
|
||||
});
|
||||
}
|
||||
UI.changePage("account");
|
||||
usr.sendEmailVerification();
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
})
|
||||
.catch(function (error) {
|
||||
// An error happened.
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
console.error(error);
|
||||
usr
|
||||
.delete()
|
||||
.then(function () {
|
||||
// User deleted.
|
||||
Notifications.add(
|
||||
"Account not created. " + error.message,
|
||||
-1
|
||||
);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
})
|
||||
.catch(function (error) {
|
||||
// An error happened.
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
Notifications.add(
|
||||
"Something went wrong. " + error.message,
|
||||
-1
|
||||
);
|
||||
console.error(error);
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(function (error) {
|
||||
// Handle Errors here.
|
||||
$(".pageLogin .register .button").removeClass("disabled");
|
||||
Notifications.add(error.message, -1);
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
});
|
||||
} else {
|
||||
$(".pageLogin .preloader").addClass("hidden");
|
||||
Notifications.add(
|
||||
"Something went wrong when checking name: " + d.data.message,
|
||||
-1
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
const checkName = await axiosInstance.get("/user/checkName");
|
||||
console.log(checkName);
|
||||
return;
|
||||
|
||||
// axiosInstance.get(`/nameCheck/${nname}`).then((d) => {
|
||||
// console.log(d.data);
|
||||
// if (d.data.resultCode === -1) {
|
||||
// Notifications.add("Name unavailable", -1);
|
||||
// $(".pageLogin .preloader").addClass("hidden");
|
||||
// $(".pageLogin .register .button").removeClass("disabled");
|
||||
// return;
|
||||
// } else if (d.data.resultCode === -2) {
|
||||
// Notifications.add(
|
||||
// "Name cannot contain special characters or contain more than 14 characters. Can include _ . and -",
|
||||
// -1
|
||||
// );
|
||||
// $(".pageLogin .preloader").addClass("hidden");
|
||||
// $(".pageLogin .register .button").removeClass("disabled");
|
||||
// return;
|
||||
// } else if (d.data.resultCode === 1) {
|
||||
// firebase
|
||||
// .auth()
|
||||
// .createUserWithEmailAndPassword(email, password)
|
||||
// .then((user) => {
|
||||
// // Account has been created here.
|
||||
// // dontCheckUserName = true;
|
||||
// let usr = user.user;
|
||||
// //maybe there's a better place for the api call
|
||||
// axiosInstance.post("/signUp", {
|
||||
// name: nname,
|
||||
// uid: usr.uid,
|
||||
// email: email,
|
||||
// });
|
||||
// usr
|
||||
// .updateProfile({
|
||||
// displayName: nname,
|
||||
// })
|
||||
// .then(async function () {
|
||||
// // Update successful.
|
||||
// usr.sendEmailVerification();
|
||||
// AllTimeStats.clear();
|
||||
// Notifications.add("Account created", 1, 3);
|
||||
// $("#menu .icon-button.account .text").text(nname);
|
||||
// try {
|
||||
// firebase.analytics().logEvent("accountCreated", usr.uid);
|
||||
// } catch (e) {
|
||||
// console.log("Analytics unavailable");
|
||||
// }
|
||||
// $(".pageLogin .preloader").addClass("hidden");
|
||||
// DB.setSnapshot({
|
||||
// results: [],
|
||||
// personalBests: {},
|
||||
// tags: [],
|
||||
// globalStats: {
|
||||
// time: undefined,
|
||||
// started: undefined,
|
||||
// completed: undefined,
|
||||
// },
|
||||
// });
|
||||
// if (TestLogic.notSignedInLastResult !== null) {
|
||||
// TestLogic.setNotSignedInUid(usr.uid);
|
||||
// axiosInstance
|
||||
// .post("/testCompleted", {
|
||||
// obj: TestLogic.notSignedInLastResult,
|
||||
// })
|
||||
// .then(() => {
|
||||
// DB.getSnapshot().results.push(
|
||||
// TestLogic.notSignedInLastResult
|
||||
// );
|
||||
// });
|
||||
// }
|
||||
// UI.changePage("account");
|
||||
// usr.sendEmailVerification();
|
||||
// $(".pageLogin .register .button").removeClass("disabled");
|
||||
// })
|
||||
// .catch(function (error) {
|
||||
// // An error happened.
|
||||
// $(".pageLogin .register .button").removeClass("disabled");
|
||||
// console.error(error);
|
||||
// usr
|
||||
// .delete()
|
||||
// .then(function () {
|
||||
// // User deleted.
|
||||
// Notifications.add(
|
||||
// "Account not created. " + error.message,
|
||||
// -1
|
||||
// );
|
||||
// $(".pageLogin .preloader").addClass("hidden");
|
||||
// })
|
||||
// .catch(function (error) {
|
||||
// // An error happened.
|
||||
// $(".pageLogin .preloader").addClass("hidden");
|
||||
// Notifications.add(
|
||||
// "Something went wrong. " + error.message,
|
||||
// -1
|
||||
// );
|
||||
// console.error(error);
|
||||
// });
|
||||
// });
|
||||
// })
|
||||
// .catch(function (error) {
|
||||
// // Handle Errors here.
|
||||
// $(".pageLogin .register .button").removeClass("disabled");
|
||||
// Notifications.add(error.message, -1);
|
||||
// $(".pageLogin .preloader").addClass("hidden");
|
||||
// });
|
||||
// } else {
|
||||
// $(".pageLogin .preloader").addClass("hidden");
|
||||
// Notifications.add(
|
||||
// "Something went wrong when checking name: " + d.data.message,
|
||||
// -1
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
$(".pageLogin #forgotPasswordButton").click((e) => {
|
||||
|
|
Loading…
Reference in a new issue