Fix redirect after updating profile

This commit is contained in:
gplane 2017-04-27 16:38:40 +08:00
parent d9552e268c
commit 2ca383628e
2 changed files with 55 additions and 70 deletions

View File

@ -2,7 +2,7 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-09-15 10:39:41 * @Date: 2016-09-15 10:39:41
* @Last Modified by: g-plane * @Last Modified by: g-plane
* @Last Modified time: 2017-04-26 23:58:06 * @Last Modified time: 2017-04-27 15:33:24
*/ */
'use strict'; 'use strict';
@ -222,18 +222,11 @@ function confirmLogout() {
} }
function logout() { function logout() {
return new Promise((resolve, reject) => { return Promise.resolve($.ajax({
$.ajax({ type: "POST",
type: "POST", url: url('auth/logout'),
url: url('auth/logout'), dataType: "json"
dataType: "json", }));
success: (json) => resolve(json),
error: (json) => {
showAjaxError(json);
reject(json);
}
});
});
} }
$('#logout-button').click(() => confirmLogout()); $('#logout-button').click(() => confirmLogout());

View File

@ -2,7 +2,7 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-07-16 10:02:24 * @Date: 2016-07-16 10:02:24
* @Last Modified by: g-plane * @Last Modified by: g-plane
* @Last Modified time: 2017-04-27 00:01:38 * @Last Modified time: 2017-04-27 16:37:05
*/ */
'use strict'; 'use strict';
@ -538,49 +538,46 @@ function changeNickName() {
} }
function changePassword() { function changePassword() {
let domOldPwd = $('#password');
let domNewPwd = $('#new-passwd');
let domConfirmPwd = $('#confirm-pwd');
var password = $('#password').val(); let password = domOldPwd.val();
var new_passwd = $('#new-passwd').val(); let new_passwd = domNewPwd.val();
if (password == "") { if (password == "") {
toastr.info(trans('user.emptyPassword')); toastr.info(trans('user.emptyPassword'));
$('#passwd').focus(); domOldPwd.focus();
} else if (new_passwd == "") { } else if (new_passwd == "") {
toastr.info(trans('user.emptyNewPassword')); toastr.info(trans('user.emptyNewPassword'));
$('#new-passwd').focus(); domNewPwd.focus();
} else if ($('#confirm-pwd').val() == "") { } else if (domConfirmPwd.val() == "") {
toastr.info(trans('auth.emptyConfirmPwd')); toastr.info(trans('auth.emptyConfirmPwd'));
$('#confirm-pwd').focus(); domConfirmPwd.focus();
} else if (new_passwd != $('#confirm-pwd').val()) { } else if (new_passwd != domConfirmPwd.val()) {
toastr.warning(trans('auth.invalidConfirmPwd')); toastr.warning(trans('auth.invalidConfirmPwd'));
$('#confirm-pwd').focus(); domConfirmPwd.focus();
} else { } else {
$.ajax({ Promise.resolve($.ajax({
type: "POST", type: "POST",
url: "./profile?action=password", url: "./profile?action=password",
dataType: "json", dataType: "json",
data: { 'current_password': password, 'new_password': new_passwd}, data: { 'current_password': password, 'new_password': new_passwd }
success: function(json) { })).then(result => {
if (json.errno == 0) { if (result.errno == 0) {
swal({ return swal({ type: 'success', text: result.msg })
type: 'success', .then(() => {
html: json.msg return logout();
}).then(function() { }).then(result => {
logout(true, function() { if (result.errno == 0) {
window.location = "../auth/login"; window.location = url('auth/login');
}); }
}); }).catch(error => showAjaxError);
} else { } else {
swal({ return swal({ type: 'warning', text: result.msg });
type: 'warning', }
html: json.msg }).catch(error => showAjaxError);
});
}
},
error: showAjaxError
});
} }
return false;
} }
$('#new-email').focusin(function() { $('#new-email').focusin(function() {
@ -614,32 +611,27 @@ function changeEmail() {
text: trans('user.changeEmail', { new_email: new_email }), text: trans('user.changeEmail', { new_email: new_email }),
type: 'question', type: 'question',
showCancelButton: true showCancelButton: true
}).then(function() { }).then(() => {
$.ajax({ return Promise.resolve($.ajax({
type: "POST", type: 'POST',
url: "./profile?action=email", url: './profile?action=email',
dataType: "json", dataType: 'json',
data: { 'new_email' : new_email, 'password' : $('#current-password').val() }, data: { 'new_email': new_email, 'password': $('#current-password').val() }
success: function(json) { }));
if (json.errno == 0) { }).then(result => {
swal({ if (result.errno == 0) {
type: 'success', return swal({ type: 'success', text: result.msg })
html: json.msg .then(() => {
}).then(function() { return logout();
logout(true, function() { }).then(result => {
window.location = "../auth/login"; if (result.errno == 0) {
}); window.location = url('auth/login');
}); }
} else { }).catch(error => showAjaxError);
swal({ } else {
type: 'warning', return swal({ type: 'warning', text: result.msg });
html: json.msg }
}); }).catch(error => showAjaxError);
}
},
error: showAjaxError
});
});
} }
function deleteAccount() { function deleteAccount() {