Merge branch 's-morimto' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into n-kawahito
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
package com.example.demo.app.domain.service;
|
package com.example.demo.app.domain.service;
|
||||||
|
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
import com.example.demo.app.domain.model.LoginModel;
|
||||||
|
|
||||||
public interface LoginService {
|
public interface LoginService {
|
||||||
|
|
||||||
UserEntity login(String mailAddress, String password);
|
LoginModel login(String mailAddress, String password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.example.demo.app.domain.service.impl;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.example.demo.app.domain.model.LoginModel;
|
||||||
import com.example.demo.app.domain.service.LoginService;
|
import com.example.demo.app.domain.service.LoginService;
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
import com.example.demo.app.infra.entity.UserEntity;
|
||||||
import com.example.demo.app.infra.repository.UserRepository;
|
import com.example.demo.app.infra.repository.UserRepository;
|
||||||
@@ -15,11 +16,16 @@ public class LoginServiceImpl implements LoginService {
|
|||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserEntity login(String mailAddress, String password) {
|
public LoginModel login(String mailAddress, String password) {
|
||||||
|
|
||||||
return userRepository.findByMailAddressAndPassword(
|
UserEntity userEntity = userRepository.findByMailAddressAndPassword(
|
||||||
mailAddress,
|
mailAddress,
|
||||||
password).orElse(null);
|
password).orElse(null);
|
||||||
|
|
||||||
|
if (userEntity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LoginModel(userEntity.getUserId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.example.demo.app.infra.repository;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
import com.example.demo.app.infra.entity.UserEntity;
|
||||||
@@ -10,6 +11,10 @@ import com.example.demo.app.infra.entity.UserEntity;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
public interface UserRepository extends JpaRepository<UserEntity, Long> {
|
||||||
|
|
||||||
Optional<UserEntity> findByMailAddressAndPassword(String mailAddress, String password);
|
@Query("select u from UserEntity u where u.mailAddress = :mailAddress and u.password = :password and u.deleteFlag = 0")
|
||||||
|
Optional<UserEntity> findByMailAddressAndPassword(
|
||||||
|
String mailAddress,
|
||||||
|
String password);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
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.app.domain.model.LoginModel;
|
||||||
import com.example.demo.app.domain.service.LoginService;
|
import com.example.demo.app.domain.service.LoginService;
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
|
||||||
import com.example.demo.app.presentation.form.LoginForm;
|
import com.example.demo.app.presentation.form.LoginForm;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -33,13 +33,14 @@ public class LoginController {
|
|||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public String login(
|
public String login(
|
||||||
@ModelAttribute LoginForm loginForm,
|
@ModelAttribute LoginForm loginForm,
|
||||||
Model model, HttpSession session) {
|
Model model,
|
||||||
|
HttpSession session) {
|
||||||
|
|
||||||
UserEntity loginUser = loginService.login(
|
LoginModel loginModel = loginService.login(
|
||||||
loginForm.getMailAddress(),
|
loginForm.getMailAddress(),
|
||||||
loginForm.getPassword());
|
loginForm.getPassword());
|
||||||
|
|
||||||
if (loginUser == null) {
|
if (loginModel == null) {
|
||||||
model.addAttribute(
|
model.addAttribute(
|
||||||
"errorMessage",
|
"errorMessage",
|
||||||
"Email address or password is incorrect.");
|
"Email address or password is incorrect.");
|
||||||
@@ -47,9 +48,8 @@ public class LoginController {
|
|||||||
return "login";
|
return "login";
|
||||||
}
|
}
|
||||||
|
|
||||||
session.setAttribute("loginUser", loginUser);
|
session.setAttribute("loginUser", loginModel);
|
||||||
|
|
||||||
return "menu";
|
return "menu";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user