login画面追加
This commit is contained in:
411
frontend/login.html
Normal file
411
frontend/login.html
Normal file
@@ -0,0 +1,411 @@
|
||||
<!doctype html>
|
||||
<html lang="ja">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>NJTS 会計システム - ログイン</title>
|
||||
<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);
|
||||
}
|
||||
|
||||
.btn-register {
|
||||
background: transparent;
|
||||
color: #667eea;
|
||||
border: 2px solid #667eea;
|
||||
}
|
||||
|
||||
.btn-register:hover {
|
||||
background: #f0f0ff;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.toggle-form {
|
||||
text-align: center;
|
||||
margin-top: 20px;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.toggle-form a {
|
||||
color: #667eea;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.toggle-form a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.form {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.form.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.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" class="form active">
|
||||
<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="toggle-form">
|
||||
新規登録?
|
||||
<a onclick="toggleForm()">アカウント作成</a>
|
||||
</div>
|
||||
|
||||
<div class="loading" id="loginLoading">処理中...</div>
|
||||
</div>
|
||||
|
||||
<!-- 登録フォーム -->
|
||||
<div id="registerForm" class="form">
|
||||
<div id="messageRegister" class="message"></div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="regUsername">ユーザー名</label>
|
||||
<input
|
||||
type="text"
|
||||
id="regUsername"
|
||||
placeholder="ユーザー名を入力"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="regPassword">パスワード</label>
|
||||
<input
|
||||
type="password"
|
||||
id="regPassword"
|
||||
placeholder="6文字以上で設定"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="button-group">
|
||||
<button class="btn-login" onclick="handleRegister()">登録</button>
|
||||
<button class="btn-register" onclick="toggleForm()">
|
||||
キャンセル
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="loading" id="registerLoading">処理中...</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";
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRegister() {
|
||||
const username = document.getElementById("regUsername").value;
|
||||
const password = document.getElementById("regPassword").value;
|
||||
|
||||
if (!username || !password) {
|
||||
showMessage(
|
||||
"messageRegister",
|
||||
"ユーザー名とパスワードを入力してください",
|
||||
true,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.length < 6) {
|
||||
showMessage(
|
||||
"messageRegister",
|
||||
"パスワードは6文字以上である必要があります",
|
||||
true,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const loadingEl = document.getElementById("registerLoading");
|
||||
loadingEl.style.display = "block";
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/users/register", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ username, password }),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok) {
|
||||
showMessage(
|
||||
"messageRegister",
|
||||
"登録が完了しました。ログインしてください",
|
||||
false,
|
||||
);
|
||||
setTimeout(() => {
|
||||
toggleForm();
|
||||
document.getElementById("loginUsername").value = username;
|
||||
document.getElementById("loginPassword").value = "";
|
||||
}, 2000);
|
||||
} else {
|
||||
showMessage(
|
||||
"messageRegister",
|
||||
data.detail || "登録に失敗しました",
|
||||
true,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
showMessage(
|
||||
"messageRegister",
|
||||
"エラーが発生しました: " + error.message,
|
||||
true,
|
||||
);
|
||||
} finally {
|
||||
loadingEl.style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
// Enterキーでログイン/登録
|
||||
document.addEventListener("keypress", (e) => {
|
||||
if (e.key === "Enter") {
|
||||
const loginForm = document.getElementById("loginForm");
|
||||
if (loginForm.classList.contains("active")) {
|
||||
handleLogin();
|
||||
} else {
|
||||
handleRegister();
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user