From 26fd304a660bbee382ca40fd46001162bedc60af Mon Sep 17 00:00:00 2001 From: ddangelorb Date: Tue, 24 Aug 2021 15:03:10 -0300 Subject: [PATCH] Improving ForgotPwd structure --- ...er.java => ForgotPasswordsController.java} | 42 +++++++++---------- ... ForgotPasswordsQuestionsResponseDTO.java} | 2 +- ...wordsQuestionsUsersAnswersRequestDTO.java} | 2 +- ...wordKeys.java => ForgotPasswordsKeys.java} | 2 +- ...ons.java => ForgotPasswordsQuestions.java} | 2 +- ...ForgotPasswordsQuestionsUsersAnswers.java} | 2 +- .../ForgotPasswordQuestionsRepository.java | 7 ---- ...sswordQuestionsUsersAnswersRepository.java | 10 ----- ...ava => ForgotPasswordsKeysRepository.java} | 6 +-- .../ForgotPasswordsQuestionsRepository.java | 7 ++++ ...swordsQuestionsUsersAnswersRepository.java | 10 +++++ ...rvice.java => ForgotPasswordsService.java} | 42 +++++++++---------- .../ForgotPasswordServiceIntegrationTest.java | 8 ++-- 13 files changed, 71 insertions(+), 71 deletions(-) rename src/main/java/org/waterproofingdata/wpdauth/controller/{ForgotPasswordController.java => ForgotPasswordsController.java} (65%) rename src/main/java/org/waterproofingdata/wpdauth/dto/{ForgotPasswordQuestionsResponseDTO.java => ForgotPasswordsQuestionsResponseDTO.java} (86%) rename src/main/java/org/waterproofingdata/wpdauth/dto/{ForgotPasswordQuestionsUsersAnswersRequestDTO.java => ForgotPasswordsQuestionsUsersAnswersRequestDTO.java} (87%) rename src/main/java/org/waterproofingdata/wpdauth/model/{ForgotPasswordKeys.java => ForgotPasswordsKeys.java} (94%) rename src/main/java/org/waterproofingdata/wpdauth/model/{ForgotPasswordQuestions.java => ForgotPasswordsQuestions.java} (93%) rename src/main/java/org/waterproofingdata/wpdauth/model/{ForgotPasswordQuestionsUsersAnswers.java => ForgotPasswordsQuestionsUsersAnswers.java} (93%) delete mode 100644 src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordQuestionsRepository.java delete mode 100644 src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordQuestionsUsersAnswersRepository.java rename src/main/java/org/waterproofingdata/wpdauth/repository/{ForgotPasswordKeysRepository.java => ForgotPasswordsKeysRepository.java} (63%) create mode 100644 src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordsQuestionsRepository.java create mode 100644 src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordsQuestionsUsersAnswersRepository.java rename src/main/java/org/waterproofingdata/wpdauth/service/{ForgotPasswordService.java => ForgotPasswordsService.java} (69%) diff --git a/src/main/java/org/waterproofingdata/wpdauth/controller/ForgotPasswordController.java b/src/main/java/org/waterproofingdata/wpdauth/controller/ForgotPasswordsController.java similarity index 65% rename from src/main/java/org/waterproofingdata/wpdauth/controller/ForgotPasswordController.java rename to src/main/java/org/waterproofingdata/wpdauth/controller/ForgotPasswordsController.java index ab5af8b..9f5bc51 100644 --- a/src/main/java/org/waterproofingdata/wpdauth/controller/ForgotPasswordController.java +++ b/src/main/java/org/waterproofingdata/wpdauth/controller/ForgotPasswordsController.java @@ -10,11 +10,11 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestBody; -import org.waterproofingdata.wpdauth.dto.ForgotPasswordQuestionsResponseDTO; -import org.waterproofingdata.wpdauth.dto.ForgotPasswordQuestionsUsersAnswersRequestDTO; -import org.waterproofingdata.wpdauth.model.ForgotPasswordQuestionsUsersAnswers; +import org.waterproofingdata.wpdauth.dto.ForgotPasswordsQuestionsResponseDTO; +import org.waterproofingdata.wpdauth.dto.ForgotPasswordsQuestionsUsersAnswersRequestDTO; +import org.waterproofingdata.wpdauth.model.ForgotPasswordsQuestionsUsersAnswers; import org.waterproofingdata.wpdauth.dto.CustomMapper; -import org.waterproofingdata.wpdauth.service.ForgotPasswordService; +import org.waterproofingdata.wpdauth.service.ForgotPasswordsService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -26,71 +26,71 @@ import io.swagger.annotations.Authorization; @RestController @RequestMapping("/forgotpassword") @Api(tags = "forgotpassword") -public class ForgotPasswordController { +public class ForgotPasswordsController { @Autowired - private ForgotPasswordService forgotPasswordService; + private ForgotPasswordsService forgotPasswordsService; @PostMapping("/sendkeybyemail") - @ApiOperation(value = "${ForgotPasswordController.sendkeybyemail}") + @ApiOperation(value = "${ForgotPasswordsController.sendkeybyemail}") @ApiResponses(value = {// @ApiResponse(code = 400, message = "Something went wrong"), // @ApiResponse(code = 422, message = "Invalid email supplied")}) public void sendkeybyemail(@ApiParam("Email") @RequestParam String email) { - forgotPasswordService.sendKeyByEmail(email); + forgotPasswordsService.sendKeyByEmail(email); } @PostMapping("/loginbyemailandkey") - @ApiOperation(value = "${ForgotPasswordController.loginbyemailandkey}") + @ApiOperation(value = "${ForgotPasswordsController.loginbyemailandkey}") @ApiResponses(value = {// @ApiResponse(code = 400, message = "Something went wrong"), // @ApiResponse(code = 422, message = "Invalid username/password supplied")}) public String loginbyemailandkey(// @ApiParam("Email") @RequestParam String email, // @ApiParam("Key") @RequestParam String key) { - return forgotPasswordService.loginByEmailAndKey(email, key); + return forgotPasswordsService.loginByEmailAndKey(email, key); } @PostMapping("/passwordupdatebyemail") @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_INSTITUTION') or hasRole('ROLE_CLIENT')") - @ApiOperation(value = "${ForgotPasswordController.passwordupdatebyemail}", authorizations = { @Authorization(value="apiKey") }) + @ApiOperation(value = "${ForgotPasswordsController.passwordupdatebyemail}", authorizations = { @Authorization(value="apiKey") }) @ApiResponses(value = {// @ApiResponse(code = 400, message = "Something went wrong"), // @ApiResponse(code = 403, message = "Access denied"), // @ApiResponse(code = 404, message = "The user doesn't exist"), // @ApiResponse(code = 500, message = "Expired or invalid JWT token")}) public void passwordupdatebyemail(@ApiParam("Email") @RequestParam String email, @ApiParam("NewPassword") @RequestParam String newPassword) { - forgotPasswordService.passwordUpdateByEmail(email, newPassword); + forgotPasswordsService.passwordUpdateByEmail(email, newPassword); } @PostMapping("/findallforgotpasswordquestions") - @ApiOperation(value = "${ForgotPasswordController.findallforgotpasswordquestions}") + @ApiOperation(value = "${ForgotPasswordsController.findallforgotpasswordquestions}") @ApiResponses(value = {// @ApiResponse(code = 400, message = "Something went wrong")}) - public List findallforgotpasswordquestions() { - return CustomMapper.mapAll(forgotPasswordService.findAllForgotPasswordQuestions(), ForgotPasswordQuestionsResponseDTO.class); + public List findallforgotpasswordquestions() { + return CustomMapper.mapAll(forgotPasswordsService.findAllForgotPasswordQuestions(), ForgotPasswordsQuestionsResponseDTO.class); } @PostMapping("/saveforgotpasswordquestionsusersanswers") @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_INSTITUTION') or hasRole('ROLE_CLIENT')") - @ApiOperation(value = "${ForgotPasswordController.saveforgotpasswordquestionsusersanswers}", authorizations = { @Authorization(value="apiKey") }) + @ApiOperation(value = "${ForgotPasswordsController.saveforgotpasswordquestionsusersanswers}", authorizations = { @Authorization(value="apiKey") }) @ApiResponses(value = {// @ApiResponse(code = 400, message = "Something went wrong"), // @ApiResponse(code = 403, message = "Access denied"), // @ApiResponse(code = 404, message = "The user or forgot password questions don't exist"), // @ApiResponse(code = 500, message = "Expired or invalid JWT token")}) - public void saveforgotpasswordquestionsusersanswers(@ApiParam("Forgot Password Questions Users Answers") @RequestBody ForgotPasswordQuestionsUsersAnswersRequestDTO answer) { - forgotPasswordService.saveForgotPasswordQuestionsUsersAnswers(CustomMapper.map(answer, ForgotPasswordQuestionsUsersAnswers.class)); + public void saveforgotpasswordquestionsusersanswers(@ApiParam("Forgot Password Questions Users Answers") @RequestBody ForgotPasswordsQuestionsUsersAnswersRequestDTO answer) { + forgotPasswordsService.saveForgotPasswordQuestionsUsersAnswers(CustomMapper.map(answer, ForgotPasswordsQuestionsUsersAnswers.class)); } @PostMapping("/loginbyemailandanswers") - @ApiOperation(value = "${ForgotPasswordController.loginbyemailandanswers}") + @ApiOperation(value = "${ForgotPasswordsController.loginbyemailandanswers}") @ApiResponses(value = {// @ApiResponse(code = 400, message = "Something went wrong"), // @ApiResponse(code = 404, message = "The user or answer don't exist"), // @ApiResponse(code = 422, message = "Invalid answers supplied to login. Must have at least 2 correct ones.")}) public String loginbyemailandanswers(// @ApiParam("Email") @RequestParam String email, // - @ApiParam("Answers") @RequestParam List answers) { - return forgotPasswordService.loginByEmailAndAnswers(email, CustomMapper.mapAll(answers, ForgotPasswordQuestionsUsersAnswers.class)); + @ApiParam("Answers") @RequestParam List answers) { + return forgotPasswordsService.loginByEmailAndAnswers(email, CustomMapper.mapAll(answers, ForgotPasswordsQuestionsUsersAnswers.class)); } } diff --git a/src/main/java/org/waterproofingdata/wpdauth/dto/ForgotPasswordQuestionsResponseDTO.java b/src/main/java/org/waterproofingdata/wpdauth/dto/ForgotPasswordsQuestionsResponseDTO.java similarity index 86% rename from src/main/java/org/waterproofingdata/wpdauth/dto/ForgotPasswordQuestionsResponseDTO.java rename to src/main/java/org/waterproofingdata/wpdauth/dto/ForgotPasswordsQuestionsResponseDTO.java index c86eac0..ad00399 100644 --- a/src/main/java/org/waterproofingdata/wpdauth/dto/ForgotPasswordQuestionsResponseDTO.java +++ b/src/main/java/org/waterproofingdata/wpdauth/dto/ForgotPasswordsQuestionsResponseDTO.java @@ -6,7 +6,7 @@ import lombok.Setter; @Getter @Setter -public class ForgotPasswordQuestionsResponseDTO { +public class ForgotPasswordsQuestionsResponseDTO { @ApiModelProperty(position = 0) private Integer id; diff --git a/src/main/java/org/waterproofingdata/wpdauth/dto/ForgotPasswordQuestionsUsersAnswersRequestDTO.java b/src/main/java/org/waterproofingdata/wpdauth/dto/ForgotPasswordsQuestionsUsersAnswersRequestDTO.java similarity index 87% rename from src/main/java/org/waterproofingdata/wpdauth/dto/ForgotPasswordQuestionsUsersAnswersRequestDTO.java rename to src/main/java/org/waterproofingdata/wpdauth/dto/ForgotPasswordsQuestionsUsersAnswersRequestDTO.java index 7fd1f0b..a27f2cd 100644 --- a/src/main/java/org/waterproofingdata/wpdauth/dto/ForgotPasswordQuestionsUsersAnswersRequestDTO.java +++ b/src/main/java/org/waterproofingdata/wpdauth/dto/ForgotPasswordsQuestionsUsersAnswersRequestDTO.java @@ -7,7 +7,7 @@ import lombok.Setter; @Getter @Setter -public class ForgotPasswordQuestionsUsersAnswersRequestDTO { +public class ForgotPasswordsQuestionsUsersAnswersRequestDTO { @ApiModelProperty(position = 0) private Integer id; diff --git a/src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordKeys.java b/src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordsKeys.java similarity index 94% rename from src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordKeys.java rename to src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordsKeys.java index 28e7881..e08ffd3 100644 --- a/src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordKeys.java +++ b/src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordsKeys.java @@ -14,7 +14,7 @@ import lombok.Setter; @Getter @Setter @NoArgsConstructor -public class ForgotPasswordKeys { +public class ForgotPasswordsKeys { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; diff --git a/src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordQuestions.java b/src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordsQuestions.java similarity index 93% rename from src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordQuestions.java rename to src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordsQuestions.java index f000311..4df2080 100644 --- a/src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordQuestions.java +++ b/src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordsQuestions.java @@ -14,7 +14,7 @@ import lombok.Setter; @Getter @Setter @NoArgsConstructor -public class ForgotPasswordQuestions { +public class ForgotPasswordsQuestions { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; diff --git a/src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordQuestionsUsersAnswers.java b/src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordsQuestionsUsersAnswers.java similarity index 93% rename from src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordQuestionsUsersAnswers.java rename to src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordsQuestionsUsersAnswers.java index 908d5e4..ce80e0f 100644 --- a/src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordQuestionsUsersAnswers.java +++ b/src/main/java/org/waterproofingdata/wpdauth/model/ForgotPasswordsQuestionsUsersAnswers.java @@ -14,7 +14,7 @@ import lombok.Setter; @Getter @Setter @NoArgsConstructor -public class ForgotPasswordQuestionsUsersAnswers { +public class ForgotPasswordsQuestionsUsersAnswers { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; diff --git a/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordQuestionsRepository.java b/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordQuestionsRepository.java deleted file mode 100644 index 9f123a2..0000000 --- a/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordQuestionsRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.waterproofingdata.wpdauth.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.waterproofingdata.wpdauth.model.ForgotPasswordQuestions; - -public interface ForgotPasswordQuestionsRepository extends JpaRepository { -} diff --git a/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordQuestionsUsersAnswersRepository.java b/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordQuestionsUsersAnswersRepository.java deleted file mode 100644 index b23cd44..0000000 --- a/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordQuestionsUsersAnswersRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.waterproofingdata.wpdauth.repository; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.waterproofingdata.wpdauth.model.ForgotPasswordQuestionsUsersAnswers; - -public interface ForgotPasswordQuestionsUsersAnswersRepository extends JpaRepository { - @Query(value = "SELECT fqua.* FROM forgotpassword_questions_users_answers fqua WHERE fqua.forgotpassword_questions_id = ?1 AND fqua.users_id = ?2", nativeQuery = true) - ForgotPasswordQuestionsUsersAnswers findByForgotPasswordQuestionsAndUserid(Integer forgotpasswordquestionsid, Integer usersid); -} diff --git a/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordKeysRepository.java b/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordsKeysRepository.java similarity index 63% rename from src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordKeysRepository.java rename to src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordsKeysRepository.java index c5c4aee..9048f53 100644 --- a/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordKeysRepository.java +++ b/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordsKeysRepository.java @@ -2,9 +2,9 @@ package org.waterproofingdata.wpdauth.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; -import org.waterproofingdata.wpdauth.model.ForgotPasswordKeys; +import org.waterproofingdata.wpdauth.model.ForgotPasswordsKeys; -public interface ForgotPasswordKeysRepository extends JpaRepository { +public interface ForgotPasswordsKeysRepository extends JpaRepository { @Query(value = "SELECT f.* FROM forgotpassword_keys f WHERE f.email = ?1 AND f.key = ?2 AND f.created_at >= current_date::timestamp AND f.created_at < current_date::timestamp + interval '1 day' ORDER BY f.id DESC LIMIT 1", nativeQuery = true) - ForgotPasswordKeys findTodayRecordByEmailANDKey(String email, String key); + ForgotPasswordsKeys findTodayRecordByEmailANDKey(String email, String key); } diff --git a/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordsQuestionsRepository.java b/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordsQuestionsRepository.java new file mode 100644 index 0000000..dafea7b --- /dev/null +++ b/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordsQuestionsRepository.java @@ -0,0 +1,7 @@ +package org.waterproofingdata.wpdauth.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.waterproofingdata.wpdauth.model.ForgotPasswordsQuestions; + +public interface ForgotPasswordsQuestionsRepository extends JpaRepository { +} diff --git a/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordsQuestionsUsersAnswersRepository.java b/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordsQuestionsUsersAnswersRepository.java new file mode 100644 index 0000000..c3b17e2 --- /dev/null +++ b/src/main/java/org/waterproofingdata/wpdauth/repository/ForgotPasswordsQuestionsUsersAnswersRepository.java @@ -0,0 +1,10 @@ +package org.waterproofingdata.wpdauth.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.waterproofingdata.wpdauth.model.ForgotPasswordsQuestionsUsersAnswers; + +public interface ForgotPasswordsQuestionsUsersAnswersRepository extends JpaRepository { + @Query(value = "SELECT fqua.* FROM forgotpassword_questions_users_answers fqua WHERE fqua.forgotpassword_questions_id = ?1 AND fqua.users_id = ?2", nativeQuery = true) + ForgotPasswordsQuestionsUsersAnswers findByForgotPasswordQuestionsAndUserid(Integer forgotpasswordquestionsid, Integer usersid); +} diff --git a/src/main/java/org/waterproofingdata/wpdauth/service/ForgotPasswordService.java b/src/main/java/org/waterproofingdata/wpdauth/service/ForgotPasswordsService.java similarity index 69% rename from src/main/java/org/waterproofingdata/wpdauth/service/ForgotPasswordService.java rename to src/main/java/org/waterproofingdata/wpdauth/service/ForgotPasswordsService.java index fb150e5..0e0d19a 100644 --- a/src/main/java/org/waterproofingdata/wpdauth/service/ForgotPasswordService.java +++ b/src/main/java/org/waterproofingdata/wpdauth/service/ForgotPasswordsService.java @@ -10,26 +10,26 @@ import org.springframework.mail.javamail.JavaMailSender; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.waterproofingdata.wpdauth.exception.CustomException; -import org.waterproofingdata.wpdauth.model.ForgotPasswordKeys; -import org.waterproofingdata.wpdauth.model.ForgotPasswordQuestions; -import org.waterproofingdata.wpdauth.model.ForgotPasswordQuestionsUsersAnswers; +import org.waterproofingdata.wpdauth.model.ForgotPasswordsKeys; +import org.waterproofingdata.wpdauth.model.ForgotPasswordsQuestions; +import org.waterproofingdata.wpdauth.model.ForgotPasswordsQuestionsUsersAnswers; import org.waterproofingdata.wpdauth.model.Users; -import org.waterproofingdata.wpdauth.repository.ForgotPasswordKeysRepository; -import org.waterproofingdata.wpdauth.repository.ForgotPasswordQuestionsRepository; -import org.waterproofingdata.wpdauth.repository.ForgotPasswordQuestionsUsersAnswersRepository; +import org.waterproofingdata.wpdauth.repository.ForgotPasswordsKeysRepository; +import org.waterproofingdata.wpdauth.repository.ForgotPasswordsQuestionsRepository; +import org.waterproofingdata.wpdauth.repository.ForgotPasswordsQuestionsUsersAnswersRepository; import org.waterproofingdata.wpdauth.repository.UsersRepository; import org.waterproofingdata.wpdauth.security.JwtTokenProvider; @Service -public class ForgotPasswordService { +public class ForgotPasswordsService { @Autowired - private ForgotPasswordKeysRepository forgotPasswordKeysRepository; + private ForgotPasswordsKeysRepository forgotPasswordsKeysRepository; @Autowired - private ForgotPasswordQuestionsRepository forgotPasswordQuestionsRepository; + private ForgotPasswordsQuestionsRepository forgotPasswordsQuestionsRepository; @Autowired - private ForgotPasswordQuestionsUsersAnswersRepository forgotPasswordQuestionsUsersAnswersRepository; + private ForgotPasswordsQuestionsUsersAnswersRepository forgotPasswordsQuestionsUsersAnswersRepository; @Autowired private UsersRepository usersRepository; @@ -53,10 +53,10 @@ public class ForgotPasswordService { String key = String.format("%04d", rand.nextInt(10000)); //System.out.printf("%04d%n", rand.nextInt(10000)); - ForgotPasswordKeys entity = new ForgotPasswordKeys(); + ForgotPasswordsKeys entity = new ForgotPasswordsKeys(); entity.setEmail(email); entity.setKey(key); - forgotPasswordKeysRepository.save(entity); + forgotPasswordsKeysRepository.save(entity); SimpleMailMessage message = new SimpleMailMessage(); message.setFrom("noreply@wp6.com"); @@ -67,7 +67,7 @@ public class ForgotPasswordService { } public String loginByEmailAndKey(String email, String key) { - ForgotPasswordKeys entity = forgotPasswordKeysRepository.findTodayRecordByEmailANDKey(email, key); + ForgotPasswordsKeys entity = forgotPasswordsKeysRepository.findTodayRecordByEmailANDKey(email, key); if (entity == null) { throw new CustomException("The email and forgot key don't exist", HttpStatus.NOT_FOUND); } @@ -90,12 +90,12 @@ public class ForgotPasswordService { usersRepository.save(user); } - public List findAllForgotPasswordQuestions() { - return forgotPasswordQuestionsRepository.findAll(); + public List findAllForgotPasswordQuestions() { + return forgotPasswordsQuestionsRepository.findAll(); } - public void saveForgotPasswordQuestionsUsersAnswers(ForgotPasswordQuestionsUsersAnswers forgotPasswordQuestionsUsersAnswer) { - if (!forgotPasswordQuestionsRepository.existsById(forgotPasswordQuestionsUsersAnswer.getForgotpasswordquestionsid())) { + public void saveForgotPasswordQuestionsUsersAnswers(ForgotPasswordsQuestionsUsersAnswers forgotPasswordQuestionsUsersAnswer) { + if (!forgotPasswordsQuestionsRepository.existsById(forgotPasswordQuestionsUsersAnswer.getForgotpasswordquestionsid())) { throw new CustomException("The Forgot Password Questions provided doesn't exist", HttpStatus.NOT_FOUND); } @@ -103,18 +103,18 @@ public class ForgotPasswordService { throw new CustomException("The User provided doesn't exist", HttpStatus.NOT_FOUND); } - forgotPasswordQuestionsUsersAnswersRepository.save(forgotPasswordQuestionsUsersAnswer); + forgotPasswordsQuestionsUsersAnswersRepository.save(forgotPasswordQuestionsUsersAnswer); } - public String loginByEmailAndAnswers(String email, List answers) { + public String loginByEmailAndAnswers(String email, List answers) { Users user = usersRepository.findByEmail(email); if (user == null) { throw new CustomException("The user email doesn't exist", HttpStatus.NOT_FOUND); } int correctAnswers = 0; - for (ForgotPasswordQuestionsUsersAnswers answer : answers) { - ForgotPasswordQuestionsUsersAnswers answerComparison = forgotPasswordQuestionsUsersAnswersRepository.findByForgotPasswordQuestionsAndUserid(answer.getForgotpasswordquestionsid(), answer.getUsersid()); + for (ForgotPasswordsQuestionsUsersAnswers answer : answers) { + ForgotPasswordsQuestionsUsersAnswers answerComparison = forgotPasswordsQuestionsUsersAnswersRepository.findByForgotPasswordQuestionsAndUserid(answer.getForgotpasswordquestionsid(), answer.getUsersid()); if (answerComparison == null) { throw new CustomException("The comparison answer doesn't exist", HttpStatus.NOT_FOUND); } diff --git a/src/test/java/org/waterproofingdata/wpdauth/integrationtest/ForgotPasswordServiceIntegrationTest.java b/src/test/java/org/waterproofingdata/wpdauth/integrationtest/ForgotPasswordServiceIntegrationTest.java index 8856206..ef8c3f9 100644 --- a/src/test/java/org/waterproofingdata/wpdauth/integrationtest/ForgotPasswordServiceIntegrationTest.java +++ b/src/test/java/org/waterproofingdata/wpdauth/integrationtest/ForgotPasswordServiceIntegrationTest.java @@ -7,17 +7,17 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.waterproofingdata.wpdauth.model.ForgotPasswordQuestions; -import org.waterproofingdata.wpdauth.service.ForgotPasswordService; +import org.waterproofingdata.wpdauth.model.ForgotPasswordsQuestions; +import org.waterproofingdata.wpdauth.service.ForgotPasswordsService; @SpringBootTest public class ForgotPasswordServiceIntegrationTest { @Autowired - private ForgotPasswordService forgotPasswordService; + private ForgotPasswordsService forgotPasswordService; @Test public void testFindAllForgotPasswordQuestions() { - List r = forgotPasswordService.findAllForgotPasswordQuestions(); + List r = forgotPasswordService.findAllForgotPasswordQuestions(); assertTrue(r.size() > 0); }