FR-01
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
>>>>>>> 81d722be8d9837c5d9bcdfda5182ced23af4c17d
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
@@ -15,102 +12,24 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
<<<<<<< HEAD
|
||||
import com.example.demo.common.LoginUser;
|
||||
import com.example.demo.entity.Employee;
|
||||
import com.example.demo.repository.EmployeeRepository;
|
||||
|
||||
=======
|
||||
import com.example.demo.common.Const;
|
||||
import com.example.demo.common.LoginUser;
|
||||
import com.example.demo.service.AuthService;
|
||||
|
||||
|
||||
/** AUTH-01:ログイン/ログアウト(login.html) */
|
||||
>>>>>>> 81d722be8d9837c5d9bcdfda5182ced23af4c17d
|
||||
@Controller
|
||||
public class LoginController {
|
||||
private final AuthService authService;
|
||||
|
||||
|
||||
public LoginController(AuthService authService) {
|
||||
this.authService = authService;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
private final EmployeeRepository employeeRepository;
|
||||
|
||||
public LoginController(EmployeeRepository employeeRepository) {
|
||||
this.employeeRepository = employeeRepository;
|
||||
}
|
||||
|
||||
// ログイン画面表示
|
||||
@GetMapping("/")
|
||||
public String showLogin() {
|
||||
return "login";
|
||||
}
|
||||
|
||||
// ログイン処理
|
||||
@PostMapping("/doLogin")
|
||||
public String doLogin(
|
||||
@RequestParam(required = false) String mailAddress,
|
||||
@RequestParam(required = false) String password,
|
||||
HttpServletRequest request,
|
||||
Model model) {
|
||||
|
||||
// 入力チェック
|
||||
if (mailAddress == null || password == null
|
||||
|| mailAddress.isBlank() || password.isBlank()
|
||||
|| mailAddress.length() > 256
|
||||
|| !mailAddress.matches(
|
||||
"^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$")) {
|
||||
|
||||
model.addAttribute("errorMessage",
|
||||
"メールアドレスとパスワードを正しく入力してください。");
|
||||
return "login";
|
||||
}
|
||||
|
||||
// 在籍中の社員を検索
|
||||
Employee employee = employeeRepository
|
||||
.findByMailAddressAndFlgRetirement(
|
||||
mailAddress.trim(), "0")
|
||||
.orElse(null);
|
||||
|
||||
// 社員情報・パスワードの確認
|
||||
if (employee == null
|
||||
|| !password.equals(employee.getPassword())) {
|
||||
|
||||
model.addAttribute("errorMessage",
|
||||
"メールアドレスまたはパスワードが正しくありません。");
|
||||
return "login";
|
||||
}
|
||||
|
||||
// 古いセッションがあれば破棄
|
||||
HttpSession oldSession = request.getSession(false);
|
||||
if (oldSession != null) {
|
||||
oldSession.invalidate();
|
||||
}
|
||||
|
||||
// ログイン情報を新しいセッションに保存
|
||||
HttpSession newSession = request.getSession(true);
|
||||
|
||||
LoginUser loginUser = new LoginUser(
|
||||
employee.getIdEmployee(),
|
||||
employee.getNmEmployee(),
|
||||
employee.getKnEmployee(),
|
||||
employee.getMailAddress(),
|
||||
employee.getFlgAdmin());
|
||||
|
||||
newSession.setAttribute("loginUser", loginUser);
|
||||
|
||||
// メニュー画面へ遷移
|
||||
return "redirect:/menu";
|
||||
}
|
||||
}
|
||||
=======
|
||||
|
||||
@GetMapping("/")
|
||||
public String root() {
|
||||
return "redirect:/menu";
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/login")
|
||||
public String loginForm(HttpSession session) {
|
||||
if (session.getAttribute(Const.SESSION_LOGIN_USER) != null) {
|
||||
@@ -118,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";
|
||||
@@ -144,12 +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";
|
||||
}
|
||||
}
|
||||
|
||||
>>>>>>> 81d722be8d9837c5d9bcdfda5182ced23af4c17d
|
||||
}
|
||||
@@ -1,31 +1,41 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
@Controller
|
||||
public class MenuController {
|
||||
|
||||
// メニュー画面表示
|
||||
|
||||
@GetMapping("/menu")
|
||||
public String showMenu() {
|
||||
public String showMenu(Model model) {
|
||||
|
||||
// 仮のログインユーザー名
|
||||
model.addAttribute("loginUserName", "テストユーザー");
|
||||
|
||||
// menu.htmlを表示
|
||||
return "menu";
|
||||
}
|
||||
|
||||
// ログアウト処理
|
||||
@PostMapping("/logout")
|
||||
public String logout(HttpServletRequest request) {
|
||||
|
||||
HttpSession session = request.getSession(false);
|
||||
|
||||
if (session != null) {
|
||||
session.invalidate();
|
||||
}
|
||||
|
||||
return "redirect:/login";
|
||||
}
|
||||
}
|
||||
}
|
||||
//@Controller
|
||||
//public class MenuController {
|
||||
//
|
||||
// // メニュー画面表示
|
||||
// @GetMapping("/menu")
|
||||
// public String showMenu() {
|
||||
// return "menu";
|
||||
// }
|
||||
//
|
||||
// // ログアウト処理
|
||||
// @PostMapping("/logout")
|
||||
// public String logout(HttpServletRequest request) {
|
||||
//
|
||||
// HttpSession session = request.getSession(false);
|
||||
//
|
||||
// if (session != null) {
|
||||
// session.invalidate();
|
||||
// }
|
||||
//
|
||||
// return "redirect:/login";
|
||||
// }
|
||||
//}
|
||||
@@ -1,103 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
|
||||
<head>
|
||||
<<<<<<< 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>
|
||||
<h2>ログイン</h2>
|
||||
|
||||
<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>
|
||||
<th class="header">メールアドレス</th>
|
||||
<td>
|
||||
<input
|
||||
id="mailAddress"
|
||||
type="text"
|
||||
th:field="*{mailAddress}"
|
||||
placeholder="メールアドレス"
|
||||
required
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- パスワード -->
|
||||
<tr>
|
||||
<th class="header">パスワード</th>
|
||||
<td>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
th:field="*{password}"
|
||||
placeholder="パスワード"
|
||||
required
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- ボタン -->
|
||||
<tr>
|
||||
<td class="btnArea" colspan="2">
|
||||
<input
|
||||
type="submit"
|
||||
value="ログイン"
|
||||
/>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onclick="clearInput()">
|
||||
リセット
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- 入力内容のリセット -->
|
||||
<script>
|
||||
function clearInput() {
|
||||
document.getElementById('mailAddress').value = '';
|
||||
document.getElementById('password').value = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
=======
|
||||
<meta charset="UTF-8">
|
||||
<title>ログイン</title>
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<h1>書籍貸出管理システム</h1>
|
||||
@@ -114,45 +23,44 @@
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
>>>>>>> 81d722be8d9837c5d9bcdfda5182ced23af4c17d
|
||||
</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>-->
|
||||
@@ -167,7 +75,7 @@
|
||||
<!-- />-->
|
||||
<!-- </td>-->
|
||||
<!-- </tr>-->
|
||||
|
||||
|
||||
<!-- パスワード -->
|
||||
<!-- <tr>-->
|
||||
<!-- <th class="header">パスワード</th>-->
|
||||
@@ -181,7 +89,7 @@
|
||||
<!-- />-->
|
||||
<!-- </td>-->
|
||||
<!-- </tr>-->
|
||||
|
||||
|
||||
<!-- ボタン -->
|
||||
<!-- <tr>-->
|
||||
<!-- <td class="btnArea" colspan="2">-->
|
||||
@@ -189,7 +97,7 @@
|
||||
<!-- type="submit"-->
|
||||
<!-- value="ログイン"-->
|
||||
<!-- />-->
|
||||
|
||||
|
||||
<!-- <button-->
|
||||
<!-- type="button"-->
|
||||
<!-- onclick="clearInput()">-->
|
||||
@@ -198,11 +106,11 @@
|
||||
<!-- </td>-->
|
||||
<!-- </tr>-->
|
||||
<!-- </table>-->
|
||||
|
||||
|
||||
<!-- </form>-->
|
||||
|
||||
|
||||
<!-- </div>-->
|
||||
|
||||
|
||||
<!-- 入力内容のリセット -->
|
||||
<!-- <script>-->
|
||||
<!-- function clearInput() {-->
|
||||
@@ -210,6 +118,6 @@
|
||||
<!-- document.getElementById('password').value = '';-->
|
||||
<!-- }-->
|
||||
<!-- </script>-->
|
||||
|
||||
|
||||
<!--</body>-->
|
||||
<!--</html>-->
|
||||
@@ -8,7 +8,7 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div th:replace="~{fragments/header :: header}"></div>
|
||||
<!-- <div th:replace="~{fragments/header :: header}"></div>-->
|
||||
<main>
|
||||
<h1>書籍管理システム</h1>
|
||||
<h2>メニュー</h2>
|
||||
|
||||
Reference in New Issue
Block a user