Merge branch 'h-seya' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/ShareBooks_new into s-tajihi
# Conflicts: # src/main/resources/templates/book.html # src/main/resources/templates/topmenu.html
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
package com.example.demo.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class BookUpdateConfirmController {
|
||||||
|
|
||||||
|
@PostMapping("/updateconfirm")
|
||||||
|
public String updateConfirm() {
|
||||||
|
return "updateconfirm";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.example.demo.controller;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class BookUpdateController {
|
||||||
|
|
||||||
|
@PostMapping("/update")
|
||||||
|
public String update() {
|
||||||
|
return "update";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/bookUpdate")
|
||||||
|
public String bookUpdate() {
|
||||||
|
return "book";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,22 +1,77 @@
|
|||||||
package com.example.demo.controller;
|
package com.example.demo.controller;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
|
import com.example.demo.entity.AccountEntity;
|
||||||
|
import com.example.demo.form.LoginForm;
|
||||||
|
import com.example.demo.service.LoginService;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class LoginController {
|
public class LoginController {
|
||||||
|
|
||||||
@GetMapping("/login")
|
private final LoginService loginService;
|
||||||
public String showLogin() {
|
|
||||||
return "login";
|
// Boot起動直後にログイン画面に移動する用のメソッド
|
||||||
|
@GetMapping("/")
|
||||||
|
public String index(HttpSession session) {
|
||||||
|
if (session.getAttribute("loginEmployee") != null) {
|
||||||
|
return "redirect:/topmenu";
|
||||||
|
}
|
||||||
|
return "redirect:/login";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/doLogin")
|
@GetMapping("/login")
|
||||||
public String doLogin() {
|
public String loginForm(Model model, HttpSession session) {
|
||||||
|
if (session.getAttribute("loginEmployee") != null) {
|
||||||
return "redirect:/topmenu";
|
return "redirect:/topmenu";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model.addAttribute("loginForm", new LoginForm());
|
||||||
|
return "login";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 実際のログイン処理
|
||||||
|
@PostMapping("/login")
|
||||||
|
public String doLogin(
|
||||||
|
@Valid @ModelAttribute LoginForm loginForm,
|
||||||
|
BindingResult bindingResult,
|
||||||
|
Model model,
|
||||||
|
HttpSession session) {
|
||||||
|
|
||||||
|
if (bindingResult.hasErrors()) {
|
||||||
|
return "login";
|
||||||
|
}
|
||||||
|
|
||||||
|
AccountEntity accountEntity = loginService.login(loginForm);
|
||||||
|
if (accountEntity == null) {
|
||||||
|
model.addAttribute("loginError",
|
||||||
|
"ログインIDまたはパスワードが正しくありません");
|
||||||
|
return "login";
|
||||||
|
}
|
||||||
|
|
||||||
|
session.setAttribute("loginEmployee", accountEntity);
|
||||||
|
return "redirect:/topmenu";
|
||||||
|
}
|
||||||
|
|
||||||
|
// ログアウト処理
|
||||||
|
@GetMapping("/logout")
|
||||||
|
public String logout(HttpSession session) {
|
||||||
|
session.invalidate();
|
||||||
|
return "redirect:/login";
|
||||||
|
}
|
||||||
|
|
||||||
|
// 各画面からトップメニューへの遷移用
|
||||||
@GetMapping("/topmenu")
|
@GetMapping("/topmenu")
|
||||||
public String showTopMenu() {
|
public String showTopMenu() {
|
||||||
return "topmenu";
|
return "topmenu";
|
||||||
|
|||||||
40
src/main/java/com/example/demo/entity/AccountEntity.java
Normal file
40
src/main/java/com/example/demo/entity/AccountEntity.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package com.example.demo.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* accountテーブル用のEntityクラス
|
||||||
|
* ログイン時やセッションでの管理者判別に使う
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "account")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class AccountEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name="login_info_id")
|
||||||
|
private Integer loginInfoId;
|
||||||
|
|
||||||
|
@Column(name="employee_id")
|
||||||
|
private Integer employeeId;
|
||||||
|
|
||||||
|
@Column(name="password_hash")
|
||||||
|
private String passwordHash;
|
||||||
|
|
||||||
|
@Column(name="admin_flag")
|
||||||
|
private int adminFlag;
|
||||||
|
|
||||||
|
}
|
||||||
17
src/main/java/com/example/demo/form/LoginForm.java
Normal file
17
src/main/java/com/example/demo/form/LoginForm.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.example.demo.form;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LoginForm {
|
||||||
|
|
||||||
|
@NotNull(message = "社員IDを入力してください")
|
||||||
|
private Integer employeeId;
|
||||||
|
|
||||||
|
@NotBlank(message = "パスワードを入力してください")
|
||||||
|
private String passwordHash;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.example.demo.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import com.example.demo.entity.AccountEntity;
|
||||||
|
|
||||||
|
public interface AccountRepository extends JpaRepository<AccountEntity,Integer>{
|
||||||
|
|
||||||
|
AccountEntity findByEmployeeId (Integer employeeId);
|
||||||
|
|
||||||
|
}
|
||||||
31
src/main/java/com/example/demo/service/LoginService.java
Normal file
31
src/main/java/com/example/demo/service/LoginService.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package com.example.demo.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.example.demo.entity.AccountEntity;
|
||||||
|
import com.example.demo.form.LoginForm;
|
||||||
|
import com.example.demo.repository.AccountRepository;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class LoginService {
|
||||||
|
|
||||||
|
private final AccountRepository accountRepository;
|
||||||
|
|
||||||
|
public AccountEntity login(LoginForm form) {
|
||||||
|
AccountEntity accountEntity =
|
||||||
|
accountRepository.findByEmployeeId(form.getEmployeeId());
|
||||||
|
|
||||||
|
if(accountEntity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!accountEntity.getPasswordHash().equals(form.getPasswordHash()))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return accountEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,29 +1,35 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>ログイン</title>
|
<title>ログイン</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>ログイン</h1>
|
<h1>ログイン</h1>
|
||||||
<form action="doLogin"
|
|
||||||
method="post"
|
|
||||||
th:object="${loginInfoForm}">
|
|
||||||
|
|
||||||
<div class="msgBox error" th:if="${messageError} != null">
|
<p class="message message-error" th:if="${loginError}" th:text="${loginError}">
|
||||||
<span class="error" th:text="${messageError.message}"></span>
|
</p>
|
||||||
|
|
||||||
|
<form th:action="@{/login}" th:object="${loginForm}" method="post">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="employeeId">社員ID</label>
|
||||||
|
<input id="employeeId" type="text" th:field="*{employeeId}">
|
||||||
|
<p class="field-error" th:errors="*{employeeId}"></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<table>
|
<div class="form-group">
|
||||||
<tr>
|
<label for="passwordHash">パスワード</label>
|
||||||
<td class="btnArea" colspan="2">
|
<input id="passwordHash" type="password" th:field="*{passwordHash}">
|
||||||
<input type="submit" value="ログイン"/>
|
<p class="field-error" th:errors="*{passwordHash}"></p>
|
||||||
<button onclick="clearInput()">リセット</button>
|
</div>
|
||||||
</td>
|
|
||||||
</tr>
|
<input type="submit" value="ログイン">
|
||||||
</table>
|
<input type="reset" value="リセット">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -5,6 +5,13 @@
|
|||||||
<title>図書情報更新入力</title>
|
<title>図書情報更新入力</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
更新入力画面
|
||||||
|
|
||||||
|
<form method="post" action="updateconfirm">
|
||||||
|
<button type="submit" class="btn-login">
|
||||||
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"/><polyline points="10 17 15 12 10 7"/><line x1="15" y1="12" x2="3" y2="12"/></svg>
|
||||||
|
更新内容確認
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
24
src/main/resources/templates/updateConfirm.html
Normal file
24
src/main/resources/templates/updateConfirm.html
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>更新内容確認</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
更新内容確認画面
|
||||||
|
|
||||||
|
<form method="post" action="update">
|
||||||
|
<button type="submit" class="btn-login">
|
||||||
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"/><polyline points="10 17 15 12 10 7"/><line x1="15" y1="12" x2="3" y2="12"/></svg>
|
||||||
|
戻る
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form method="post" action="bookUpdate">
|
||||||
|
<button type="submit" class="btn-login">
|
||||||
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"/><polyline points="10 17 15 12 10 7"/><line x1="15" y1="12" x2="3" y2="12"/></svg>
|
||||||
|
更新完了
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user