Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ class UserController : BasicController() {
fun createUser(name: String, email: String, password: String): Uni<UserEntity> {
val user: User = createUC.createUser(name, email, password)
val entity: UserEntity = mapper.map(user, UserEntity::class.java)
// Allow the ID to be null for auto-generation by the database
entity.id = null
return userRepository.createUser(entity)
.onItem().ifNotNull().transform { u -> u }
.onItem().ifNotNull().call { user -> this.sendValidationEmail(user) }
Expand Down Expand Up @@ -133,7 +135,9 @@ class UserController : BasicController() {
// generates a JWT
return userRepository.authenticate(entity)
.onItem().ifNotNull()
.transform { this.generateJWT(it) }
.transform {
this.generateJWT(it)
}
}

/**
Expand Down Expand Up @@ -168,7 +172,6 @@ class UserController : BasicController() {
response.authentication = dto
response.requires2FA = false
}

response
}
}
Expand Down Expand Up @@ -236,6 +239,8 @@ class UserController : BasicController() {
// User doesn't exist, create it
// Generate a secure password (user won't use it, but DB requires it)
entity.password = DigestUtils.sha256Hex(UUID.randomUUID().toString())
// Garantir que o ID seja null para permitir geração automática pelo banco
entity.id = null
userRepository.createUser(entity)
.onItem().ifNotNull().transform { newUser ->
val response = LoginResponseDTO()
Expand Down Expand Up @@ -813,4 +818,3 @@ class UserController : BasicController() {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.JoinTable
Expand All @@ -45,7 +46,7 @@ class UserEntity : PanacheEntityBase() {

/** Primary key. */
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonIgnore
var id: Long? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ class UserRepositoryImpl @Inject constructor(
.failWith(IOException("Role not found"))
.onItem().ifNotNull()
.transformToUni { role ->
// Allow the ID to be null for auto-generation by the database
user.id = null
user.addRole(role)
Panache.withTransaction { user.persist() }
.onItem().transform { user }
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/import.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ INSERT INTO Role (id, name) VALUES (2, 'user');
INSERT INTO User (id, hash, name, email, password, emailValid, emailValidationCode, isUsing2FA, secret2FA, require2FAForBasicLogin, require2FAForSocialLogin)
VALUES (1, '00000000-0000-0000-0000-000000000001', 'Administrator', 'admin@orion.dev', '24febcc27e4a5762911a4481a941a3563cc4bf5e5f61f0ea3799333871d2a89b', true, '00000000-0000-0000-0000-000000000001', false, NULL, false, false);

-- Associar roles ao usuário admin (admin e user)
-- A tabela de junção está definida explicitamente na entidade UserEntity como "User_Role"
-- Associate roles to admin user (admin and user)
-- The junction table is explicitly defined in the UserEntity as "User_Role"
INSERT INTO User_Role (User_id, roles_id) VALUES (1, 1); -- admin
INSERT INTO User_Role (User_id, roles_id) VALUES (1, 2); -- user

-- Update the auto-increment of the User table to avoid primary key conflict
-- This ensures that the next automatically generated ID will be 2
ALTER TABLE User AUTO_INCREMENT = 2;
Loading