mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 16:20:04 +00:00
Use PhosphorIcons instead of FontAwesome
Start implementation of setup process
This commit is contained in:
@@ -32,14 +32,20 @@ class SetupDataLoader(
|
||||
}
|
||||
|
||||
fun setupUsers() {
|
||||
val superadmin = User("admin")
|
||||
superadmin.password = "admin"
|
||||
superadmin.roles = listOf(roleRepository.findByRolename(Roles.SUPERADMIN.roleName)!!)
|
||||
val superadmin = User(
|
||||
username = "admin",
|
||||
password = "admin",
|
||||
roles = listOf(roleRepository.findByRolename(Roles.SUPERADMIN.roleName)!!)
|
||||
)
|
||||
|
||||
userService.registerUser(superadmin)
|
||||
|
||||
val user = User("user")
|
||||
user.password = "user"
|
||||
user.roles = listOf(roleRepository.findByRolename(Roles.USER.roleName)!!)
|
||||
val user = User(
|
||||
username = "user",
|
||||
password = "user",
|
||||
roles = listOf(roleRepository.findByRolename(Roles.USER.roleName)!!)
|
||||
)
|
||||
|
||||
userService.registerUser(user)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package de.grimsi.gameyfin.users
|
||||
|
||||
import de.grimsi.gameyfin.users.dto.UserInfo
|
||||
import de.grimsi.gameyfin.users.dto.UserRegistration
|
||||
import de.grimsi.gameyfin.users.entities.User
|
||||
import dev.hilla.Endpoint
|
||||
import jakarta.annotation.security.PermitAll
|
||||
import org.springframework.security.core.Authentication
|
||||
@@ -8,7 +10,9 @@ import org.springframework.security.core.GrantedAuthority
|
||||
import org.springframework.security.core.context.SecurityContextHolder
|
||||
|
||||
@Endpoint
|
||||
class UserEndpoint {
|
||||
class UserEndpoint(
|
||||
private val userService: UserService
|
||||
) {
|
||||
|
||||
@PermitAll
|
||||
fun getUserInfo(): UserInfo {
|
||||
@@ -16,4 +20,18 @@ class UserEndpoint {
|
||||
val authorities: List<String> = auth.authorities.map { g: GrantedAuthority -> g.authority }
|
||||
return UserInfo(auth.name, authorities)
|
||||
}
|
||||
|
||||
@PermitAll
|
||||
fun registerUser(registration: UserRegistration): Boolean {
|
||||
val user = User(
|
||||
username = registration.username,
|
||||
password = registration.password,
|
||||
email = registration.email,
|
||||
roles = userService.toRoles(registration.roles)
|
||||
)
|
||||
|
||||
userService.registerUser(user)
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package de.grimsi.gameyfin.users
|
||||
|
||||
import de.grimsi.gameyfin.users.entities.Role
|
||||
import de.grimsi.gameyfin.users.entities.User
|
||||
import de.grimsi.gameyfin.users.persistence.RoleRepository
|
||||
import de.grimsi.gameyfin.users.persistence.UserRepository
|
||||
import jakarta.transaction.Transactional
|
||||
import org.springframework.security.core.GrantedAuthority
|
||||
@@ -17,6 +18,7 @@ import org.springframework.stereotype.Service
|
||||
@Transactional
|
||||
class UserService(
|
||||
private val userRepository: UserRepository,
|
||||
private val roleRepository: RoleRepository,
|
||||
private val passwordEncoder: PasswordEncoder
|
||||
) : UserDetailsService {
|
||||
|
||||
@@ -40,6 +42,10 @@ class UserService(
|
||||
return userRepository.save(user)
|
||||
}
|
||||
|
||||
fun toRoles(roles: Collection<String>): List<Role> {
|
||||
return roles.mapNotNull { r -> roleRepository.findByRolename(r) }
|
||||
}
|
||||
|
||||
private fun toAuthorities(roles: Collection<Role>): List<GrantedAuthority> {
|
||||
return roles.map { r -> SimpleGrantedAuthority(r.rolename) }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package de.grimsi.gameyfin.users.dto
|
||||
|
||||
data class UserRegistration(
|
||||
val username: String,
|
||||
val password: String,
|
||||
val email: String,
|
||||
val roles: List<String>
|
||||
)
|
||||
@@ -16,7 +16,7 @@ class User(
|
||||
var id: Long? = null,
|
||||
|
||||
@field:NotNull
|
||||
var password: String? = null,
|
||||
var password: String,
|
||||
|
||||
@field:Nullable
|
||||
var email: String? = null,
|
||||
@@ -33,5 +33,5 @@ class User(
|
||||
joinColumns = [JoinColumn(name = "user_id", referencedColumnName = "id")],
|
||||
inverseJoinColumns = [JoinColumn(name = "role_id", referencedColumnName = "id")]
|
||||
)
|
||||
var roles: Collection<Role> = emptyList()
|
||||
var roles: Collection<Role>
|
||||
)
|
||||
Reference in New Issue
Block a user