Email field for User

This commit is contained in:
MathewFrancis 2025-05-14 14:52:49 +05:30
parent cb53ca38e5
commit a1f542d0ca
19 changed files with 34 additions and 14 deletions

View File

@ -79,6 +79,8 @@ CREATE TABLE `user`(
CONSTRAINT `user_table_pk` PRIMARY KEY(`u_id`)
)ENGINE = 'Innodb', AUTO_INCREMENT = 1, DEFAULT CHARSET 'latin1';
ALTER TABLE `user` ADD COLUMN `user_email_id` VARCHAR(50) UNIQUE NOT NULL;
ALTER TABLE `user_roles` ADD CONSTRAINT `user_lones_U_fk_to_user` FOREIGN KEY(`u_id`) REFERENCES `user`(`u_id`);
ALTER TABLE `user_roles` ADD CONSTRAINT `user_lones_R_fk_to_user` FOREIGN KEY(`role_id`) REFERENCES `roles`(`role_id`);
@ -92,7 +94,7 @@ SELECT * FROM `user_roles`;
SELECT * FROM `roles`;
DELETE FROM `user` WHERE `user_name` = 'Mathew Francis';
DELETE FROM `user_roles` WHERE `u_id` = 9;
DELETE FROM `user_roles` WHERE `u_id` = (SELECT `u_id` FROM `user_roles` LIMIT 1);
DELETE FROM `roles` WHERE `roles`.`role_name` = 'ROLE_admin'

View File

@ -1,12 +1,9 @@
3,51
1,53
3,50
1,52
2,47
1,51
3,49
2,46
1,50
19,5
19,4
19,3
19,2
19,1
19,0
18,4
18,3
18,2
@ -175,11 +172,14 @@
3,8
2,8
1,8
3,49
3,7
2,7
1,7
3,6
2,46
2,6
1,50
1,6
3,5
2,5

View File

@ -1,5 +1,6 @@
package com.example.cezenPBX.DTO.user;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
@ -7,6 +8,9 @@ public record AdminSetPasswordDTO(
@NotBlank(message = "Username cannot be blank")
String userName,
@Email(message = "Email is not valid")
String email,
@NotBlank(message = "Password cannot be blank")
@Size(min = 8, message = "Password must be at least 8 characters long")
String password,

View File

@ -24,7 +24,8 @@ public class SignUpController {
return this.pbxUserService.adminSetUserNamePasswordSet(
adminSetPasswordDTO.userName(),
adminSetPasswordDTO.password(),
adminSetPasswordDTO.confirmPassword()
adminSetPasswordDTO.confirmPassword(),
adminSetPasswordDTO.email()
);
}

View File

@ -22,6 +22,9 @@ final public class UserEntity {
@Column(name = "password")
private String password;
@Column(name = "user_email_id")
private String email;
//ROLE
@ManyToMany(
fetch = FetchType.LAZY,
@ -44,10 +47,12 @@ final public class UserEntity {
public UserEntity(){}
public UserEntity(String userName, String password) {
public UserEntity(String userName, String password, String email) {
this.userName = userName;
this.password = password;
this.email = email;
}
public int getId() {
return id;
}
@ -67,6 +72,14 @@ final public class UserEntity {
return roles;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public void setARole(Role role){
if(this.roles == null){
this.roles = new HashSet<Role>();

View File

@ -22,13 +22,13 @@ public class PbxUserService {
// must perform the sanity checks before being set to the database
// method will return a faulty return status if the damin exists
public ReturnStatus adminSetUserNamePasswordSet(String userName, String password, String confirmPassword){
public ReturnStatus adminSetUserNamePasswordSet(String userName, String password, String confirmPassword, String email){
// password will be checked here
if(!password.equals(confirmPassword)){
return new ReturnStatus(false, "Passwords do not match", "Passwords do not match");
}
// password encryption
UserEntity userEntity = new UserEntity(userName, "{bcrypt}"+passwordEncoder.encode(password));
UserEntity userEntity = new UserEntity(userName, "{bcrypt}"+passwordEncoder.encode(password), email);
// commit the username and password to the database
return userOpsDAO.adminSetPasswordToDb(userEntity);