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,18 +12,11 @@ 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;
|
||||
@@ -35,77 +25,6 @@ public class LoginController {
|
||||
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";
|
||||
@@ -151,5 +70,3 @@ public class LoginController {
|
||||
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";
|
||||
// }
|
||||
//}
|
||||
@@ -2,97 +2,6 @@
|
||||
<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}">
|
||||
@@ -114,7 +23,6 @@
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
>>>>>>> 81d722be8d9837c5d9bcdfda5182ced23af4c17d
|
||||
</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