mirror of https://github.com/usbharu/Hideout.git
refactor: UserAuthenticationを非推奨に
This commit is contained in:
parent
8101354e91
commit
98178ef5ab
|
@ -1,16 +1,26 @@
|
||||||
package dev.usbharu.hideout.domain.model
|
package dev.usbharu.hideout.domain.model
|
||||||
|
|
||||||
|
import org.h2.mvstore.type.LongDataType
|
||||||
import org.jetbrains.exposed.dao.id.LongIdTable
|
import org.jetbrains.exposed.dao.id.LongIdTable
|
||||||
import org.jetbrains.exposed.sql.ResultRow
|
import org.jetbrains.exposed.sql.ResultRow
|
||||||
|
import org.jetbrains.exposed.sql.Table
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.ZoneId
|
||||||
|
|
||||||
data class User(
|
data class User(
|
||||||
|
val id:Long,
|
||||||
val name: String,
|
val name: String,
|
||||||
val domain: String,
|
val domain: String,
|
||||||
val screenName: String,
|
val screenName: String,
|
||||||
val description: String,
|
val description: String,
|
||||||
|
val password:String? = null,
|
||||||
val inbox: String,
|
val inbox: String,
|
||||||
val outbox: String,
|
val outbox: String,
|
||||||
val url: String
|
val url: String,
|
||||||
|
val publicKey:String,
|
||||||
|
val privateKey:String? = null,
|
||||||
|
val createdAt:LocalDateTime
|
||||||
)
|
)
|
||||||
|
|
||||||
data class UserEntity(
|
data class UserEntity(
|
||||||
|
@ -35,15 +45,21 @@ data class UserEntity(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
object Users : LongIdTable("users") {
|
object Users : Table("users") {
|
||||||
|
val id = long("id").uniqueIndex()
|
||||||
val name = varchar("name", length = 64)
|
val name = varchar("name", length = 64)
|
||||||
val domain = varchar("domain", length = 255)
|
val domain = varchar("domain", length = 255)
|
||||||
val screenName = varchar("screen_name", length = 64)
|
val screenName = varchar("screen_name", length = 64)
|
||||||
val description = varchar("description", length = 600)
|
val description = varchar("description", length = 600)
|
||||||
|
val password = varchar("password", length = 255).nullable()
|
||||||
val inbox = varchar("inbox", length = 255).uniqueIndex()
|
val inbox = varchar("inbox", length = 255).uniqueIndex()
|
||||||
val outbox = varchar("outbox", length = 255).uniqueIndex()
|
val outbox = varchar("outbox", length = 255).uniqueIndex()
|
||||||
val url = varchar("url", length = 255).uniqueIndex()
|
val url = varchar("url", length = 255).uniqueIndex()
|
||||||
|
val publicKey = varchar("public_key", length = 10000)
|
||||||
|
val privateKey = varchar("private_key", length = 10000)
|
||||||
|
val createdAt = long("created_at")
|
||||||
|
|
||||||
|
override val primaryKey: PrimaryKey = PrimaryKey(id)
|
||||||
init {
|
init {
|
||||||
uniqueIndex(name, domain)
|
uniqueIndex(name, domain)
|
||||||
}
|
}
|
||||||
|
@ -52,12 +68,17 @@ object Users : LongIdTable("users") {
|
||||||
|
|
||||||
fun ResultRow.toUser(): User {
|
fun ResultRow.toUser(): User {
|
||||||
return User(
|
return User(
|
||||||
|
this[Users.id],
|
||||||
this[Users.name],
|
this[Users.name],
|
||||||
this[Users.domain],
|
this[Users.domain],
|
||||||
this[Users.screenName],
|
this[Users.screenName],
|
||||||
this[Users.description],
|
this[Users.description],
|
||||||
|
this[Users.password],
|
||||||
this[Users.inbox],
|
this[Users.inbox],
|
||||||
this[Users.outbox],
|
this[Users.outbox],
|
||||||
this[Users.url]
|
this[Users.url],
|
||||||
|
this[Users.publicKey],
|
||||||
|
this[Users.privateKey],
|
||||||
|
LocalDateTime.ofInstant(Instant.ofEpochMilli((this[Users.createdAt])), ZoneId.systemDefault())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,14 @@ package dev.usbharu.hideout.domain.model
|
||||||
import org.jetbrains.exposed.dao.id.LongIdTable
|
import org.jetbrains.exposed.dao.id.LongIdTable
|
||||||
import org.jetbrains.exposed.sql.ReferenceOption
|
import org.jetbrains.exposed.sql.ReferenceOption
|
||||||
|
|
||||||
|
@Deprecated("")
|
||||||
data class UserAuthentication(
|
data class UserAuthentication(
|
||||||
val userId: Long,
|
val userId: Long,
|
||||||
val hash: String?,
|
val hash: String?,
|
||||||
val publicKey: String,
|
val publicKey: String,
|
||||||
val privateKey: String?
|
val privateKey: String?
|
||||||
)
|
)
|
||||||
|
@Deprecated("")
|
||||||
data class UserAuthenticationEntity(
|
data class UserAuthenticationEntity(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val userId: Long,
|
val userId: Long,
|
||||||
|
@ -25,7 +26,7 @@ data class UserAuthenticationEntity(
|
||||||
userAuthentication.privateKey
|
userAuthentication.privateKey
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@Deprecated("")
|
||||||
object UsersAuthentication : LongIdTable("users_auth") {
|
object UsersAuthentication : LongIdTable("users_auth") {
|
||||||
val userId = long("user_id").references(Users.id, onUpdate = ReferenceOption.CASCADE)
|
val userId = long("user_id").references(Users.id, onUpdate = ReferenceOption.CASCADE)
|
||||||
val hash = varchar("hash", length = 64).nullable()
|
val hash = varchar("hash", length = 64).nullable()
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package dev.usbharu.hideout.repository
|
package dev.usbharu.hideout.repository
|
||||||
|
|
||||||
import dev.usbharu.hideout.domain.model.User
|
import dev.usbharu.hideout.domain.model.*
|
||||||
import dev.usbharu.hideout.domain.model.UserEntity
|
|
||||||
import dev.usbharu.hideout.domain.model.Users
|
|
||||||
import dev.usbharu.hideout.domain.model.UsersFollowers
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
|
@ -20,21 +17,9 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ResultRow.toUser(): User {
|
|
||||||
return User(
|
|
||||||
this[Users.name],
|
|
||||||
this[Users.domain],
|
|
||||||
this[Users.screenName],
|
|
||||||
this[Users.description],
|
|
||||||
this[Users.inbox],
|
|
||||||
this[Users.outbox],
|
|
||||||
this[Users.url]
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun ResultRow.toUserEntity(): UserEntity {
|
private fun ResultRow.toUserEntity(): UserEntity {
|
||||||
return UserEntity(
|
return UserEntity(
|
||||||
this[Users.id].value,
|
this[Users.id],
|
||||||
this[Users.name],
|
this[Users.name],
|
||||||
this[Users.domain],
|
this[Users.domain],
|
||||||
this[Users.screenName],
|
this[Users.screenName],
|
||||||
|
@ -58,7 +43,7 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
it[inbox] = user.inbox
|
it[inbox] = user.inbox
|
||||||
it[outbox] = user.outbox
|
it[outbox] = user.outbox
|
||||||
it[url] = user.url
|
it[url] = user.url
|
||||||
}[Users.id].value, user)
|
}[Users.id], user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +128,7 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
.select { Users.id eq id }
|
.select { Users.id eq id }
|
||||||
.map {
|
.map {
|
||||||
UserEntity(
|
UserEntity(
|
||||||
id = it[followers[Users.id]].value,
|
id = it[followers[Users.id]],
|
||||||
name = it[followers[Users.name]],
|
name = it[followers[Users.name]],
|
||||||
domain = it[followers[Users.domain]],
|
domain = it[followers[Users.domain]],
|
||||||
screenName = it[followers[Users.screenName]],
|
screenName = it[followers[Users.screenName]],
|
||||||
|
|
|
@ -17,6 +17,7 @@ import io.ktor.client.request.*
|
||||||
import io.ktor.client.statement.*
|
import io.ktor.client.statement.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
class ActivityPubUserServiceImpl(
|
class ActivityPubUserServiceImpl(
|
||||||
private val userService: UserService,
|
private val userService: UserService,
|
||||||
|
@ -91,6 +92,7 @@ class ActivityPubUserServiceImpl(
|
||||||
val person = Config.configData.objectMapper.readValue<Person>(httpResponse.bodyAsText())
|
val person = Config.configData.objectMapper.readValue<Person>(httpResponse.bodyAsText())
|
||||||
val userEntity = userService.create(
|
val userEntity = userService.create(
|
||||||
User(
|
User(
|
||||||
|
id = 0L,
|
||||||
name = person.preferredUsername
|
name = person.preferredUsername
|
||||||
?: throw IllegalActivityPubObjectException("preferredUsername is null"),
|
?: throw IllegalActivityPubObjectException("preferredUsername is null"),
|
||||||
domain = url.substringAfter(":").substringBeforeLast("/"),
|
domain = url.substringAfter(":").substringBeforeLast("/"),
|
||||||
|
@ -98,7 +100,9 @@ class ActivityPubUserServiceImpl(
|
||||||
description = person.summary ?: "",
|
description = person.summary ?: "",
|
||||||
inbox = person.inbox ?: throw IllegalActivityPubObjectException("inbox is null"),
|
inbox = person.inbox ?: throw IllegalActivityPubObjectException("inbox is null"),
|
||||||
outbox = person.outbox ?: throw IllegalActivityPubObjectException("outbox is null"),
|
outbox = person.outbox ?: throw IllegalActivityPubObjectException("outbox is null"),
|
||||||
url = url
|
url = url,
|
||||||
|
publicKey = "",
|
||||||
|
createdAt = LocalDateTime.now()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
userAuthService.createAccount(
|
userAuthService.createAccount(
|
||||||
|
|
|
@ -13,6 +13,7 @@ import io.ktor.util.*
|
||||||
import java.security.*
|
import java.security.*
|
||||||
import java.security.interfaces.RSAPrivateKey
|
import java.security.interfaces.RSAPrivateKey
|
||||||
import java.security.interfaces.RSAPublicKey
|
import java.security.interfaces.RSAPublicKey
|
||||||
|
import java.time.LocalDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class UserAuthService(
|
class UserAuthService(
|
||||||
|
@ -34,13 +35,16 @@ class UserAuthService(
|
||||||
override suspend fun registerAccount(username: String, hash: String) {
|
override suspend fun registerAccount(username: String, hash: String) {
|
||||||
val url = "${Config.configData.url}/users/$username"
|
val url = "${Config.configData.url}/users/$username"
|
||||||
val registerUser = User(
|
val registerUser = User(
|
||||||
|
id = 0L,
|
||||||
name = username,
|
name = username,
|
||||||
domain = Config.configData.domain,
|
domain = Config.configData.domain,
|
||||||
screenName = username,
|
screenName = username,
|
||||||
description = "",
|
description = "",
|
||||||
inbox = "$url/inbox",
|
inbox = "$url/inbox",
|
||||||
outbox = "$url/outbox",
|
outbox = "$url/outbox",
|
||||||
url = url
|
url = url,
|
||||||
|
publicKey = "",
|
||||||
|
createdAt = LocalDateTime.now(),
|
||||||
)
|
)
|
||||||
val createdUser = userRepository.create(registerUser)
|
val createdUser = userRepository.create(registerUser)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue