[EDIT]パスワード再設定のバグ修正
This commit is contained in:
@@ -24,38 +24,19 @@ public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
.orElse(null);
|
||||
|
||||
if (userEntity == null) {
|
||||
System.out.println("ユーザーなし");
|
||||
return null;
|
||||
}
|
||||
|
||||
System.out.println("DB質問ID="
|
||||
+ userEntity.getQuestionEntity().getSecretQuestionId());
|
||||
|
||||
System.out.println("入力質問ID="
|
||||
+ authenticationForm.getSecretQuestionId());
|
||||
|
||||
if (!userEntity.getQuestionEntity().getSecretQuestionId()
|
||||
.equals(authenticationForm.getSecretQuestionId())) {
|
||||
|
||||
System.out.println("質問ID不一致");
|
||||
return null;
|
||||
}
|
||||
|
||||
System.out.println("DB回答=["
|
||||
+ userEntity.getSecretQuestionAnswer() + "]");
|
||||
|
||||
System.out.println("入力回答=["
|
||||
+ authenticationForm.getSecretAnswer() + "]");
|
||||
|
||||
if (!userEntity.getSecretQuestionAnswer()
|
||||
.equals(authenticationForm.getSecretAnswer())) {
|
||||
|
||||
System.out.println("回答不一致");
|
||||
return null;
|
||||
}
|
||||
|
||||
System.out.println("認証OK");
|
||||
|
||||
return new AuthenticationModel(userEntity.getUserId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ 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.LoginModel;
|
||||
import com.example.demo.app.domain.service.PasswordResetService;
|
||||
import com.example.demo.app.presentation.form.PasswordResetForm;
|
||||
|
||||
@@ -25,29 +26,45 @@ public class PasswordResetController {
|
||||
|
||||
@PostMapping("/password/reset")
|
||||
public String resetPassword(
|
||||
PasswordResetForm passwordResetForm,
|
||||
Model model,
|
||||
HttpSession session){
|
||||
|
||||
Long userId =
|
||||
(Long) session.getAttribute("passwordResetUserId");
|
||||
|
||||
if(userId == null) {
|
||||
return "redirect:/login";
|
||||
}
|
||||
|
||||
boolean isReset =
|
||||
passwordResetService.resetPassword(userId, passwordResetForm);
|
||||
|
||||
if(!isReset) {
|
||||
model.addAttribute("Message", "パスワードが一致しません。");
|
||||
return "password_reset";
|
||||
}
|
||||
|
||||
session.removeAttribute("passwordResetUserId");
|
||||
|
||||
return "redirect:/login";
|
||||
PasswordResetForm passwordResetForm,
|
||||
Model model,
|
||||
HttpSession session){
|
||||
|
||||
Long userId =
|
||||
(Long) session.getAttribute("passwordResetUserId");
|
||||
|
||||
if (userId == null) {
|
||||
LoginModel loginUser =
|
||||
(LoginModel) session.getAttribute("loginUser");
|
||||
|
||||
if (loginUser != null) {
|
||||
userId = loginUser.getUserId();
|
||||
}
|
||||
}
|
||||
|
||||
if (userId == null) {
|
||||
return "redirect:/login";
|
||||
}
|
||||
|
||||
boolean isReset =
|
||||
passwordResetService.resetPassword(userId, passwordResetForm);
|
||||
|
||||
System.out.println("isReset=" + isReset);
|
||||
|
||||
if(!isReset) {
|
||||
model.addAttribute("Message", "パスワードが一致しません。");
|
||||
return "password_reset";
|
||||
}
|
||||
|
||||
session.removeAttribute("passwordResetUserId");
|
||||
|
||||
LoginModel loginUser =
|
||||
(LoginModel) session.getAttribute("loginUser");
|
||||
|
||||
if (loginUser != null) {
|
||||
return "redirect:/menu";
|
||||
}
|
||||
|
||||
return "redirect:/login";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -36,8 +36,8 @@
|
||||
<button type="submit">再設定</button>
|
||||
</form>
|
||||
|
||||
<div th:if="${errorMessage}">
|
||||
<p th:text="${errorMessage}"></p>
|
||||
<div th:if="${Message}">
|
||||
<p th:text="${Message}"></p>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user