use of com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO in project AuthGuard by AuthGuard.
the class PasswordResetRequestValidatorTest method validateValidByPassword.
@Test
void validateValidByPassword() {
final PasswordResetRequestDTO request = PasswordResetRequestDTO.builder().byToken(false).identifier("identifier").oldPassword("oldPassword").newPassword("newPassword").domain("main").build();
final Validator<PasswordResetRequestDTO> validator = Validators.getForClass(PasswordResetRequestDTO.class);
final List<Violation> violations = validator.validate(request);
assertThat(violations).isEmpty();
}
use of com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO in project AuthGuard by AuthGuard.
the class PasswordResetRequestValidatorTest method validateMissingTokenAndNewPassword.
@Test
void validateMissingTokenAndNewPassword() {
final PasswordResetRequestDTO request = PasswordResetRequestDTO.builder().byToken(true).build();
final Validator<PasswordResetRequestDTO> validator = Validators.getForClass(PasswordResetRequestDTO.class);
final List<Violation> violations = validator.validate(request);
assertThat(violations).contains(new Violation("resetToken", ViolationType.MISSING_REQUIRED_VALUE));
assertThat(violations).contains(new Violation("newPassword", ViolationType.MISSING_REQUIRED_VALUE));
}
use of com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO in project AuthGuard by AuthGuard.
the class PasswordResetRequestValidatorTest method validateValidByToken.
@Test
void validateValidByToken() {
final PasswordResetRequestDTO request = PasswordResetRequestDTO.builder().byToken(true).resetToken("token").newPassword("newPassword").build();
final Validator<PasswordResetRequestDTO> validator = Validators.getForClass(PasswordResetRequestDTO.class);
final List<Violation> violations = validator.validate(request);
assertThat(violations).isEmpty();
}
use of com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO in project AuthGuard by AuthGuard.
the class PasswordResetRequestValidatorTest method validateMissingIdentifierAndOldPassword.
@Test
void validateMissingIdentifierAndOldPassword() {
final PasswordResetRequestDTO request = PasswordResetRequestDTO.builder().byToken(false).build();
final Validator<PasswordResetRequestDTO> validator = Validators.getForClass(PasswordResetRequestDTO.class);
final List<Violation> violations = validator.validate(request);
assertThat(violations).contains(new Violation("identifier", ViolationType.MISSING_REQUIRED_VALUE));
assertThat(violations).contains(new Violation("oldPassword", ViolationType.MISSING_REQUIRED_VALUE));
assertThat(violations).contains(new Violation("newPassword", ViolationType.MISSING_REQUIRED_VALUE));
}
use of com.nexblocks.authguard.api.dto.requests.PasswordResetRequestDTO in project AuthGuard by AuthGuard.
the class CredentialsRoute method resetPassword.
@Override
public void resetPassword(final Context context) {
final PasswordResetRequestDTO request = passwordResetRequestBodyHandler.getValidated(context);
if (request.getIdentifier() != null && !ActorDomainVerifier.verifyActorDomain(context, request.getDomain())) {
return;
}
final Optional<CredentialsBO> updated;
if (request.isByToken()) {
updated = credentialsService.resetPasswordByToken(request.getResetToken(), request.getNewPassword());
} else {
updated = credentialsService.replacePassword(request.getIdentifier(), request.getOldPassword(), request.getNewPassword(), request.getDomain());
}
if (updated.isPresent()) {
context.status(200).json(updated.get());
} else {
context.status(404);
}
}
Aggregations