FIC_Solar/SolarPower/wwwroot/js/site.js
Kai c6a9d9653b 1. 密碼 bug fix
2. 固定地圖總覽
2021-08-19 12:07:57 +08:00

156 lines
4.3 KiB
JavaScript

//#region 個人資訊表單驗證
$(function () {
$.ajaxSetup({
//完成请求后触发。即在success或error触发后触发
complete: function (XMLHttpRequest, status) {
if ('499' == XMLHttpRequest.status) {
window.location.href = "/Login/Index";
}
},
})
$("#personal-info-form").validate({
rules: {
name_modal: {
required: true,
maxlength: 50
},
email_modal: {
email: true,
},
},
});
$("#btn-personal-info").click(function (e) {
var url = "/User/GetPersonalInfo"
$.post(url, null, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
}
$("#name_modal").val(rel.data.name);
$("#account_modal").val(rel.data.account);
$("#email_modal").val(rel.data.email);
$("#phone_modal").val(rel.data.phone);
$('#personal-info-modal').modal();
}, 'json');
});
})
//#endregion
//#region 修改個人資料
function SavePersonalInfo() {
if ($("#personal-info-form").valid()) {
var url = "/User/SavePersonalInfo";
var send_data = {
Name: $("#name_modal").val(),
Account: $("#account_modal").val(),
Email: $("#email_modal").val(),
Phone: $("#phone_modal").val()
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
return;
}
else if (rel.code == "9998") {
toast_error(rel.msg);
setTimeout(function () {
location.href = "/Login/Logout";
}, 5000)
}
toast_ok(rel.msg);
$('#personal-info-modal').modal('hide');
}, 'json');
}
}
//#endregion
//#region 變更密碼表單驗證
$(function () {
jQuery.validator.addMethod("pwcheck", function (value, element) {
var xxx = /^[A-Za-z0-9\d=!@#$%^&+=]*$/.test(value);
return xxx;// consists of only these
//&& /[a-z]/.test(value) // has a lowercase letter
//&& /\d/.test(value) // has a digit
});
$("#change-password-form").validate({
rules: {
old_password_modal: {
required: true,
//rangelength: [6, 12]
},
new_password_modal: {
required: true,
rangelength: [6, 12],
pwcheck: true
},
again_password_modal: {
required: true,
rangelength: [6, 12],
pwcheck: true,
equalTo: "#new_password_id_modal",
}
},
messages: {
new_password_modal: {
pwcheck: "密碼格式錯誤,格式需為大小寫英文或數字或特殊符號【!@#$%^&+=】"
},
again_password_modal: {
pwcheck: "密碼格式錯誤,格式需為大小寫英文或數字或特殊符號【!@#$%^&+=】",
equalTo: "兩次密碼輸入不同"
}
}
});
$("#btn-change-password").click(function (e) {
$("#change-password-form").trigger("reset");
$('#change-password-modal').modal();
});
})
//#endregion
//#region 變更密碼
function ChangePassword() {
if ($("#change-password-form").valid()) {
var url = "/User/ChangePassword";
var send_data = {
OldPassword: $("#old_password_id_modal").val(),
NewPassword: $("#new_password_id_modal").val(),
AgainPassword: $("#again_password_id_modal").val()
}
$.post(url, send_data, function (rel) {
if (rel.code == "9999") {
toast_error(rel.msg);
return;
}
else if (rel.code == "9998") {
toast_error(rel.msg);
setTimeout(function () {
location.href = "/Login/Logout";
}, 5000)
return;
} else if (rel.code == "0001") {
toast_error(rel.msg);
return;
}
toast_ok(rel.msg);
$('#change-password-modal').modal('hide');
}, 'json');
}
}
//#endregion