-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/local-checkstyle-linter
- Loading branch information
Showing
16 changed files
with
259 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
backend/src/main/java/com/greenfoxacademy/backend/dtos/RegisterResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.greenfoxacademy.backend.dtos; | ||
|
||
|
||
/** | ||
* RegisterResponseDto represents a registration response. | ||
* | ||
* @param id of the created user | ||
* | ||
*/ | ||
|
||
public record RegisterResponseDto( | ||
Integer id | ||
) { | ||
public RegisterResponseDto { | ||
} | ||
} |
13 changes: 11 additions & 2 deletions
13
backend/src/main/java/com/greenfoxacademy/backend/dtos/RegisterUserDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
package com.greenfoxacademy.backend.dtos; | ||
|
||
import com.greenfoxacademy.backend.services.ValidPassword; | ||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
/** | ||
* Data Transfer Object for User Entity. | ||
*/ | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
public class RegisterUserDto { | ||
@NotBlank | ||
private String firstName; | ||
@NotBlank | ||
private String lastName; | ||
private String email; | ||
@ValidPassword | ||
private String password; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
backend/src/main/java/com/greenfoxacademy/backend/services/PasswordConstraintValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.greenfoxacademy.backend.services; | ||
|
||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import java.util.ArrayList; | ||
|
||
|
||
/** | ||
* Custom validator for password field. | ||
*/ | ||
public class PasswordConstraintValidator implements ConstraintValidator<ValidPassword, String> { | ||
|
||
@Override | ||
public boolean isValid(String password, ConstraintValidatorContext constraintValidatorContext) { | ||
if (password == null) { | ||
constraintValidatorContext | ||
.disableDefaultConstraintViolation(); | ||
constraintValidatorContext | ||
.buildConstraintViolationWithTemplate("Password should be added") | ||
.addConstraintViolation(); | ||
return false; | ||
} | ||
boolean isValid = true; | ||
ArrayList<String> errorMessages = new ArrayList<>(); | ||
if (password.length() < 8) { | ||
errorMessages.add("must be at least 8 characters long"); | ||
isValid = false; | ||
} | ||
if (password.matches(".*\\s.*")) { | ||
errorMessages.add("must not contain whitespace"); | ||
isValid = false; | ||
} | ||
if (!password.matches(".*\\d.*")) { | ||
errorMessages.add("must contain at least one digit"); | ||
isValid = false; | ||
} | ||
if (!password.matches(".*[A-Z].*")) { | ||
errorMessages.add("must contain at least one uppercase letter"); | ||
isValid = false; | ||
} | ||
if (!password.matches(".*[a-z].*")) { | ||
errorMessages.add("must contain at least one lowercase letter"); | ||
isValid = false; | ||
} | ||
if (!isValid) { | ||
constraintValidatorContext.disableDefaultConstraintViolation(); | ||
constraintValidatorContext | ||
.buildConstraintViolationWithTemplate( | ||
"Invalid password: " + String.join(", ", errorMessages) | ||
) | ||
.addConstraintViolation(); | ||
} | ||
return isValid; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
backend/src/main/java/com/greenfoxacademy/backend/services/ValidPassword.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.greenfoxacademy.backend.services; | ||
|
||
|
||
import static java.lang.annotation.ElementType.ANNOTATION_TYPE; | ||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* ValidPassword annotation to mark a field as a password which should be validated. | ||
*/ | ||
@Documented | ||
@Constraint (validatedBy = PasswordConstraintValidator.class) | ||
@Target ({TYPE, FIELD, ANNOTATION_TYPE}) | ||
@Retention(RUNTIME) | ||
public @interface ValidPassword { | ||
|
||
/** | ||
* Message to be displayed when the password is invalid. | ||
*/ | ||
String message() default "Invalid Password"; | ||
|
||
/** | ||
* Groups. | ||
*/ | ||
Class<?>[] groups() default {}; | ||
|
||
/** | ||
* Payload. | ||
*/ | ||
Class<? extends Payload>[] payload() default {}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,4 @@ | |
"typescript": "^5.2.2", | ||
"vite": "^5.2.0" | ||
} | ||
} | ||
} |
Oops, something went wrong.