Parking_space_ASPNET/Parking_spaces/Views/Home/Login.cshtml

266 lines
8.7 KiB
Plaintext
Raw Normal View History

2024-02-01 11:37:15 +08:00
@{
ViewData["Title"] = "Login";
Layout = null;
}
<!--
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: #ffffff;
border-radius: 5px;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.container h1 {
text-align: center;
margin-bottom: 20px;
}
.container label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
.container input[type="text"],
.container input[type="password"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 20px;
}
.container button {
display: block;
width: 100%;
padding: 10px;
background-color: #4caf50;
color: #ffffff;
border: none;
border-radius: 5px;
cursor: pointer;
}
.container button:hover {
background-color: #45a049;
}
</style>
-->
<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>Login</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">
</head>
<body class="bg-gradient-primary">
<div class="container">
<!-- Outer Row -->
<div class="row justify-content-center">
<div class="col-xl-10 col-lg-12 col-md-9">
<div class="card o-hidden border-0 shadow-lg my-5">
<div class="card-body p-0">
<!-- Nested Row within Card Body -->
<div class="row">
<div class="col-lg-6 ">
<img style="width:100%" src="~/bootstrap_1/img/Yuntech.png">
</div>
<div class="col-lg-6">
<div class="p-5">
<div class="text-center">
<h1>Login</h1>
</div>
<div class="user">
<div class="form-group">
<input type="email" 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>
<a onclick="login_clicked()" class="btn btn-success btn-user btn-block">
Login
</a>
<a onclick="passerby_clicked()" class="btn btn-primary btn-user btn-block">
路人登入
</a>
<hr>
</div>
<hr>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<!--
<div class="container">
<h1>Login</h1>
<div >
<label for="username">Username:</label>
<input type="text" id="username_id" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password_id" name="password" required>
<button onclick="login_clicked()">登入</button>
<button style="background-color: #0066FF;background-color: #5599FF;" onclick="passerby_clicked()">路人登入</button>
</div>
2024-02-14 22:14:34 +08:00
</div>-->
<script src="/bootstrap_1/vendor/jquery/jquery.min.js"></script>
2024-02-01 11:37:15 +08:00
<!--登入頁面-->
<script>
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);
/* 0521
$.ajax({
type: "POST",
url: "Users/authenticate",
data: stringify_obj,
contentType: "application/json",
success: function (msg) {
console.log(msg)
var token = msg.token; // 替换为您的JWT令牌
var redirectUrl = "/Park_spaces/Parking_spaces_total_table"; // 替换为您的目标URL
// 构建带有JWT令牌的完整URL
var urlWithToken = redirectUrl + "?token=" + token;
if(msg!=null){
window.location = urlWithToken;
}
//window.location = "/Park_spaces/Parking_spaces_total_table";
}
});
*/
/*0522
$.ajax({
type: "POST",
url: "Users/authenticate",
data: stringify_obj,
contentType: "application/json",
success: function (msg) {
console.log(msg)
var token = msg.token; // 替换为您的JWT令牌
// 将令牌存储在本地存储中
localStorage.setItem('token_park_space', token);
// 跳转到目标页面
window.location.href = '/Park_spaces/Parking_spaces_total_table';
},
error: function (xhr, status, error) {
// 处理错误
window.alert("請輸入正確帳號密碼");
document.getElementById("username_id").value = ""
document.getElementById("password_id").value = ""
console.log("error")
}
});*/
/*0523*/
$.ajax({
type: "POST",
2024-02-14 22:02:50 +08:00
url: "http://140.125.20.183:7700/Users/authenticate",
2024-02-01 11:37:15 +08:00
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';
/*
// 获取 JWT 令牌
var token = token_str;
$.ajax({
type: "GET",
url: 'Park_spaces/Parking_spaces_total_table',
//url: 'http://140.125.20.183:5173/Users/token',
2024-02-01 11:37:15 +08:00
headers: {
'Authorization': token
},
success: function (response) {
// window.location.href = '/test/' + response;
window.location = '/Park_spaces/test/' + response;
//console.log(response)
},
error: function (xhr) {
// 处理错误响应,例如跳转到未授权页面
window.location.href = 'https://example.com/unauthorized_page';
}
});*/
}
</script>
<!--路人登入-->
<script>
function passerby_clicked() {
localStorage.removeItem('token_park_space');
window.location.href = '/Park_spaces/Parking_spaces_total_table';
}
</script>