User creation on login (server-seitig)
This commit is contained in:
+33
-7
@@ -5,8 +5,8 @@ function clearAuthState() {
|
||||
auth.mail = ''; // Full mail address
|
||||
auth.roles = {}; // Role authorizations e.g. {user: true}
|
||||
auth.gender = ''; // Gender (e.g. Frau)
|
||||
auth.bookmarks = []; // Ids of bookmarks
|
||||
auth.abos = []; // Abos
|
||||
auth.abos = []; // Followed tags
|
||||
auth.bookmarks = []; // Ids of bookmarks
|
||||
}
|
||||
clearAuthState();
|
||||
|
||||
@@ -20,6 +20,32 @@ function fillAuthState(state) {
|
||||
}
|
||||
}
|
||||
|
||||
function updateUserInDB() {
|
||||
$.ajax({
|
||||
url: "api/usr",
|
||||
data: {
|
||||
abos: JSON.stringify(auth.abos),
|
||||
bookmarks: JSON.stringify(auth.bookmarks),
|
||||
mail: auth.mail,
|
||||
name: auth.name,
|
||||
_id: auth.user,
|
||||
roles: JSON.stringify(auth.roles),
|
||||
type: auth.type,
|
||||
},
|
||||
method: "POST"
|
||||
}).done(successful_save).fail(failed_save);
|
||||
|
||||
function successful_save(res) {
|
||||
console.info("User-save: Successful.");
|
||||
console.info(res);
|
||||
}
|
||||
|
||||
function failed_save(err) {
|
||||
console.info("User-save: Failed.");
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
// Login component: Login panel (if not logged in) or Logout element (if logged in)
|
||||
Vue.component('login-panel', {
|
||||
template: `
|
||||
@@ -57,13 +83,13 @@ Vue.component('login-panel', {
|
||||
</div>`,
|
||||
data: function () {
|
||||
return {
|
||||
auth: auth,
|
||||
user: '',
|
||||
pwd: '',
|
||||
error: false,
|
||||
};
|
||||
},
|
||||
// TODO: Check if enough for session cookie re-login; checkbox
|
||||
// Doesn't work
|
||||
// mounted: function() {
|
||||
// this.checkData();
|
||||
// },
|
||||
@@ -94,6 +120,7 @@ Vue.component('login-panel', {
|
||||
|
||||
function successful_login(resData) {
|
||||
fillAuthState(resData);
|
||||
updateUserInDB();
|
||||
console.info("Correct credentials");
|
||||
this.closeLoginPanel;
|
||||
|
||||
@@ -103,7 +130,7 @@ Vue.component('login-panel', {
|
||||
|
||||
function failed_login(err) {
|
||||
console.info("Wrong credentials");
|
||||
this.showError=true;
|
||||
this.error=true;
|
||||
this.showLoginPanel;
|
||||
|
||||
console.log("error: " + err.responseText);
|
||||
@@ -129,10 +156,9 @@ Vue.component('login-panel', {
|
||||
|
||||
function failed_login(err) {
|
||||
console.info("Re-Auth: Wrong credentials");
|
||||
this.showError=true;
|
||||
this.error=true;
|
||||
this.showLoginPanel;
|
||||
|
||||
console.log("error: " + err.responseText);
|
||||
console.log(err);
|
||||
}
|
||||
},
|
||||
@@ -140,6 +166,6 @@ Vue.component('login-panel', {
|
||||
clearAuthState();
|
||||
$.ajax({ url: "api/logout", method: "POST" });
|
||||
this.closeLoginPanel;
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user