Compare commits
20 Commits
24caa7f6e2
...
19615ef3f4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19615ef3f4 | ||
|
|
f059dc9f53 | ||
|
|
0ce3d392a9 | ||
|
|
0a48649741 | ||
|
|
004ea0d5b9 | ||
|
|
21dd389deb | ||
|
|
bef3b58ef4 | ||
|
|
7548257db6 | ||
|
|
93473b1822 | ||
|
|
853af1ec43 | ||
|
|
2a29f53479 | ||
|
|
4f46641774 | ||
|
|
d507d68e1b | ||
|
|
536a98767d | ||
|
|
401542974c | ||
|
|
1be82da0a6 | ||
|
|
a7112b7bc0 | ||
|
|
593e58db8c | ||
|
|
a6d075a686 | ||
|
|
5bf0e41745 |
@@ -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;
|
||||
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
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.ModelAttribute;
|
||||
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
|
||||
@RequiredArgsConstructor
|
||||
public class LoginController {
|
||||
|
||||
@GetMapping("/login")
|
||||
public String showLogin() {
|
||||
return "login";
|
||||
private final LoginService loginService;
|
||||
|
||||
// Boot起動直後にログイン画面に移動する用のメソッド
|
||||
@GetMapping("/")
|
||||
public String index(HttpSession session) {
|
||||
if (session.getAttribute("loginEmployee") != null) {
|
||||
return "redirect:/topmenu";
|
||||
}
|
||||
return "redirect:/login";
|
||||
}
|
||||
|
||||
@PostMapping("/doLogin")
|
||||
public String doLogin() {
|
||||
@GetMapping("/login")
|
||||
public String loginForm(Model model, HttpSession session) {
|
||||
if (session.getAttribute("loginEmployee") != null) {
|
||||
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")
|
||||
public String showTopMenu() {
|
||||
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;
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
@@ -88,4 +89,7 @@ public class Book {
|
||||
@Column(name = "book_approval", nullable = false)
|
||||
private Integer bookApproval;
|
||||
|
||||
@OneToOne(mappedBy = "book")
|
||||
private BookLend bookLends;
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.Data;
|
||||
@@ -22,8 +24,9 @@ public class BookLend {
|
||||
private int lendId;
|
||||
|
||||
// 図書管理ID(BK-1など)
|
||||
@Column(name = "book_manage_id", nullable = false)
|
||||
private String bookManageId;
|
||||
@OneToOne
|
||||
@JoinColumn(name = "book_manage_id", referencedColumnName = "book_manage_id",nullable = false)
|
||||
private Book book;
|
||||
|
||||
// 図書管理ID(BK-1など)
|
||||
@Column(name = "employee_id", nullable = false)
|
||||
|
||||
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>
|
||||
<html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>ログイン</title>
|
||||
<meta charset="UTF-8">
|
||||
<title>ログイン</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>ログイン</h1>
|
||||
<form action="doLogin"
|
||||
method="post"
|
||||
th:object="${loginInfoForm}">
|
||||
|
||||
<div class="msgBox error" th:if="${messageError} != null">
|
||||
<span class="error" th:text="${messageError.message}"></span>
|
||||
<p class="message message-error" th:if="${loginError}" th:text="${loginError}">
|
||||
</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>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td class="btnArea" colspan="2">
|
||||
<input type="submit" value="ログイン"/>
|
||||
<button onclick="clearInput()">リセット</button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="form-group">
|
||||
<label for="passwordHash">パスワード</label>
|
||||
<input id="passwordHash" type="password" th:field="*{passwordHash}">
|
||||
<p class="field-error" th:errors="*{passwordHash}"></p>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="ログイン">
|
||||
<input type="reset" value="リセット">
|
||||
</form>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,10 +1,34 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>トップメニュー</title>
|
||||
<meta charset="UTF-8">
|
||||
<title>トップメニュー</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div class="header-bar">
|
||||
|
||||
<div class="header-left">
|
||||
ShareBooks
|
||||
</div>
|
||||
|
||||
<div class="header-right">
|
||||
|
||||
<span class="user">
|
||||
テストユーザー(一般)
|
||||
</span>
|
||||
|
||||
<a class="button-link" th:href="@{/logout}">
|
||||
ログアウト
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<h1>
|
||||
メインメニュー
|
||||
</h1>
|
||||
@@ -82,4 +106,5 @@
|
||||
</a>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -5,6 +5,13 @@
|
||||
<title>図書情報更新入力</title>
|
||||
</head>
|
||||
<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>
|
||||
</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