1
0
Fork 0

removed sync calls from user views

This commit is contained in:
hkernbach 2016-02-19 21:39:51 +01:00
parent e1af85af36
commit e9259f1ae3
2 changed files with 50 additions and 42 deletions

View File

@ -28,29 +28,27 @@ window.Users = Backbone.Model.extend({
return "/_api/user"; return "/_api/user";
}, },
checkPassword: function(passwd) { checkPassword: function(passwd, callback) {
var result = false;
$.ajax({ $.ajax({
cache: false, cache: false,
type: "POST", type: "POST",
async: false, // sequential calls!
url: "/_api/user/" + this.get("user"), url: "/_api/user/" + this.get("user"),
data: JSON.stringify({ passwd: passwd }), data: JSON.stringify({ passwd: passwd }),
contentType: "application/json", contentType: "application/json",
processData: false, processData: false,
success: function(data) { success: function(data) {
result = data.result; callback(false, data);
},
error: function(data) {
callback(true, data);
} }
}); });
return result;
}, },
setPassword: function(passwd) { setPassword: function(passwd) {
$.ajax({ $.ajax({
cache: false, cache: false,
type: "PATCH", type: "PATCH",
async: false, // sequential calls!
url: "/_api/user/" + this.get("user"), url: "/_api/user/" + this.get("user"),
data: JSON.stringify({ passwd: passwd }), data: JSON.stringify({ passwd: passwd }),
contentType: "application/json", contentType: "application/json",
@ -58,15 +56,20 @@ window.Users = Backbone.Model.extend({
}); });
}, },
setExtras: function(name, img) { setExtras: function(name, img, callback) {
$.ajax({ $.ajax({
cache: false, cache: false,
type: "PATCH", type: "PATCH",
async: false, // sequential calls!
url: "/_api/user/" + this.get("user"), url: "/_api/user/" + this.get("user"),
data: JSON.stringify({"extra": {"name":name, "img":img}}), data: JSON.stringify({"extra": {"name":name, "img":img}}),
contentType: "application/json", contentType: "application/json",
processData: false processData: false,
success: function() {
callback(false);
},
error: function() {
callback(true);
}
}); });
} }

View File

@ -339,49 +339,54 @@
$('#newCurrentPassword').closest("th").css("backgroundColor", "white"); $('#newCurrentPassword').closest("th").css("backgroundColor", "white");
$('#confirmCurrentPassword').closest("th").css("backgroundColor", "white"); $('#confirmCurrentPassword').closest("th").css("backgroundColor", "white");
//check //check
var hasError = false; var hasError = false;
//Check old password
if (!this.validateCurrentPassword(oldPasswd)) {
$('#oldCurrentPassword').closest("th").css("backgroundColor", "red");
hasError = true;
}
//check confirmation
if (newPasswd !== confirmPasswd) {
$('#confirmCurrentPassword').closest("th").css("backgroundColor", "red");
hasError = true;
}
//check new password
if (!this.validatePassword(newPasswd)) {
$('#newCurrentPassword').closest("th").css("backgroundColor", "red");
hasError = true;
}
if (hasError) { var callback = function(error, data) {
return; if (error) {
} arangoHelper.arangoError("User", "Could not verify old password");
this.currentUser.setPassword(newPasswd); }
window.modalView.hide(); else {
if (data) {
//check confirmation
if (newPasswd !== confirmPasswd) {
arangoHelper.arangoError("User", "New passwords do not match");
hasError = true;
}
//check new password
/*if (!this.validatePassword(newPasswd)) {
$('#newCurrentPassword').closest("th").css("backgroundColor", "red");
hasError = true;
}*/
if (!hasError) {
this.currentUser.setPassword(newPasswd);
arangoHelper.arangoNotification("User", "Password changed");
window.modalView.hide();
}
}
}
}.bind(this);
this.currentUser.checkPassword(oldPasswd, callback);
}, },
validateCurrentPassword : function (pwd) {
return this.currentUser.checkPassword(pwd);
},
submitEditCurrentUserProfile: function() { submitEditCurrentUserProfile: function() {
var name = $('#editCurrentName').val(); var name = $('#editCurrentName').val();
var img = $('#editCurrentUserProfileImg').val(); var img = $('#editCurrentUserProfileImg').val();
img = this.parseImgString(img); img = this.parseImgString(img);
/* if (!this.validateName(name)) {
$('#editName').closest("th").css("backgroundColor", "red");
return;
}*/
this.currentUser.setExtras(name, img); var callback = function(error) {
this.updateUserProfile(); if (error) {
arangoHelper.arangoError("User", "Could not edit user settings");
}
else {
arangoHelper.arangoNotification("User", "Changes confirmed.");
this.updateUserProfile();
}
}.bind(this);
this.currentUser.setExtras(name, img, callback);
window.modalView.hide(); window.modalView.hide();
}, },