This commit is contained in:
admin
2026-05-22 23:05:25 +09:00
parent cea3016fbe
commit e8690d130b
23 changed files with 581 additions and 187 deletions

View File

@@ -4,6 +4,7 @@
<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;
@@ -108,16 +109,6 @@
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;
@@ -138,32 +129,6 @@
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;
@@ -181,7 +146,7 @@
</div>
<!-- ログインフォーム -->
<div id="loginForm" class="form active">
<div id="loginForm">
<div id="messageLogin" class="message"></div>
<div class="form-group">
@@ -208,47 +173,8 @@
<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>
@@ -330,82 +256,19 @@
}
}
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キーでログイン/登録
// EnterキーでログインできるようにEnterキーをバインド
document.addEventListener("keypress", (e) => {
if (e.key === "Enter") {
const loginForm = document.getElementById("loginForm");
if (loginForm.classList.contains("active")) {
handleLogin();
} else {
handleRegister();
}
handleLogin();
}
});
// ログインページから後退ボタンで離脱できないようにする
// (ログアウト後に戻るボタンでメニューが見えてしまう問題の対策)
history.pushState(null, "", window.location.href);
window.addEventListener("popstate", function () {
history.pushState(null, "", window.location.href);
});
</script>
</body>
</html>