parking-html/Parking_spaces/Views/Home/Login.cshtml
2024-10-01 02:34:26 +08:00

163 lines
5.5 KiB
Plaintext

@{
ViewData["Title"] = "Login";
Layout = null;
}
<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>雲科校園停車場登錄</title>
<!-- Custom fonts for this template-->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
<!-- Custom styles for this template-->
<link href="~/bootstrap_1/css/sb-admin-2.min.css" rel="stylesheet">
<style>
body.bg-gradient-primary {
background: url('/bootstrap_1/img/1.jpg') no-repeat center center fixed;
background-size: cover;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-container {
background-color: transparent;
border-radius: 5px;
padding: 80px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
align-items: center;
width: 90%; /* 設置 container 的寬度為 90% */
max-width: 600px; /* 設置 container 的最大寬度為 600px */
}
.login-header {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.login-header img {
height: 100px;
margin-right: 15px;
}
.login-header h1 {
margin: 0;
font-size: 100px;
}
.login-content {
max-width: 500px;
width: 100%;
}
.login-content .form-group {
margin-bottom: 20px;
}
.login-content input[type="text"],
.login-content input[type="password"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
.login-content button {
display: block;
width: 100%;
padding: 10px 0;
background-color: #4caf50;
color: #ffffff;
border: none;
border-radius: 5px;
cursor: pointer;
margin-top: 10px;
}
.login-content button:hover {
background-color: #45a049;
}
</style>
</head>
<body class="bg-gradient-primary">
<div class="login-container">
<form id="login-form" onsubmit="handleFormSubmit(event)">
<div class="login-header">
<img src="~/bootstrap_1/img/Yuntech.png" alt="Yuntech">
<h1>Login</h1>
</div>
<div class="login-content">
<div class="form-group">
<input type="text" class="form-control form-control-user" id="username_id" aria-describedby="emailHelp" placeholder="輸入帳號...">
</div>
<div class="form-group">
<input type="password" class="form-control form-control-user" id="password_id" placeholder="密碼">
</div>
<button type="submit" class="btn btn-success btn-user btn-block">Login</button>
<a onclick="passerby_clicked()" class="btn btn-primary btn-user btn-block">路人登入</a>
<hr>
</div>
</form>
</div>
<script src="/bootstrap_1/vendor/jquery/jquery.min.js"></script>
<script>
function handleFormSubmit(event) {
event.preventDefault(); // 防止表單的默認提交
login_clicked(); // 手動調用登陸函數
}
function login_clicked() {
var username = document.getElementById("username_id").value;
var password = document.getElementById("password_id").value;
console.log(username, password);
var obj = { Username: username, Password: password };
var stringify_obj = JSON.stringify(obj);
$.ajax({
type: "POST",
url: "http://localhost:7700/Users/authenticate",
data: stringify_obj,
contentType: "application/json",
success: function (msg) {
console.log(msg);
var token = msg.token;
go_to_next_view(token);
},
error: function (xhr, status, error) {
window.alert("請輸入正確帳號密碼");
document.getElementById("username_id").value = "";
document.getElementById("password_id").value = "";
console.log("error");
}
});
}
function go_to_next_view(token_str) {
localStorage.setItem('token_park_space', token_str);
window.location = '/Park_spaces/Parking_spaces_total_table';
}
function passerby_clicked() {
localStorage.removeItem('token_park_space');
window.location.href = '/Park_spaces/Parking_spaces_total_table';
}
</script>
</body>
</html>