This commit is contained in:
2026-10-21 14:28:51 +09:00
10 changed files with 330 additions and 123 deletions

View File

@@ -1,6 +1,6 @@
package com.example.demo.controller;
import java.util.Optional;
import jakarta.servlet.http.HttpServletRequest;
@@ -15,21 +15,21 @@ import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.common.Const;
import com.example.demo.common.LoginUser;
import com.example.demo.service.AuthService;
/** AUTH-01:ログイン/ログアウト(login.html) */
@Controller
public class LoginController {
private final AuthService authService;
public LoginController(AuthService authService) {
this.authService = authService;
}
@GetMapping("/")
public String root() {
return "redirect:/menu";
}
@GetMapping("/login")
public String loginForm(HttpSession session) {
if (session.getAttribute(Const.SESSION_LOGIN_USER) != null) {
@@ -37,14 +37,14 @@ public class LoginController {
}
return "login";
}
@PostMapping("/login")
public String login(@RequestParam(defaultValue = "") String mailAddress,
@RequestParam(defaultValue = "") String password,
HttpServletRequest request, Model model) {
String mail = mailAddress.trim();
model.addAttribute("mailAddress", mail); // 入力値を保持(パスワードは保持しない)
if (mail.isEmpty() || password.isEmpty()) {
model.addAttribute("errorMessage", "メールアドレスとパスワードを入力してください。");
return "login";
@@ -63,11 +63,10 @@ public class LoginController {
request.getSession(true).setAttribute(Const.SESSION_LOGIN_USER, user.get());
return "redirect:/menu";
}
@PostMapping("/logout")
public String logout(HttpSession session) {
session.invalidate();
return "redirect:/login";
}
}
}

View File

@@ -2,7 +2,7 @@ package com.example.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
/** メニュー画面(menu.html)。表示内容は管理者フラグで切り替える。 */
@Controller
public class MenuController {
@@ -10,4 +10,4 @@ public class MenuController {
public String menu() {
return "menu";
}
}
}

View File

@@ -1,33 +1,82 @@
package com.example.demo.form;
/** 社員登録・編集フォーム */
public class EmployeeForm {
private Integer idEmployee;
private String nmEmployee = "";
private String knEmployee = "";
private String mailAddress = "";
private String password = "";
private String flgAdmin = "0";
private String flgRetirement = "0";
private Integer idEmployee;
private String nmEmployee = "";
private String knEmployee = "";
private String mailAddress = "";
private String password = "";
private String flgAdmin = "0";
private String flgRetirement = "0";
public void trim() {
nmEmployee = t(nmEmployee); knEmployee = t(knEmployee); mailAddress = t(mailAddress);
flgAdmin = t(flgAdmin); flgRetirement = t(flgRetirement);
if (password == null) password = "";
}
private static String t(String s) { return s == null ? "" : s.trim(); }
public void trim() {
nmEmployee = t(nmEmployee);
knEmployee = t(knEmployee);
mailAddress = t(mailAddress);
flgAdmin = t(flgAdmin);
flgRetirement = t(flgRetirement);
if (password == null)
password = "";
}
public Integer getIdEmployee() { return idEmployee; }
public void setIdEmployee(Integer v) { this.idEmployee = v; }
public String getNmEmployee() { return nmEmployee; }
public void setNmEmployee(String v) { this.nmEmployee = v; }
public String getKnEmployee() { return knEmployee; }
public void setKnEmployee(String v) { this.knEmployee = v; }
public String getMailAddress() { return mailAddress; }
public void setMailAddress(String v) { this.mailAddress = v; }
public String getPassword() { return password; }
public void setPassword(String v) { this.password = v; }
public String getFlgAdmin() { return flgAdmin; }
public void setFlgAdmin(String v) { this.flgAdmin = v; }
public String getFlgRetirement() { return flgRetirement; }
public void setFlgRetirement(String v) { this.flgRetirement = v; }
private static String t(String s) {
return s == null ? "" : s.trim();
}
public Integer getIdEmployee() {
return idEmployee;
}
public void setIdEmployee(Integer v) {
this.idEmployee = v;
}
public String getNmEmployee() {
return nmEmployee;
}
public void setNmEmployee(String v) {
this.nmEmployee = v;
}
public String getKnEmployee() {
return knEmployee;
}
public void setKnEmployee(String v) {
this.knEmployee = v;
}
public String getMailAddress() {
return mailAddress;
}
public void setMailAddress(String v) {
this.mailAddress = v;
}
public String getPassword() {
return password;
}
public void setPassword(String v) {
this.password = v;
}
public String getFlgAdmin() {
return flgAdmin;
}
public void setFlgAdmin(String v) {
this.flgAdmin = v;
}
public String getFlgRetirement() {
return flgRetirement;
}
public void setFlgRetirement(String v) {
this.flgRetirement = v;
}
}

View File

@@ -10,4 +10,4 @@ spring.jpa.open-in-view=false
spring.jpa.properties.hibernate.jdbc.time_zone=Asia/Tokyo
spring.thymeleaf.cache=false
server.servlet.session.timeout=30m
server.servlet.session.timeout=30m

View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>社員登録完了画面</title>
<link rel="stylesheet" th:href="@{/css/style.css}">
</head>
<body>
<!-- 共通ヘッダー -->
<div th:replace="~{fragments/header :: header}"></div>
<main class="complete-container">
<h2>社員登録完了</h2>
<p th:text="${message != null ? message : '社員登録が完了しました。'}">
社員登録が完了しました。
</p>
<a th:href="@{/menu}">メニューへ戻る</a>
</main>
</body>
</html>

View File

@@ -0,0 +1,79 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>社員登録確認画面</title>
<link rel="stylesheet" th:href="@{/css/style.css}">
</head>
<body>
<!-- 共通ヘッダー -->
<div th:replace="~{fragments/header :: header}"></div>
<main>
<h1>社員登録確認</h1>
<!-- エラーメッセージ -->
<div class="error"
th:if="${errors != null and !errors.isEmpty()}">
<p th:each="error : ${errors}"
th:text="${error}">
</p>
</div>
<div class="card">
<p>以下の内容で登録します。内容を確認してください。</p>
<!-- 登録ボタン -->
<form th:action="@{/admin/employees/new/execute}"
th:object="${form}"
method="post">
<table>
<tr>
<th>社員名</th>
<td th:text="*{nmEmployee}"></td>
</tr>
<tr>
<th>社員名よみ</th>
<td th:text="*{knEmployee}"></td>
</tr>
<tr>
<th>メールアドレス</th>
<td th:text="*{mailAddress}"></td>
</tr>
<tr>
<th>パスワード</th>
<td>********</td>
</tr>
<tr>
<th>権限</th>
<td th:text="*{flgAdmin == '1' ? '管理者' : '一般'}"></td>
</tr>
</table>
<!-- 登録処理に必要な値を引き継ぐ -->
<input type="hidden" th:field="*{nmEmployee}">
<input type="hidden" th:field="*{knEmployee}">
<input type="hidden" th:field="*{mailAddress}">
<input type="hidden" th:field="*{password}">
<input type="hidden" th:field="*{flgAdmin}">
<div class="actions">
<button type="submit" class="btn">
登録
</button>
</div>
</form>
<!-- 入力画面へ戻る -->
<form th:action="@{/admin/employees/new/input}"
th:object="${form}"
method="post">
<input type="hidden" th:field="*{nmEmployee}">
<input type="hidden" th:field="*{knEmployee}">
<input type="hidden" th:field="*{mailAddress}">
<input type="hidden" th:field="*{password}">
<input type="hidden" th:field="*{flgAdmin}">
<div class="back-link">
<button type="submit" class="sub">
社員情報入力に戻る
</button>
</div>
</form>
</div>
</main>
</body>
</html>

View File

@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>社員登録画面</title>
<link rel="stylesheet" th:href="@{/css/style.css}">
</head>
<body>
<!-- 共通ヘッダー -->
<div th:replace="~{fragments/header :: header}"></div>
<!-- 社員登録入力画面 -->
<main>
<h2>社員登録</h2>
<!-- 入力エラー表示 -->
<div th:if="${errors != null and !errors.isEmpty()}">
<p th:each="error : ${errors}"
th:text="${error}"
class="error">
</p>
</div>
<form th:action="@{/admin/employees/new/confirm}"
th:object="${form}"
method="post">
<div>
<label for="nmEmployee">社員名</label>
<input type="text"
id="nmEmployee"
th:field="*{nmEmployee}">
</div>
<div>
<label for="knEmployee">社員名よみ</label>
<input type="text"
id="knEmployee"
th:field="*{knEmployee}">
</div>
<div>
<label for="mailAddress">メールアドレス</label>
<input type="email"
id="mailAddress"
th:field="*{mailAddress}">
</div>
<div>
<label for="password">パスワード</label>
<input type="password"
id="password"
th:field="*{password}">
</div>
<fieldset>
<legend>権限</legend>
<label>
<input type="radio"
th:field="*{flgAdmin}"
value="0">
一般
</label>
<label>
<input type="radio"
th:field="*{flgAdmin}"
value="1">
管理者
</label>
</fieldset>
<button type="submit">登録確認</button>
</form>
<a th:href="@{/menu}">メニューへ戻る</a>
</main>
</body>
</html>

View File

@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>ログイン</title>
<link rel="stylesheet" th:href="@{/css/style.css}">
</head>
<body>
<main>
<h1>書籍貸出管理システム</h1>
@@ -24,43 +24,43 @@
</div>
</main>
</body>
</html>
<!--<!DOCTYPE html>-->
<!--<html xmlns:th="http://www.thymeleaf.org">-->
<!--<head>-->
<!-- <meta charset="UTF-8">-->
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0">-->
<!-- 外部スクリプトの読み込み -->
<!-- <script th:src="@{/js/common.js}"></script>-->
<!-- CSSの読み込み -->
<!-- <link rel="stylesheet" th:href="@{/css/all.css}" type="text/css">-->
<!-- <link rel="stylesheet" th:href="@{/css/style.css}" type="text/css">-->
<!-- <title>ログイン</title>-->
<!--</head>-->
<!--<body>-->
<!-- <div class="loginContainer">-->
<!-- <h1>ログイン</h1>-->
<!-- <form th:action="@{/doLogin}"-->
<!-- method="post"-->
<!-- th:object="${loginInfoForm}">-->
<!-- エラーメッセージ -->
<!-- <div class="msgBox error"-->
<!-- th:if="${messageError != null}">-->
<!-- <span class="error"-->
<!-- th:text="${messageError.message}"></span>-->
<!-- </div>-->
<!-- <table>-->
<!-- メールアドレス -->
<!-- <tr>-->
@@ -75,7 +75,7 @@
<!-- />-->
<!-- </td>-->
<!-- </tr>-->
<!-- パスワード -->
<!-- <tr>-->
<!-- <th class="header">パスワード</th>-->
@@ -89,7 +89,7 @@
<!-- />-->
<!-- </td>-->
<!-- </tr>-->
<!-- ボタン -->
<!-- <tr>-->
<!-- <td class="btnArea" colspan="2">-->
@@ -97,7 +97,7 @@
<!-- type="submit"-->
<!-- value="ログイン"-->
<!-- />-->
<!-- <button-->
<!-- type="button"-->
<!-- onclick="clearInput()">-->
@@ -106,11 +106,11 @@
<!-- </td>-->
<!-- </tr>-->
<!-- </table>-->
<!-- </form>-->
<!-- </div>-->
<!-- 入力内容のリセット -->
<!-- <script>-->
<!-- function clearInput() {-->
@@ -118,6 +118,6 @@
<!-- document.getElementById('password').value = '';-->
<!-- }-->
<!-- </script>-->
<!--</body>-->
<!--</html>-->

View File

@@ -23,3 +23,6 @@
</main>
</body>
</html>