FR-01
This commit is contained in:
@@ -1,11 +1,8 @@
|
|||||||
package com.example.demo.controller;
|
package com.example.demo.controller;
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
>>>>>>> 81d722be8d9837c5d9bcdfda5182ced23af4c17d
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpSession;
|
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.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
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.Const;
|
||||||
import com.example.demo.common.LoginUser;
|
import com.example.demo.common.LoginUser;
|
||||||
import com.example.demo.service.AuthService;
|
import com.example.demo.service.AuthService;
|
||||||
|
|
||||||
/** AUTH-01:ログイン/ログアウト(login.html) */
|
/** AUTH-01:ログイン/ログアウト(login.html) */
|
||||||
>>>>>>> 81d722be8d9837c5d9bcdfda5182ced23af4c17d
|
|
||||||
@Controller
|
@Controller
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
private final AuthService authService;
|
private final AuthService authService;
|
||||||
|
|
||||||
public LoginController(AuthService authService) {
|
public LoginController(AuthService authService) {
|
||||||
this.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("/")
|
@GetMapping("/")
|
||||||
public String root() {
|
public String root() {
|
||||||
return "redirect:/menu";
|
return "redirect:/menu";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/login")
|
@GetMapping("/login")
|
||||||
public String loginForm(HttpSession session) {
|
public String loginForm(HttpSession session) {
|
||||||
if (session.getAttribute(Const.SESSION_LOGIN_USER) != null) {
|
if (session.getAttribute(Const.SESSION_LOGIN_USER) != null) {
|
||||||
@@ -118,14 +37,14 @@ public class LoginController {
|
|||||||
}
|
}
|
||||||
return "login";
|
return "login";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public String login(@RequestParam(defaultValue = "") String mailAddress,
|
public String login(@RequestParam(defaultValue = "") String mailAddress,
|
||||||
@RequestParam(defaultValue = "") String password,
|
@RequestParam(defaultValue = "") String password,
|
||||||
HttpServletRequest request, Model model) {
|
HttpServletRequest request, Model model) {
|
||||||
String mail = mailAddress.trim();
|
String mail = mailAddress.trim();
|
||||||
model.addAttribute("mailAddress", mail); // 入力値を保持(パスワードは保持しない)
|
model.addAttribute("mailAddress", mail); // 入力値を保持(パスワードは保持しない)
|
||||||
|
|
||||||
if (mail.isEmpty() || password.isEmpty()) {
|
if (mail.isEmpty() || password.isEmpty()) {
|
||||||
model.addAttribute("errorMessage", "メールアドレスとパスワードを入力してください。");
|
model.addAttribute("errorMessage", "メールアドレスとパスワードを入力してください。");
|
||||||
return "login";
|
return "login";
|
||||||
@@ -144,12 +63,10 @@ public class LoginController {
|
|||||||
request.getSession(true).setAttribute(Const.SESSION_LOGIN_USER, user.get());
|
request.getSession(true).setAttribute(Const.SESSION_LOGIN_USER, user.get());
|
||||||
return "redirect:/menu";
|
return "redirect:/menu";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/logout")
|
@PostMapping("/logout")
|
||||||
public String logout(HttpSession session) {
|
public String logout(HttpSession session) {
|
||||||
session.invalidate();
|
session.invalidate();
|
||||||
return "redirect:/login";
|
return "redirect:/login";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
>>>>>>> 81d722be8d9837c5d9bcdfda5182ced23af4c17d
|
|
||||||
@@ -1,31 +1,41 @@
|
|||||||
package com.example.demo.controller;
|
package com.example.demo.controller;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import jakarta.servlet.http.HttpSession;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class MenuController {
|
public class MenuController {
|
||||||
|
|
||||||
// メニュー画面表示
|
|
||||||
@GetMapping("/menu")
|
@GetMapping("/menu")
|
||||||
public String showMenu() {
|
public String showMenu(Model model) {
|
||||||
|
|
||||||
|
// 仮のログインユーザー名
|
||||||
|
model.addAttribute("loginUserName", "テストユーザー");
|
||||||
|
|
||||||
|
// menu.htmlを表示
|
||||||
return "menu";
|
return "menu";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// ログアウト処理
|
//@Controller
|
||||||
@PostMapping("/logout")
|
//public class MenuController {
|
||||||
public String logout(HttpServletRequest request) {
|
//
|
||||||
|
// // メニュー画面表示
|
||||||
HttpSession session = request.getSession(false);
|
// @GetMapping("/menu")
|
||||||
|
// public String showMenu() {
|
||||||
if (session != null) {
|
// return "menu";
|
||||||
session.invalidate();
|
// }
|
||||||
}
|
//
|
||||||
|
// // ログアウト処理
|
||||||
return "redirect:/login";
|
// @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>
|
<!DOCTYPE html>
|
||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
|
||||||
<head>
|
<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">
|
<meta charset="UTF-8">
|
||||||
<title>ログイン</title>
|
<title>ログイン</title>
|
||||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<h1>書籍貸出管理システム</h1>
|
<h1>書籍貸出管理システム</h1>
|
||||||
@@ -114,45 +23,44 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
>>>>>>> 81d722be8d9837c5d9bcdfda5182ced23af4c17d
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
<!--<!DOCTYPE html>-->
|
<!--<!DOCTYPE html>-->
|
||||||
<!--<html xmlns:th="http://www.thymeleaf.org">-->
|
<!--<html xmlns:th="http://www.thymeleaf.org">-->
|
||||||
|
|
||||||
<!--<head>-->
|
<!--<head>-->
|
||||||
<!-- <meta charset="UTF-8">-->
|
<!-- <meta charset="UTF-8">-->
|
||||||
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0">-->
|
<!-- <meta name="viewport" content="width=device-width, initial-scale=1.0">-->
|
||||||
|
|
||||||
<!-- 外部スクリプトの読み込み -->
|
<!-- 外部スクリプトの読み込み -->
|
||||||
<!-- <script th:src="@{/js/common.js}"></script>-->
|
<!-- <script th:src="@{/js/common.js}"></script>-->
|
||||||
|
|
||||||
<!-- CSSの読み込み -->
|
<!-- CSSの読み込み -->
|
||||||
<!-- <link rel="stylesheet" th:href="@{/css/all.css}" type="text/css">-->
|
<!-- <link rel="stylesheet" th:href="@{/css/all.css}" type="text/css">-->
|
||||||
<!-- <link rel="stylesheet" th:href="@{/css/style.css}" type="text/css">-->
|
<!-- <link rel="stylesheet" th:href="@{/css/style.css}" type="text/css">-->
|
||||||
|
|
||||||
<!-- <title>ログイン</title>-->
|
<!-- <title>ログイン</title>-->
|
||||||
<!--</head>-->
|
<!--</head>-->
|
||||||
|
|
||||||
<!--<body>-->
|
<!--<body>-->
|
||||||
|
|
||||||
<!-- <div class="loginContainer">-->
|
<!-- <div class="loginContainer">-->
|
||||||
|
|
||||||
<!-- <h1>ログイン</h1>-->
|
<!-- <h1>ログイン</h1>-->
|
||||||
|
|
||||||
<!-- <form th:action="@{/doLogin}"-->
|
<!-- <form th:action="@{/doLogin}"-->
|
||||||
<!-- method="post"-->
|
<!-- method="post"-->
|
||||||
<!-- th:object="${loginInfoForm}">-->
|
<!-- th:object="${loginInfoForm}">-->
|
||||||
|
|
||||||
<!-- エラーメッセージ -->
|
<!-- エラーメッセージ -->
|
||||||
<!-- <div class="msgBox error"-->
|
<!-- <div class="msgBox error"-->
|
||||||
<!-- th:if="${messageError != null}">-->
|
<!-- th:if="${messageError != null}">-->
|
||||||
<!-- <span class="error"-->
|
<!-- <span class="error"-->
|
||||||
<!-- th:text="${messageError.message}"></span>-->
|
<!-- th:text="${messageError.message}"></span>-->
|
||||||
<!-- </div>-->
|
<!-- </div>-->
|
||||||
|
|
||||||
<!-- <table>-->
|
<!-- <table>-->
|
||||||
<!-- メールアドレス -->
|
<!-- メールアドレス -->
|
||||||
<!-- <tr>-->
|
<!-- <tr>-->
|
||||||
@@ -167,7 +75,7 @@
|
|||||||
<!-- />-->
|
<!-- />-->
|
||||||
<!-- </td>-->
|
<!-- </td>-->
|
||||||
<!-- </tr>-->
|
<!-- </tr>-->
|
||||||
|
|
||||||
<!-- パスワード -->
|
<!-- パスワード -->
|
||||||
<!-- <tr>-->
|
<!-- <tr>-->
|
||||||
<!-- <th class="header">パスワード</th>-->
|
<!-- <th class="header">パスワード</th>-->
|
||||||
@@ -181,7 +89,7 @@
|
|||||||
<!-- />-->
|
<!-- />-->
|
||||||
<!-- </td>-->
|
<!-- </td>-->
|
||||||
<!-- </tr>-->
|
<!-- </tr>-->
|
||||||
|
|
||||||
<!-- ボタン -->
|
<!-- ボタン -->
|
||||||
<!-- <tr>-->
|
<!-- <tr>-->
|
||||||
<!-- <td class="btnArea" colspan="2">-->
|
<!-- <td class="btnArea" colspan="2">-->
|
||||||
@@ -189,7 +97,7 @@
|
|||||||
<!-- type="submit"-->
|
<!-- type="submit"-->
|
||||||
<!-- value="ログイン"-->
|
<!-- value="ログイン"-->
|
||||||
<!-- />-->
|
<!-- />-->
|
||||||
|
|
||||||
<!-- <button-->
|
<!-- <button-->
|
||||||
<!-- type="button"-->
|
<!-- type="button"-->
|
||||||
<!-- onclick="clearInput()">-->
|
<!-- onclick="clearInput()">-->
|
||||||
@@ -198,11 +106,11 @@
|
|||||||
<!-- </td>-->
|
<!-- </td>-->
|
||||||
<!-- </tr>-->
|
<!-- </tr>-->
|
||||||
<!-- </table>-->
|
<!-- </table>-->
|
||||||
|
|
||||||
<!-- </form>-->
|
<!-- </form>-->
|
||||||
|
|
||||||
<!-- </div>-->
|
<!-- </div>-->
|
||||||
|
|
||||||
<!-- 入力内容のリセット -->
|
<!-- 入力内容のリセット -->
|
||||||
<!-- <script>-->
|
<!-- <script>-->
|
||||||
<!-- function clearInput() {-->
|
<!-- function clearInput() {-->
|
||||||
@@ -210,6 +118,6 @@
|
|||||||
<!-- document.getElementById('password').value = '';-->
|
<!-- document.getElementById('password').value = '';-->
|
||||||
<!-- }-->
|
<!-- }-->
|
||||||
<!-- </script>-->
|
<!-- </script>-->
|
||||||
|
|
||||||
<!--</body>-->
|
<!--</body>-->
|
||||||
<!--</html>-->
|
<!--</html>-->
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div th:replace="~{fragments/header :: header}"></div>
|
<!-- <div th:replace="~{fragments/header :: header}"></div>-->
|
||||||
<main>
|
<main>
|
||||||
<h1>書籍管理システム</h1>
|
<h1>書籍管理システム</h1>
|
||||||
<h2>メニュー</h2>
|
<h2>メニュー</h2>
|
||||||
|
|||||||
Reference in New Issue
Block a user