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 f20fbbd..64390c2 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 23b2c8c..2a1b591 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 8132071..24052fa 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 deb1e1a..6df4624 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 ddf0da7..d157d77 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 73ecd9c..3c7fc0a 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);