Compare commits
3 Commits
d65a84ea79
...
67ad98b0ae
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67ad98b0ae | ||
| 79cbbc1f2b | |||
| 1170c710e3 |
@@ -1,9 +1,9 @@
|
||||
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 {
|
||||
|
||||
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 com.example.demo.app.domain.model.LoginModel;
|
||||
import com.example.demo.app.domain.service.LoginService;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
@@ -15,11 +16,16 @@ public class LoginServiceImpl implements LoginService {
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public UserEntity login(String mailAddress, String password) {
|
||||
public LoginModel login(String mailAddress, String password) {
|
||||
|
||||
return userRepository.findByMailAddressAndPassword(
|
||||
UserEntity userEntity = userRepository.findByMailAddressAndPassword(
|
||||
mailAddress,
|
||||
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 org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
@@ -10,6 +11,10 @@ import com.example.demo.app.infra.entity.UserEntity;
|
||||
@Repository
|
||||
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.PostMapping;
|
||||
|
||||
import com.example.demo.app.domain.model.LoginModel;
|
||||
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 lombok.RequiredArgsConstructor;
|
||||
@@ -33,13 +33,14 @@ public class LoginController {
|
||||
@PostMapping("/login")
|
||||
public String login(
|
||||
@ModelAttribute LoginForm loginForm,
|
||||
Model model, HttpSession session) {
|
||||
Model model,
|
||||
HttpSession session) {
|
||||
|
||||
UserEntity loginUser = loginService.login(
|
||||
LoginModel loginModel = loginService.login(
|
||||
loginForm.getMailAddress(),
|
||||
loginForm.getPassword());
|
||||
|
||||
if (loginUser == null) {
|
||||
if (loginModel == null) {
|
||||
model.addAttribute(
|
||||
"errorMessage",
|
||||
"Email address or password is incorrect.");
|
||||
@@ -47,9 +48,8 @@ public class LoginController {
|
||||
return "login";
|
||||
}
|
||||
|
||||
session.setAttribute("loginUser", loginUser);
|
||||
session.setAttribute("loginUser", loginModel);
|
||||
|
||||
return "menu";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user