275 lines
7.0 KiB
HTML
275 lines
7.0 KiB
HTML
<!doctype html>
|
|
<html lang="ja">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>NJTS 会計システム - ログイン</title>
|
|
<link rel="stylesheet" href="/css/mobile.css" />
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family:
|
|
system-ui,
|
|
-apple-system,
|
|
"Yu Gothic UI",
|
|
"Hiragino Kaku Gothic ProN",
|
|
"メイリオ",
|
|
sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
padding: 20px;
|
|
}
|
|
|
|
.login-container {
|
|
background: white;
|
|
border-radius: 10px;
|
|
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
|
|
width: 100%;
|
|
max-width: 400px;
|
|
padding: 40px;
|
|
}
|
|
|
|
.logo {
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.logo h1 {
|
|
font-size: 28px;
|
|
color: #333;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.logo p {
|
|
font-size: 14px;
|
|
color: #666;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
color: #333;
|
|
}
|
|
|
|
input[type="text"],
|
|
input[type="password"] {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 5px;
|
|
font-size: 14px;
|
|
transition: border-color 0.3s;
|
|
}
|
|
|
|
input[type="text"]:focus,
|
|
input[type="password"]:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
}
|
|
|
|
.button-group {
|
|
display: flex;
|
|
gap: 10px;
|
|
margin-top: 30px;
|
|
}
|
|
|
|
button {
|
|
flex: 1;
|
|
padding: 12px;
|
|
border: none;
|
|
border-radius: 5px;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.btn-login {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
}
|
|
|
|
.btn-login:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
|
|
}
|
|
|
|
.message {
|
|
padding: 12px;
|
|
border-radius: 5px;
|
|
margin-bottom: 20px;
|
|
display: none;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.message.error {
|
|
background: #fee;
|
|
color: #c33;
|
|
border: 1px solid #fcc;
|
|
}
|
|
|
|
.message.success {
|
|
background: #efe;
|
|
color: #3c3;
|
|
border: 1px solid #cfc;
|
|
}
|
|
|
|
.loading {
|
|
display: none;
|
|
text-align: center;
|
|
color: #667eea;
|
|
margin-top: 10px;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<div class="login-container">
|
|
<div class="logo">
|
|
<h1>NJTS</h1>
|
|
<p>会計システム</p>
|
|
</div>
|
|
|
|
<!-- ログインフォーム -->
|
|
<div id="loginForm">
|
|
<div id="messageLogin" class="message"></div>
|
|
|
|
<div class="form-group">
|
|
<label for="loginUsername">ユーザー名</label>
|
|
<input
|
|
type="text"
|
|
id="loginUsername"
|
|
placeholder="ユーザー名を入力"
|
|
required
|
|
/>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="loginPassword">パスワード</label>
|
|
<input
|
|
type="password"
|
|
id="loginPassword"
|
|
placeholder="パスワードを入力"
|
|
required
|
|
/>
|
|
</div>
|
|
|
|
<div class="button-group">
|
|
<button class="btn-login" onclick="handleLogin()">ログイン</button>
|
|
</div>
|
|
|
|
<div class="loading" id="loginLoading">処理中...</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function toggleForm() {
|
|
const loginForm = document.getElementById("loginForm");
|
|
const registerForm = document.getElementById("registerForm");
|
|
|
|
loginForm.classList.toggle("active");
|
|
registerForm.classList.toggle("active");
|
|
|
|
// メッセージをリセット
|
|
clearMessage("messageLogin");
|
|
clearMessage("messageRegister");
|
|
}
|
|
|
|
function showMessage(elementId, message, isError = false) {
|
|
const messageEl = document.getElementById(elementId);
|
|
messageEl.textContent = message;
|
|
messageEl.className = `message ${isError ? "error" : "success"}`;
|
|
messageEl.style.display = "block";
|
|
}
|
|
|
|
function clearMessage(elementId) {
|
|
const messageEl = document.getElementById(elementId);
|
|
messageEl.style.display = "none";
|
|
messageEl.textContent = "";
|
|
}
|
|
|
|
async function handleLogin() {
|
|
const username = document.getElementById("loginUsername").value;
|
|
const password = document.getElementById("loginPassword").value;
|
|
|
|
if (!username || !password) {
|
|
showMessage(
|
|
"messageLogin",
|
|
"ユーザー名とパスワードを入力してください",
|
|
true,
|
|
);
|
|
return;
|
|
}
|
|
|
|
const loadingEl = document.getElementById("loginLoading");
|
|
loadingEl.style.display = "block";
|
|
|
|
try {
|
|
const response = await fetch("/api/users/login", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ username, password }),
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
// ユーザー情報をlocalStorageに保存
|
|
localStorage.setItem("currentUser", JSON.stringify(data));
|
|
showMessage("messageLogin", "ログインに成功しました!", false);
|
|
// 2秒後にメインページにリダイレクト
|
|
setTimeout(() => {
|
|
window.location.href = "/index.html";
|
|
}, 2000);
|
|
} else {
|
|
showMessage(
|
|
"messageLogin",
|
|
data.detail || "ログインに失敗しました",
|
|
true,
|
|
);
|
|
}
|
|
} catch (error) {
|
|
showMessage(
|
|
"messageLogin",
|
|
"エラーが発生しました: " + error.message,
|
|
true,
|
|
);
|
|
} finally {
|
|
loadingEl.style.display = "none";
|
|
}
|
|
}
|
|
|
|
// EnterキーでログインできるようにEnterキーをバインド
|
|
document.addEventListener("keypress", (e) => {
|
|
if (e.key === "Enter") {
|
|
handleLogin();
|
|
}
|
|
});
|
|
|
|
// ログインページから後退ボタンで離脱できないようにする
|
|
// (ログアウト後に戻るボタンでメニューが見えてしまう問題の対策)
|
|
history.pushState(null, "", window.location.href);
|
|
window.addEventListener("popstate", function () {
|
|
history.pushState(null, "", window.location.href);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|