From e0d2d6c6b706208595f145476cfe9daf54e12635 Mon Sep 17 00:00:00 2001 From: MenekseYuncu Date: Fri, 25 Oct 2024 23:24:00 +0300 Subject: [PATCH 1/8] GBS-55 | username added to database --- src/main/resources/db/migration/V1__ddl.sql | 1 + src/main/resources/db/migration/V2__dml.sql | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/resources/db/migration/V1__ddl.sql b/src/main/resources/db/migration/V1__ddl.sql index 1c011656..ddf0da71 100644 --- a/src/main/resources/db/migration/V1__ddl.sql +++ b/src/main/resources/db/migration/V1__ddl.sql @@ -47,6 +47,7 @@ create table if not exists gb_user password varchar(255) not null, first_name varchar(25) not null, last_name varchar(25) not null, + username varchar(20) not null unique, avatar_path varchar(255), biography text, birth_date date, diff --git a/src/main/resources/db/migration/V2__dml.sql b/src/main/resources/db/migration/V2__dml.sql index c92fdf86..73ecd9c9 100644 --- a/src/main/resources/db/migration/V2__dml.sql +++ b/src/main/resources/db/migration/V2__dml.sql @@ -274,30 +274,30 @@ values (0, null, 'Bilim', 'Bilim kategorisidir.', 'bilim', 'flask-conical', 'gelecekbilimde', current_timestamp); -insert into gb_user (id, birth_date, email, gender, first_name, last_name, password, +insert into gb_user (id, birth_date, email, gender, first_name, last_name, username, password, status, role_id, created_by, created_at) values ('22afc9b4-807f-4eb2-b286-788631d1ed55', current_date, 'admin@gelecekbilimde.net', - 'FEMALE', 'Test', 'Yönetici', + 'FEMALE', 'Test', 'Yönetici', 'yönetici12', '$2a$10$atVE.cT5YpEOS7ZLSoVdk.QKVyYBCgvNhvQEuCcXbEMpohYIjbZDG', 'VERIFIED', 'c147b5c2-87f7-4bb7-a165-368f639d8c3c', 'gelecekbilimde', current_timestamp); -insert into gb_user (id, birth_date, email, gender, first_name, last_name, password, +insert into gb_user (id, birth_date, email, gender, first_name, last_name, username, password, status, role_id, created_by, created_at) values ('99af408c-bec9-4cf2-a5ea-218b12b88a50', current_date, 'moderator@gelecekbilimde.net', - 'FEMALE', 'Test', 'Moderatör', + 'FEMALE', 'Test', 'Moderatör', 'moderatör12', '$2a$10$atVE.cT5YpEOS7ZLSoVdk.QKVyYBCgvNhvQEuCcXbEMpohYIjbZDG', 'VERIFIED', '1ed82a25-d348-4576-b4e6-1f2a7c430ca7', 'gelecekbilimde', current_timestamp); -insert into gb_user (id, birth_date, email, gender, first_name, last_name, password, +insert into gb_user (id, birth_date, email, gender, first_name, last_name, username, password, status, role_id, created_by, created_at) values ('fee95298-952d-4d1c-81dd-ae5a96b964e5', current_date, 'author@gelecekbilimde.net', - 'MALE', 'Test', 'Yazar', + 'MALE', 'Test', 'Yazar', 'yazar12', '$2a$10$atVE.cT5YpEOS7ZLSoVdk.QKVyYBCgvNhvQEuCcXbEMpohYIjbZDG', 'VERIFIED', '4d98a76c-9841-4aea-b296-2f27aa610b6c', 'gelecekbilimde', current_timestamp); -insert into gb_user (id, birth_date, email, gender, first_name, last_name, password, +insert into gb_user (id, birth_date, email, gender, first_name, last_name, username, password, status, role_id, created_by, created_at) values ('233d4054-e7b9-43ba-8b26-ca9254df78cd', current_date, 'user@gelecekbilimde.net', - 'MALE', 'Test', 'Kullanıcı', + 'MALE', 'Test', 'Kullanıcı', 'kullanıcı12', '$2a$10$atVE.cT5YpEOS7ZLSoVdk.QKVyYBCgvNhvQEuCcXbEMpohYIjbZDG', 'VERIFIED', 'e3a1a32d-fcd7-46f0-bb2b-201df6b2b808', 'gelecekbilimde', current_timestamp); From f7fd8bcc094c3ad1ddb973dc4ea3221a09a380b7 Mon Sep 17 00:00:00 2001 From: MenekseYuncu Date: Fri, 25 Oct 2024 23:24:45 +0300 Subject: [PATCH 2/8] GBS-55 | username validation created --- .../auth/model/request/RegisterRequest.java | 5 +++ .../common/util/validation/Username.java | 22 ++++++++++++ .../util/validation/UsernameValidator.java | 35 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/Username.java create mode 100644 src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java b/src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java index 56a8e1df..f20fbbd2 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java @@ -8,6 +8,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.gelecekbilimde.scienceplatform.common.util.validation.Username; import org.gelecekbilimde.scienceplatform.user.model.enums.UserDegree; import org.gelecekbilimde.scienceplatform.user.model.enums.UserGender; @@ -28,6 +29,10 @@ public class RegisterRequest { @Size(min = 2, max = 25) private String lastname; + @NotBlank + @Username + private String username; + @NotBlank @Email @Size(min = 8, max = 255) diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/Username.java b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/Username.java new file mode 100644 index 00000000..37179f9d --- /dev/null +++ b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/Username.java @@ -0,0 +1,22 @@ +package org.gelecekbilimde.scienceplatform.common.util.validation; + +import jakarta.validation.Constraint; +import jakarta.validation.Payload; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(value = ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Constraint(validatedBy = UsernameValidator.class) +public @interface Username { + + String message() default "must be valid"; + + Class[] groups() default {}; + + Class[] payload() default {}; + +} diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java new file mode 100644 index 00000000..ecb1c7c6 --- /dev/null +++ b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java @@ -0,0 +1,35 @@ +package org.gelecekbilimde.scienceplatform.common.util.validation; + +import jakarta.validation.ConstraintValidator; +import jakarta.validation.ConstraintValidatorContext; +import org.springframework.util.StringUtils; + +class UsernameValidator implements ConstraintValidator { + + private static final String USERNAME_REGEX = "^[a-zA-Z0-9]{3,20}$"; + + @Override + public boolean isValid(String value, ConstraintValidatorContext context) { + if (!StringUtils.hasText(value)) { + return true; + } + + String lowerCasedValue = value.toLowerCase(); + + if (value.startsWith(" ") || value.endsWith(" ")) { + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate("name must not start or end with whitespace") + .addConstraintViolation(); + return false; + } + + if (!lowerCasedValue.matches(USERNAME_REGEX)) { + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate("Username must be 3-20 characters long and alphanumeric") + .addConstraintViolation(); + return false; + } + + return true; + } +} From 3cc6f0442719f4c5c5832c8dd1e0737356970823 Mon Sep 17 00:00:00 2001 From: MenekseYuncu Date: Fri, 25 Oct 2024 23:25:58 +0300 Subject: [PATCH 3/8] GBS-55 | username added --- .../service/impl/RegistrationServiceImpl.java | 6 ++++++ .../exception/UsernameAlreadyTakenException.java | 16 ++++++++++++++++ .../scienceplatform/user/model/User.java | 6 ++++++ .../user/model/entity/UserEntity.java | 3 +++ .../scienceplatform/user/port/UserReadPort.java | 1 + .../user/port/adapter/UserAdapter.java | 6 ++++++ .../user/repository/UserRepository.java | 2 ++ 7 files changed, 40 insertions(+) create mode 100644 src/main/java/org/gelecekbilimde/scienceplatform/user/exception/UsernameAlreadyTakenException.java diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/auth/service/impl/RegistrationServiceImpl.java b/src/main/java/org/gelecekbilimde/scienceplatform/auth/service/impl/RegistrationServiceImpl.java index 89663df3..23b2c8c6 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/auth/service/impl/RegistrationServiceImpl.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/auth/service/impl/RegistrationServiceImpl.java @@ -12,6 +12,7 @@ import org.gelecekbilimde.scienceplatform.auth.model.request.VerifyRequest; import org.gelecekbilimde.scienceplatform.auth.port.RoleReadPort; import org.gelecekbilimde.scienceplatform.auth.service.RegistrationService; +import org.gelecekbilimde.scienceplatform.user.exception.UsernameAlreadyTakenException; import org.gelecekbilimde.scienceplatform.user.model.User; import org.gelecekbilimde.scienceplatform.user.model.UserVerification; import org.gelecekbilimde.scienceplatform.user.model.enums.UserStatus; @@ -48,9 +49,14 @@ public void register(RegisterRequest request) { Role role = roleReadPort.findByName(RoleName.USER) .orElseThrow(() -> new RoleNotFoundByNameException(RoleName.USER.name())); + if (userReadPort.existsByUsername(request.getUsername())) { + throw new UsernameAlreadyTakenException(request.getUsername()); + } + User user = User.builder() .firstName(request.getFirstname()) .lastName(request.getLastname()) + .username(request.getUsername()) .email(request.getEmail()) .birthDate(request.getBirthDate()) .biography(request.getBiography()) diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/user/exception/UsernameAlreadyTakenException.java b/src/main/java/org/gelecekbilimde/scienceplatform/user/exception/UsernameAlreadyTakenException.java new file mode 100644 index 00000000..a8fea786 --- /dev/null +++ b/src/main/java/org/gelecekbilimde/scienceplatform/user/exception/UsernameAlreadyTakenException.java @@ -0,0 +1,16 @@ +package org.gelecekbilimde.scienceplatform.user.exception; + +import org.gelecekbilimde.scienceplatform.common.exception.AbstractServerException; + +import java.io.Serial; + +public final class UsernameAlreadyTakenException extends AbstractServerException { + + @Serial + private static final long serialVersionUID = -3365493595680402581L; + + public UsernameAlreadyTakenException(String username) { + super(("username is already taken" + username)); + } + +} diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java b/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java index 1cdd862c..2ef1c872 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java @@ -23,6 +23,7 @@ public class User extends BaseDomainModel { private String password; private String firstName; private String lastName; + private String username; private String avatarPath; private String biography; private LocalDate birthDate; @@ -32,6 +33,11 @@ public class User extends BaseDomainModel { private Role role; + public String getUsername() { + return username.toLowerCase(); + } + + public boolean isVerified() { return this.status == UserStatus.VERIFIED; } diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/user/model/entity/UserEntity.java b/src/main/java/org/gelecekbilimde/scienceplatform/user/model/entity/UserEntity.java index 9c19af83..1c80f586 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/user/model/entity/UserEntity.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/user/model/entity/UserEntity.java @@ -56,6 +56,9 @@ public class UserEntity extends BaseEntity { @Column(name = "last_name") private String lastName; + @Column(name = "username") + private String username; + @Column(name = "avatar_path") private String avatar; diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/user/port/UserReadPort.java b/src/main/java/org/gelecekbilimde/scienceplatform/user/port/UserReadPort.java index d39ebedb..d6b4e55a 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/user/port/UserReadPort.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/user/port/UserReadPort.java @@ -12,4 +12,5 @@ public interface UserReadPort { boolean existsByEmail(String email); + boolean existsByUsername(String username); } diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/user/port/adapter/UserAdapter.java b/src/main/java/org/gelecekbilimde/scienceplatform/user/port/adapter/UserAdapter.java index 65a3d573..8a535781 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/user/port/adapter/UserAdapter.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/user/port/adapter/UserAdapter.java @@ -43,6 +43,12 @@ public boolean existsByEmail(final String email) { } + @Override + public boolean existsByUsername(String username) { + return userRepository.existsByUsername(username); + } + + @Override public User save(User user) { final UserEntity userEntity = userToEntityMapper.map(user); diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/user/repository/UserRepository.java b/src/main/java/org/gelecekbilimde/scienceplatform/user/repository/UserRepository.java index fdf72375..635b76e8 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/user/repository/UserRepository.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/user/repository/UserRepository.java @@ -10,4 +10,6 @@ public interface UserRepository extends JpaRepository { Optional findByEmail(String email); boolean existsByEmail(String email); + + boolean existsByUsername(String username); } From 223d60a9a12968d4eea260b6969146070e3a8878 Mon Sep 17 00:00:00 2001 From: MenekseYuncu Date: Fri, 25 Oct 2024 23:54:14 +0300 Subject: [PATCH 4/8] GBS-55 | fixed --- .../common/util/validation/UsernameValidator.java | 2 +- .../user/exception/UsernameAlreadyTakenException.java | 6 +++--- .../org/gelecekbilimde/scienceplatform/user/model/User.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java index ecb1c7c6..8132071d 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java @@ -16,7 +16,7 @@ public boolean isValid(String value, ConstraintValidatorContext context) { String lowerCasedValue = value.toLowerCase(); - if (value.startsWith(" ") || value.endsWith(" ")) { + if (!value.trim().equals(value)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("name must not start or end with whitespace") .addConstraintViolation(); diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/user/exception/UsernameAlreadyTakenException.java b/src/main/java/org/gelecekbilimde/scienceplatform/user/exception/UsernameAlreadyTakenException.java index a8fea786..1f243c0d 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/user/exception/UsernameAlreadyTakenException.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/user/exception/UsernameAlreadyTakenException.java @@ -1,16 +1,16 @@ package org.gelecekbilimde.scienceplatform.user.exception; -import org.gelecekbilimde.scienceplatform.common.exception.AbstractServerException; +import org.gelecekbilimde.scienceplatform.common.exception.AbstractConflictException; import java.io.Serial; -public final class UsernameAlreadyTakenException extends AbstractServerException { +public final class UsernameAlreadyTakenException extends AbstractConflictException { @Serial private static final long serialVersionUID = -3365493595680402581L; public UsernameAlreadyTakenException(String username) { - super(("username is already taken" + username)); + super(String.format("'%s' username already taken", username)); } } diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java b/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java index 2ef1c872..deb1e1a6 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java @@ -34,7 +34,7 @@ public class User extends BaseDomainModel { public String getUsername() { - return username.toLowerCase(); + return username != null ? username.toLowerCase() : null; } From 346f64c6e7e6425fa4bcdc646079470f87f75503 Mon Sep 17 00:00:00 2001 From: MenekseYuncu Date: Sat, 26 Oct 2024 12:39:24 +0300 Subject: [PATCH 5/8] GBS-55 | conversation resolved --- .../auth/model/request/RegisterRequest.java | 1 + .../auth/service/impl/RegistrationServiceImpl.java | 2 +- .../common/util/validation/UsernameValidator.java | 4 ++-- .../gelecekbilimde/scienceplatform/user/model/User.java | 5 ----- src/main/resources/db/migration/V1__ddl.sql | 2 +- src/main/resources/db/migration/V2__dml.sql | 8 ++++---- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java b/src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java index f20fbbd2..64390c2d 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java @@ -31,6 +31,7 @@ public class RegisterRequest { @NotBlank @Username + @Size(min = 3, max = 20) private String username; @NotBlank diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/auth/service/impl/RegistrationServiceImpl.java b/src/main/java/org/gelecekbilimde/scienceplatform/auth/service/impl/RegistrationServiceImpl.java index 23b2c8c6..2a1b5912 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/auth/service/impl/RegistrationServiceImpl.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/auth/service/impl/RegistrationServiceImpl.java @@ -56,7 +56,7 @@ public void register(RegisterRequest request) { User user = User.builder() .firstName(request.getFirstname()) .lastName(request.getLastname()) - .username(request.getUsername()) + .username(request.getUsername().toLowerCase()) .email(request.getEmail()) .birthDate(request.getBirthDate()) .biography(request.getBiography()) diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java index 8132071d..24052faa 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java @@ -6,7 +6,7 @@ class UsernameValidator implements ConstraintValidator { - private static final String USERNAME_REGEX = "^[a-zA-Z0-9]{3,20}$"; + private static final String USERNAME_REGEX = "^[a-zA-Z0-9]$"; @Override public boolean isValid(String value, ConstraintValidatorContext context) { @@ -25,7 +25,7 @@ public boolean isValid(String value, ConstraintValidatorContext context) { if (!lowerCasedValue.matches(USERNAME_REGEX)) { context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate("Username must be 3-20 characters long and alphanumeric") + context.buildConstraintViolationWithTemplate("Username must be alphanumeric") .addConstraintViolation(); return false; } diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java b/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java index deb1e1a6..6df46240 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/user/model/User.java @@ -33,11 +33,6 @@ public class User extends BaseDomainModel { private Role role; - public String getUsername() { - return username != null ? username.toLowerCase() : null; - } - - public boolean isVerified() { return this.status == UserStatus.VERIFIED; } diff --git a/src/main/resources/db/migration/V1__ddl.sql b/src/main/resources/db/migration/V1__ddl.sql index ddf0da71..d157d778 100644 --- a/src/main/resources/db/migration/V1__ddl.sql +++ b/src/main/resources/db/migration/V1__ddl.sql @@ -43,7 +43,7 @@ create table if not exists gb_user ( id varchar(36) not null primary key, role_id varchar(36) not null, - email varchar(255) not null, + email varchar(255) not null unique, password varchar(255) not null, first_name varchar(25) not null, last_name varchar(25) not null, diff --git a/src/main/resources/db/migration/V2__dml.sql b/src/main/resources/db/migration/V2__dml.sql index 73ecd9c9..3c7fc0a4 100644 --- a/src/main/resources/db/migration/V2__dml.sql +++ b/src/main/resources/db/migration/V2__dml.sql @@ -277,27 +277,27 @@ values (0, null, 'Bilim', 'Bilim kategorisidir.', 'bilim', 'flask-conical', insert into gb_user (id, birth_date, email, gender, first_name, last_name, username, password, status, role_id, created_by, created_at) values ('22afc9b4-807f-4eb2-b286-788631d1ed55', current_date, 'admin@gelecekbilimde.net', - 'FEMALE', 'Test', 'Yönetici', 'yönetici12', + 'FEMALE', 'Test', 'Yönetici', ' administrator12', '$2a$10$atVE.cT5YpEOS7ZLSoVdk.QKVyYBCgvNhvQEuCcXbEMpohYIjbZDG', 'VERIFIED', 'c147b5c2-87f7-4bb7-a165-368f639d8c3c', 'gelecekbilimde', current_timestamp); insert into gb_user (id, birth_date, email, gender, first_name, last_name, username, password, status, role_id, created_by, created_at) values ('99af408c-bec9-4cf2-a5ea-218b12b88a50', current_date, 'moderator@gelecekbilimde.net', - 'FEMALE', 'Test', 'Moderatör', 'moderatör12', + 'FEMALE', 'Test', 'Moderatör', 'moderator12', '$2a$10$atVE.cT5YpEOS7ZLSoVdk.QKVyYBCgvNhvQEuCcXbEMpohYIjbZDG', 'VERIFIED', '1ed82a25-d348-4576-b4e6-1f2a7c430ca7', 'gelecekbilimde', current_timestamp); insert into gb_user (id, birth_date, email, gender, first_name, last_name, username, password, status, role_id, created_by, created_at) values ('fee95298-952d-4d1c-81dd-ae5a96b964e5', current_date, 'author@gelecekbilimde.net', - 'MALE', 'Test', 'Yazar', 'yazar12', + 'MALE', 'Test', 'Yazar', 'author12', '$2a$10$atVE.cT5YpEOS7ZLSoVdk.QKVyYBCgvNhvQEuCcXbEMpohYIjbZDG', 'VERIFIED', '4d98a76c-9841-4aea-b296-2f27aa610b6c', 'gelecekbilimde', current_timestamp); insert into gb_user (id, birth_date, email, gender, first_name, last_name, username, password, status, role_id, created_by, created_at) values ('233d4054-e7b9-43ba-8b26-ca9254df78cd', current_date, 'user@gelecekbilimde.net', - 'MALE', 'Test', 'Kullanıcı', 'kullanıcı12', + 'MALE', 'Test', 'Kullanıcı', 'users12', '$2a$10$atVE.cT5YpEOS7ZLSoVdk.QKVyYBCgvNhvQEuCcXbEMpohYIjbZDG', 'VERIFIED', 'e3a1a32d-fcd7-46f0-bb2b-201df6b2b808', 'gelecekbilimde', current_timestamp); From 77524e1382088f686561dc44e4f81294e88177b3 Mon Sep 17 00:00:00 2001 From: MenekseYuncu Date: Sat, 26 Oct 2024 13:18:14 +0300 Subject: [PATCH 6/8] GBS-55 | conversation resolved --- src/main/resources/db/migration/V2__dml.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/db/migration/V2__dml.sql b/src/main/resources/db/migration/V2__dml.sql index 3c7fc0a4..a3002e50 100644 --- a/src/main/resources/db/migration/V2__dml.sql +++ b/src/main/resources/db/migration/V2__dml.sql @@ -277,7 +277,7 @@ values (0, null, 'Bilim', 'Bilim kategorisidir.', 'bilim', 'flask-conical', insert into gb_user (id, birth_date, email, gender, first_name, last_name, username, password, status, role_id, created_by, created_at) values ('22afc9b4-807f-4eb2-b286-788631d1ed55', current_date, 'admin@gelecekbilimde.net', - 'FEMALE', 'Test', 'Yönetici', ' administrator12', + 'FEMALE', 'Test', 'Yönetici', 'administrator12', '$2a$10$atVE.cT5YpEOS7ZLSoVdk.QKVyYBCgvNhvQEuCcXbEMpohYIjbZDG', 'VERIFIED', 'c147b5c2-87f7-4bb7-a165-368f639d8c3c', 'gelecekbilimde', current_timestamp); From 050447b5d559ca91fdf63bcd12154a0d79ebcb50 Mon Sep 17 00:00:00 2001 From: MenekseYuncu Date: Sun, 27 Oct 2024 11:51:48 +0300 Subject: [PATCH 7/8] GBS-55 | The size conversation resolved --- .../auth/model/request/RegisterRequest.java | 1 - .../common/util/validation/UsernameValidator.java | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java b/src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java index 64390c2d..f20fbbd2 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/auth/model/request/RegisterRequest.java @@ -31,7 +31,6 @@ public class RegisterRequest { @NotBlank @Username - @Size(min = 3, max = 20) private String username; @NotBlank diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java index 24052faa..dfc76a3c 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java @@ -6,7 +6,7 @@ class UsernameValidator implements ConstraintValidator { - private static final String USERNAME_REGEX = "^[a-zA-Z0-9]$"; + private static final String USERNAME_REGEX = "^[a-zA-Z0-9]{3,20}$"; @Override public boolean isValid(String value, ConstraintValidatorContext context) { @@ -23,6 +23,13 @@ public boolean isValid(String value, ConstraintValidatorContext context) { return false; } + if (value.length() <= 3 || value.length() >= 20) { + context.disableDefaultConstraintViolation(); + context.buildConstraintViolationWithTemplate("Username must be between 3 and 20 characters long") + .addConstraintViolation(); + return false; + } + if (!lowerCasedValue.matches(USERNAME_REGEX)) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate("Username must be alphanumeric") From 4c51f2dd6dca073c5273cb9d28247f93171d86fd Mon Sep 17 00:00:00 2001 From: MenekseYuncu Date: Sun, 27 Oct 2024 22:08:53 +0300 Subject: [PATCH 8/8] The size conversation resolved --- .../common/util/validation/UsernameValidator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java index dfc76a3c..8b2958bc 100644 --- a/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java +++ b/src/main/java/org/gelecekbilimde/scienceplatform/common/util/validation/UsernameValidator.java @@ -25,14 +25,14 @@ public boolean isValid(String value, ConstraintValidatorContext context) { if (value.length() <= 3 || value.length() >= 20) { context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate("Username must be between 3 and 20 characters long") + context.buildConstraintViolationWithTemplate("must be between 3 and 20 characters long") .addConstraintViolation(); return false; } if (!lowerCasedValue.matches(USERNAME_REGEX)) { context.disableDefaultConstraintViolation(); - context.buildConstraintViolationWithTemplate("Username must be alphanumeric") + context.buildConstraintViolationWithTemplate("must be alphanumeric") .addConstraintViolation(); return false; }