diff options
author | Marvin Borner | 2019-04-14 01:02:09 +0200 |
---|---|---|
committer | Marvin Borner | 2019-04-14 01:02:09 +0200 |
commit | c6e874ed068a640ad5ca2406b9abf93123bfb92e (patch) | |
tree | dad74a5ad09de113b26e85a39445ab7baf080b57 /src/main/kotlin/DatabaseController.kt | |
parent | 7117f01a3e64726f4e069df21634647613325d4a (diff) |
Added multi user directory support
Diffstat (limited to 'src/main/kotlin/DatabaseController.kt')
-rw-r--r-- | src/main/kotlin/DatabaseController.kt | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/main/kotlin/DatabaseController.kt b/src/main/kotlin/DatabaseController.kt index 8b82093..a89a719 100644 --- a/src/main/kotlin/DatabaseController.kt +++ b/src/main/kotlin/DatabaseController.kt @@ -123,12 +123,12 @@ class DatabaseController(dbFileLocation: String = "main.db") { } /** - * Returns the corresponding username using [uuid] + * Returns the corresponding username using [userId] */ - fun getUsernameByUUID(uuid: String): String { + fun getUsername(userId: Int): String { return transaction { try { - UserData.select { UserData.uuid eq uuid }.map { it[UserData.username] }[0] + UserData.select { UserData.id eq userId }.map { it[UserData.username] }[0] } catch (_: Exception) { "" } @@ -136,6 +136,19 @@ class DatabaseController(dbFileLocation: String = "main.db") { } /** + * Returns the corresponding username using [uuid] + */ + fun getUserIdByUUID(uuid: String): Int { + return transaction { + try { + UserData.select { UserData.uuid eq uuid }.map { it[UserData.id] }[0] + } catch (_: Exception) { + -1 + } + } + } + + /** * Returns the corresponding uuid using [usernameString] */ fun getUUID(usernameString: String): String { @@ -156,19 +169,17 @@ class DatabaseController(dbFileLocation: String = "main.db") { try { UserData.select { UserData.username eq usernameString }.map { it[UserData.id] }[0] } catch (_: Exception) { - log.warning("User not found!") -1 } } } /** - * Returns the corresponding role using [usernameString] + * Returns the corresponding role using [userId] */ - fun getRoles(usernameString: String): List<Roles> { + fun getRoles(userId: Int): List<Roles> { return transaction { try { - val userId = UserData.select { UserData.username eq usernameString }.map { it[UserData.id] }[0] val userRoleId = UserRoles.select { UserRoles.userId eq userId }.map { it[UserRoles.roleId] }[0] val userRoles = mutableListOf<Roles>() |