01.
if
(
false
){
02.
var
company_list =
''
;
03.
}
04.
var
ExCeption=(jqXHR, exception)=>{
05.
var
msg =
''
;
06.
if
(jqXHR.status === 0) { msg =
'Not connect.\n Verify Network.'
;
07.
}
else
if
(jqXHR.status === 404) { msg =
'Requested page not found. [404]'
;
08.
}
else
if
(jqXHR.status === 500) { msg =
'Internal Server Error [500].'
;
09.
}
else
if
(exception ===
'parsererror'
) { msg =
'Requested JSON parse failed.'
;
10.
}
else
if
(exception ===
'timeout'
) { msg =
'Time out error.'
;
11.
}
else
if
(exception ===
'abort'
) { msg =
'Ajax request aborted.'
;
12.
}
else
{ msg =
'Uncaught Error.\n'
+ jqXHR.responseText; }
13.
swal.showValidationError(msg+
'<br>กรุณาทดลองใหม่'
);
14.
};
15.
var
ar={ Login:
''
, Password:
''
};
16.
$(document).ready(()=>{ Login(); });
17.
function
Login(){
18.
var
html=`<table style=
"font-size: 10pt; width: 100%"
>
19.
<tr><td align=right width=
"30%"
>Company</td>
20.
<td><select id=
"company"
class=
"hk_input"
>`+company_list+`</select></td></tr>
21.
<tr><td align=right >User Name</td>
22.
<td><input type=
"text"
id=
"user"
class=
"hk_input"
placeholder=
"Username [4-10]"
value=
"`+ar.Login+`"
></td></tr>
23.
<tr><td align=right >Password</td>
24.
<td><input type=
"password"
class=
"hk_input"
id=
"pass"
placeholder=
"Password [4-10]"
value=
"`+ar.Password+`"
></td></tr>
25.
</table>
26.
<b class=
"btn btn-info"
id=
"login"
>Login</b><br><br>
27.
<a href=
"#"
id=
"forgot"
>Forgot Password</a>`;
28.
swal({
29.
title:
'Login to Your Account'
, html: html, showCancelButton:
false
, showConfirmButton:
false
, backdrop:
false
,
30.
onOpen: ()=>{
31.
$(
'.swal2-input'
).focusin(()=>{swal.resetValidationError();});
32.
$(
'#user'
).keyup(e=>{
if
(e.keyCode===13){$(
'#pass'
).focus();}});
33.
$(
'#pass'
).keyup(e=>{
if
(e.keyCode===13 || e.keyCode === 9){ $(
'#login'
).click();}});
34.
$(
'#forgot'
).click(()=>{
35.
ar.Login=$(
'#user'
).val();
36.
if
(ar.Login.length<1){
37.
swal(
'Lost Password Error'
,
'Please fill in Usename'
,
'error'
).then(()=>{ setTimeout( ()=>{ Login();}, 100);});
38.
return
;
39.
}
40.
$.ajax({url:
'/Home/Lospw'
, type:
'POST'
, dataType:
'json'
, data: ar, error: ExCeption, success: rs=>{
41.
if
( rs.msg===
'complete'
){
42.
swal(
'Your are request Password'
,
'I send your password to your Email.<br>Please open your Email'
,
'success'
).then(()=>{setTimeout(()=>{ Login();}, 100);});
43.
}
else
if
(rs.msg===
'error'
){ swal(
'Request Password Error'
,rs.error,
'error'
).then(()=>{setTimeout(()=>{ Login();}, 100);});}
44.
}});
45.
});
46.
$(
'#login'
).click( ()=>{
47.
ar={ UserID: $(
'#user'
).val().toUpperCase(), Password:$(
'#pass'
).val() };
48.
if
( !(/[A-Z0-9\-_]{2,10}/).test(ar.UserID)){
49.
swal.showValidationError(
'Wrong Name.<br>And must be only in English and numbers.<br>2-10 Digits'
);
50.
}
else
if
( !(/[a-zA-Z0-9\-_]{2,10}/).test(ar.Password)){
51.
swal.showValidationError(
'Wrong Password<br>And must be only in English and numbers.<br>2-10 Digits'
);
52.
}
else
{
53.
$.ajax({ url:
'/Home/Login/'
+$(
'#company'
).val(), type:
'POST'
, dataType:
'json'
, data: ar, error: ExCeption, success: rs=>{
54.
if
( rs.msg===
'complete'
){ location.href=
"/Home"
;}
55.
else
{ swal(
'Request Password Error'
,rs.error,
'error'
).then(()=>{setTimeout(()=>{ Login();}, 100);});}
56.
}});
57.
}
58.
});
59.
},
60.
preConfirm: ()=>{
61.
return
false
;
62.
}
63.
}).then(()=>{ Login();});
64.
}