Compare commits
15 Commits
3d3177bbfa
...
646c37ea57
| Author | SHA1 | Date | |
|---|---|---|---|
| 646c37ea57 | |||
|
|
6b91c91c19 | ||
|
|
1c5cb6bf7a | ||
|
|
e2286762d6 | ||
|
|
0c19adb63f | ||
|
|
f86d47c17a | ||
| a98554ac69 | |||
|
|
cf31d03415 | ||
|
|
80d83b96f4 | ||
|
|
7f828657ad | ||
|
|
064b74c49b | ||
|
|
4fc69cddb3 | ||
| 72477d014b | |||
|
|
792172664c | ||
|
|
882212aed5 |
@@ -0,0 +1,10 @@
|
||||
package com.example.demo.app.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class AuthenticationModel {
|
||||
private Long userId;
|
||||
}
|
||||
@@ -8,10 +8,9 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class UserModel {
|
||||
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private String emailAddress;
|
||||
private String mailAddress;
|
||||
private String password;
|
||||
private Integer secretQuestionId;
|
||||
private String secretAnswer;
|
||||
@@ -19,7 +18,7 @@ public class UserModel {
|
||||
private Integer saving;
|
||||
private Integer annualIncome;
|
||||
private Integer monthlyBudget;
|
||||
private Integer goalId;
|
||||
private Integer courseId;
|
||||
private Long goalId;
|
||||
private Long courseId;
|
||||
private Integer deleteFlag;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.example.demo.app.domain.service;
|
||||
|
||||
import com.example.demo.app.domain.model.AuthenticationModel;
|
||||
import com.example.demo.app.presentation.form.AuthenticationForm;
|
||||
|
||||
public interface AuthenticationService {
|
||||
|
||||
AuthenticationModel authenticate(AuthenticationForm authenticationForm);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.model.AuthenticationModel;
|
||||
import com.example.demo.app.domain.service.AuthenticationService;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
import com.example.demo.app.presentation.form.AuthenticationForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public AuthenticationModel authenticate(AuthenticationForm authenticationForm) {
|
||||
|
||||
UserEntity userEntity = userRepository.findByMailAddress(
|
||||
authenticationForm.getMailAddress())
|
||||
.orElse(null);
|
||||
|
||||
if (userEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!userEntity.getQuestionEntity().getSecretQuestionId()
|
||||
.equals(authenticationForm.getSecretQuestionId())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!userEntity.getSecretQuestionAnswer()
|
||||
.equals(authenticationForm.getSecretAnswer())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new AuthenticationModel(userEntity.getUserId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import com.example.demo.app.domain.model.AuthenticationModel;
|
||||
import com.example.demo.app.domain.service.AuthenticationService;
|
||||
import com.example.demo.app.infra.repository.QuestionRepository;
|
||||
import com.example.demo.app.presentation.form.AuthenticationForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class AuthenticationController {
|
||||
|
||||
private final AuthenticationService authenticationService;
|
||||
private final QuestionRepository questionRepository;
|
||||
|
||||
@GetMapping("/authentication")
|
||||
public String showAuthentication(Model model) {
|
||||
|
||||
model.addAttribute("authenticationForm", new AuthenticationForm());
|
||||
model.addAttribute("questionList", questionRepository.findAll());
|
||||
|
||||
return "authentication";
|
||||
}
|
||||
|
||||
@PostMapping("/authentication")
|
||||
public String authenticate(
|
||||
AuthenticationForm authenticationForm,
|
||||
Model model,
|
||||
HttpSession session) {
|
||||
|
||||
AuthenticationModel authenticationModel =
|
||||
authenticationService.authenticate(authenticationForm);
|
||||
|
||||
if (authenticationModel == null) {
|
||||
model.addAttribute("errorMessage", "認証情報が正しくありません。");
|
||||
model.addAttribute("questionList", questionRepository.findAll());
|
||||
|
||||
return "authentication";
|
||||
}
|
||||
|
||||
session.setAttribute(
|
||||
"passwordResetUserId",
|
||||
authenticationModel.getUserId());
|
||||
|
||||
return "password_reset";
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AuthenticationForm {
|
||||
private String mailAddress;
|
||||
private Integer secretQuestionId;
|
||||
private String secretAnswer;
|
||||
}
|
||||
53
src/main/resources/templates/Authentication.html
Normal file
53
src/main/resources/templates/Authentication.html
Normal file
@@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>認証</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<h1>本人認証確認</h1>
|
||||
|
||||
<form th:action="@{/authentication}" th:object="${authenticationForm}" method="post">
|
||||
|
||||
<div>
|
||||
<label for="mailAddress">メールアドレス</label>
|
||||
<input type="email" id="mailAddress" th:field="*{mailAddress}">
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="secretQuestionId">秘密の質問</label>
|
||||
<select id="secretQuestionId" th:field="*{secretQuestionId}">
|
||||
|
||||
<option value="">選択してください</option>
|
||||
|
||||
<option th:each="question : ${questionList}" th:value="${question.secretQuestionId}"
|
||||
th:text="${question.questionText}">
|
||||
</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="secretAnswer">秘密の質問の回答</label>
|
||||
<input type="text" id="secretAnswer" th:field="*{secretAnswer}">
|
||||
</div>
|
||||
|
||||
<button type="submit">確認</button>
|
||||
|
||||
</form>
|
||||
|
||||
<form th:action="@{/login}" method="get">
|
||||
<button type="submit">戻る</button>
|
||||
</form>
|
||||
</main>
|
||||
|
||||
<script th:if="${errorMessage}" th:inline="javascript">
|
||||
alert(/*[[${errorMessage}]]*/);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user