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