forked from rachanon/stdbWeb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
3.7 KiB
128 lines
3.7 KiB
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="utf-8"> |
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
|
<title>Login</title> |
|
<link rel="stylesheet" href="css/style.css"> |
|
<link rel="shortcut icon" type="image/png" href="https://avatars1.githubusercontent.com/u/17867603?v=3&s=200"/> |
|
<script src="js/jquery-3.0.0.min.js"></script> |
|
<!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]--> |
|
<style> |
|
.flexCenter { |
|
display:flex; |
|
height: 550px; |
|
justify-content: center; |
|
align-items:center; |
|
} |
|
</style> |
|
</head> |
|
|
|
|
|
<body> |
|
<section id="boxlogin" class="container"> |
|
|
|
</section> |
|
</body> |
|
<script language="javascript"> |
|
|
|
var token = '' |
|
|
|
function pasuser(form) { |
|
var data = {"username": form.login.value, "password": form.password.value} |
|
// console.log(form.login.value) |
|
// console.log(form.password.value) |
|
// console.log(data) |
|
$.ajax({ |
|
type: "POST", |
|
url: 'http://www.serv.stdb.most.go.th/api-token-auth/', |
|
data: data, |
|
success: success, |
|
dataType: 'json' |
|
}); |
|
} |
|
|
|
function success(respone) { |
|
// console.log(respone) |
|
// console.log(respone.token) |
|
localStorage.setItem("token", respone.token); |
|
getToken(); |
|
} |
|
|
|
function getToken(){ |
|
sesToken = sessionStorage.getItem('token'); |
|
if( sesToken === null){ |
|
token = localStorage.getItem("token") |
|
// console.log(token) |
|
// console.log('==================') |
|
if( token != null ){ |
|
$.ajax({ |
|
type: "POST", |
|
url: 'http://www.serv.stdb.most.go.th/api-token-verify/', |
|
data: { "token" : token }, |
|
header: { |
|
Authorization: 'Bearer '+ token, |
|
}, |
|
success: checkToken, |
|
error: tokenError, |
|
dataType: 'json' |
|
}); |
|
} |
|
else{ |
|
loginPage(); |
|
} |
|
} |
|
else{ |
|
window.location.href = 'instrument.html'; |
|
} |
|
} |
|
|
|
function checkToken(tokenrespone) { |
|
sessionStorage.getItem('token',tokenrespone.token); |
|
try { |
|
if( tokenrespone.token === token ){ |
|
window.location.href = 'instrument.html'; |
|
// console.log('go to page'); |
|
// console.log(tokenrespone.token); |
|
} |
|
} |
|
catch(err) { |
|
// console.log(err.message); |
|
loginPage(); |
|
} |
|
|
|
} |
|
function tokenError(){ |
|
loginPage(); |
|
} |
|
function loginPage(){ |
|
localStorage.removeItem('token'); |
|
var loginTag = '<div class="login">' |
|
+'<h1>Login to STDB</h1>' |
|
+'<form method="post" >' |
|
+'<p><input type="text" name="login" value="" placeholder="Username or Email"></p>' |
|
+'<p><input type="password" name="password" value="" placeholder="Password"></p>' |
|
+'<p class="remember_me">' |
|
+'<label>' |
|
+'<input type="checkbox" name="remember_me" id="remember_me">' |
|
+'Remember me on this computer' |
|
+'</label>' |
|
+'</p>' |
|
+' <p class="submit"><input type="button" value="Login" onClick="pasuser(this.form)"></p>' |
|
+'</form>' |
|
+'</div>' |
|
document.getElementById("boxlogin").innerHTML = loginTag |
|
} |
|
getToken() |
|
</script> |
|
<script> |
|
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ |
|
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), |
|
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) |
|
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); |
|
|
|
ga('create', 'UA-72505920-2', 'auto'); |
|
ga('send', 'pageview'); |
|
|
|
</script> |
|
</html>
|
|
|