|
|
|
|
@@ -1,8 +1,11 @@
|
|
|
|
|
package com.example.demo.controller;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import jakarta.servlet.http.HttpSession;
|
|
|
|
|
import jakarta.validation.Valid;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
@@ -11,7 +14,9 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
|
|
|
|
|
import com.example.demo.entity.AccountEntity;
|
|
|
|
|
import com.example.demo.entity.Employee;
|
|
|
|
|
import com.example.demo.form.LoginForm;
|
|
|
|
|
import com.example.demo.repository.EmployeeRepository;
|
|
|
|
|
import com.example.demo.service.LoginService;
|
|
|
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
@@ -21,12 +26,20 @@ import lombok.RequiredArgsConstructor;
|
|
|
|
|
public class LoginController {
|
|
|
|
|
|
|
|
|
|
private final LoginService loginService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private EmployeeRepository employeeRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Boot起動直後にログイン画面に移動する用のメソッド
|
|
|
|
|
@GetMapping("/")
|
|
|
|
|
public String index(HttpSession session) {
|
|
|
|
|
public String index(Model model,HttpSession session) {
|
|
|
|
|
if (session.getAttribute("loginEmployee") != null) {
|
|
|
|
|
return "redirect:/topmenu";
|
|
|
|
|
if(session.getAttribute("EmployeeId") != null) {
|
|
|
|
|
|
|
|
|
|
List<Employee> emrp = employeeRepository.findByEmployeeId((Integer)session.getAttribute("EmployeeId") );
|
|
|
|
|
model.addAttribute("LoginName",emrp.getFirst().getEmployeeName());
|
|
|
|
|
}
|
|
|
|
|
return "topmenu";
|
|
|
|
|
}
|
|
|
|
|
return "redirect:/login";
|
|
|
|
|
}
|
|
|
|
|
@@ -34,7 +47,12 @@ public class LoginController {
|
|
|
|
|
@GetMapping("/login")
|
|
|
|
|
public String loginForm(Model model, HttpSession session) {
|
|
|
|
|
if (session.getAttribute("loginEmployee") != null) {
|
|
|
|
|
return "redirect:/topmenu";
|
|
|
|
|
if(session.getAttribute("EmployeeId") != null) {
|
|
|
|
|
|
|
|
|
|
List<Employee> emrp = employeeRepository.findByEmployeeId((Integer)session.getAttribute("EmployeeId") );
|
|
|
|
|
model.addAttribute("LoginName",emrp.getFirst().getEmployeeName());
|
|
|
|
|
}
|
|
|
|
|
return "topmenu";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model.addAttribute("loginForm", new LoginForm());
|
|
|
|
|
@@ -61,7 +79,13 @@ public class LoginController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
session.setAttribute("loginEmployee", accountEntity);
|
|
|
|
|
return "redirect:/topmenu";
|
|
|
|
|
|
|
|
|
|
List<Employee> emrp = employeeRepository.findByEmployeeId(accountEntity.getEmployee().getEmployeeId());
|
|
|
|
|
model.addAttribute("LoginName",emrp.getFirst().getEmployeeName());
|
|
|
|
|
session.setAttribute("EmployeeId", accountEntity.getEmployee().getEmployeeId());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "topmenu";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ログアウト処理
|
|
|
|
|
@@ -73,7 +97,13 @@ public class LoginController {
|
|
|
|
|
|
|
|
|
|
// 各画面からトップメニューへの遷移用
|
|
|
|
|
@GetMapping("/topmenu")
|
|
|
|
|
public String showTopMenu() {
|
|
|
|
|
public String showTopMenu(Model model,HttpSession session) {
|
|
|
|
|
|
|
|
|
|
if(session.getAttribute("EmployeeId") != null) {
|
|
|
|
|
|
|
|
|
|
List<Employee> emrp = employeeRepository.findByEmployeeId((Integer)session.getAttribute("EmployeeId") );
|
|
|
|
|
model.addAttribute("LoginName",emrp.getFirst().getEmployeeName());
|
|
|
|
|
}
|
|
|
|
|
return "topmenu";
|
|
|
|
|
}
|
|
|
|
|
}
|