ad_login/wwwroot/assets/javascript/custom/reset.js

92 lines
3.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

(function ($, document) {
(function ($) {
$.UrlParam = function (name) {
//宣告正規表達式
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
/*
* window.location.search 獲取URL ?之後的參數(包含問號)
* substr(1) 獲取第一個字以後的字串(就是去除掉?號)
* match(reg) 用正規表達式檢查是否符合要查詢的參數
*/
var r = window.location.search.substr(1).match(reg);
//如果取出的參數存在則取出參數的值否則回穿null
if (r != null) return unescape(r[2]); return null;
}
})(jQuery);
})(jQuery, document);
$(document).ready(function () {
$('#token').val($.UrlParam("token"));
$('#resetBtn').on('click', function () {
var new_pwd = $('#inputNewPassword').val();
var chk_pwd = $('#inputChkPassword').val();
var token = $('#token').val();
if (token === null || token === "") {
alert("無效的密碼重設驗證,請重新申請!");
return;
}
if (pwdStrengthChecke(new_pwd, 6, 2) === false) {
alert("新密碼強度不足請至少包含英文小寫、英文大寫、阿拉伯數字、特殊符號四項中的2項且長度至少為6個字元!");
return;
}
if (new_pwd != chk_pwd) {
alert("新密碼與新密碼再確認不一致!");
return;
}
if (!confirm('請注意Windows的密碼與公槽密碼是連動的更改後登入Windows與登入公槽的密碼會跟著一起改!')) {
return;
}
var formData = {
new_password: new_pwd,
token: token
}
$.ajax({
url: "/adApi/resetPassword",
type: "POST",
data: formData,
success: function (data, textStatus, jqXHR) {
if (data.ret === "yes") {
alert("密碼重設成功請使用新密碼登入PC與公槽!");
$('#inputNewPassword').val('');
$('#inputChkPassword').val('');
} else {
if (data.err_code == "1005") {
alert('無效的密碼重設驗證,請重新申請!');
return;
}
alert(data.message);
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('網路或伺服器發生錯誤,請稍後重試!');
}
});
});
});
function pwdStrengthChecke(str, length, strength) {
if (!str || str.length < length) {
return false
}
let n = 0
const regex = [
/[a-z]/,
/[A-Z]/,
/[0-9]/,
/[`~!@#$%^&*()_+=,<>\-\[\]\{\}\:;\.'"\/\\?\|]/
]
for (const r of regex) {
if (str.match(r)) {
n++
}
}
return n >= strength
}