Add JavaScript files and edit profile CSS

1) finished edit profile with delete profile
This commit is contained in:
newtbot
2024-01-23 01:44:11 +08:00
parent d819ac71b2
commit 5b262eb803
14 changed files with 296 additions and 334 deletions

View File

@ -159,7 +159,15 @@ app.auth = (function (app) {
if (getToken()) {
return app.api.get("user/me", function (error, data) {
if (!error) app.auth.user = data;
//$.scope.getUsername.push(data);
//for navbar to show username
$.scope.getUsername.update(data);
//for edit profile to show user details
//if not in edit profile page, it will not show
if (location.pathname === "/profile")
{
$.scope.getUserDetails.update(data);
}
return callback(error, data);
});
} else {
@ -167,16 +175,6 @@ app.auth = (function (app) {
}
}
function showUser(){
app.api.get("user/me", function (error, data) {
if (!error) app.auth.user = data;
$.scope.getUsername.push(data);
});
}
function logOut(callback) {
//call logout route
$.ajax({
@ -217,19 +215,13 @@ app.auth = (function (app) {
}
function homeRedirect() {
window.location.href = location.href.replace(location.replace(`/`)) || "/";
//window.location.href = location.href.replace(location.replace(`/`)) || "/";
location.replace(`/`);
}
/*
function redirectIfLoggedIn() {
if (getToken()){
homeRedirect();
}
logInRedirect();
function profileRedirect() {
location.replace(`/profile`);
}
*/
return {
getToken: getToken,
@ -239,11 +231,33 @@ app.auth = (function (app) {
forceLogin,
logInRedirect,
homeRedirect,
showUser,
profileRedirect,
//showUser,
//redirectIfLoggedIn,
};
})(app);
app.user = (function (app) {
//delete profile
function deleteProfile() {
app.api.delete("user/delete", function (error, data) {
if (error) {
app.util.actionMessage(error.message, $("#deleteProfile"), "danger");
} else {
app.auth.logOut(function () {
location.replace(`/login`);
});
}
});
}
return {
deleteProfile,
};
})(app);
//ajax form submit and pass to api
function formAJAX(btn, del) {
event.preventDefault(); // avoid to execute the actual submit of the form.
@ -251,11 +265,6 @@ function formAJAX(btn, del) {
var formData = $form.find("[name]").serializeObject(); // builds query formDataing
var method = $form.attr("method") || "post";
// if( !$form.validate()) {
// app.util.actionMessage('Please fix the form errors.', $form, 'danger')
// return false;
// }
app.util.actionMessage("Loading...", $form, "info");
//console.log('Data being sent to', $form.attr('action'), formData)