mirror of https://gitee.com/bigwinds/arangodb
removed sync calls from user views
This commit is contained in:
parent
e1af85af36
commit
e9259f1ae3
|
@ -28,29 +28,27 @@ window.Users = Backbone.Model.extend({
|
|||
return "/_api/user";
|
||||
},
|
||||
|
||||
checkPassword: function(passwd) {
|
||||
var result = false;
|
||||
|
||||
checkPassword: function(passwd, callback) {
|
||||
$.ajax({
|
||||
cache: false,
|
||||
type: "POST",
|
||||
async: false, // sequential calls!
|
||||
url: "/_api/user/" + this.get("user"),
|
||||
data: JSON.stringify({ passwd: passwd }),
|
||||
contentType: "application/json",
|
||||
processData: false,
|
||||
success: function(data) {
|
||||
result = data.result;
|
||||
callback(false, data);
|
||||
},
|
||||
error: function(data) {
|
||||
callback(true, data);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
},
|
||||
|
||||
setPassword: function(passwd) {
|
||||
$.ajax({
|
||||
cache: false,
|
||||
type: "PATCH",
|
||||
async: false, // sequential calls!
|
||||
url: "/_api/user/" + this.get("user"),
|
||||
data: JSON.stringify({ passwd: passwd }),
|
||||
contentType: "application/json",
|
||||
|
@ -58,15 +56,20 @@ window.Users = Backbone.Model.extend({
|
|||
});
|
||||
},
|
||||
|
||||
setExtras: function(name, img) {
|
||||
setExtras: function(name, img, callback) {
|
||||
$.ajax({
|
||||
cache: false,
|
||||
type: "PATCH",
|
||||
async: false, // sequential calls!
|
||||
url: "/_api/user/" + this.get("user"),
|
||||
data: JSON.stringify({"extra": {"name":name, "img":img}}),
|
||||
contentType: "application/json",
|
||||
processData: false
|
||||
processData: false,
|
||||
success: function() {
|
||||
callback(false);
|
||||
},
|
||||
error: function() {
|
||||
callback(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -339,49 +339,54 @@
|
|||
$('#newCurrentPassword').closest("th").css("backgroundColor", "white");
|
||||
$('#confirmCurrentPassword').closest("th").css("backgroundColor", "white");
|
||||
|
||||
|
||||
//check
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
this.currentUser.setPassword(newPasswd);
|
||||
window.modalView.hide();
|
||||
var callback = function(error, data) {
|
||||
if (error) {
|
||||
arangoHelper.arangoError("User", "Could not verify old password");
|
||||
}
|
||||
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() {
|
||||
var name = $('#editCurrentName').val();
|
||||
var img = $('#editCurrentUserProfileImg').val();
|
||||
img = this.parseImgString(img);
|
||||
|
||||
/* if (!this.validateName(name)) {
|
||||
$('#editName').closest("th").css("backgroundColor", "red");
|
||||
return;
|
||||
}*/
|
||||
|
||||
this.currentUser.setExtras(name, img);
|
||||
this.updateUserProfile();
|
||||
var callback = function(error) {
|
||||
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();
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue