rename user verifier
This commit is contained in:
+3
-3
@@ -7,7 +7,7 @@ import ru.shadowsparky.backend.data.StringFetcher
|
||||
import ru.shadowsparky.backend.data.StringResource
|
||||
import ru.shadowsparky.backend.data.generateRefreshToken
|
||||
import ru.shadowsparky.backend.data.toTokenHash
|
||||
import ru.shadowsparky.backend.domain.LoginVerifier
|
||||
import ru.shadowsparky.backend.domain.UserVerifier
|
||||
import ru.shadowsparky.domain.DispatcherProvider
|
||||
import ru.shadowsparky.gigawear.backend.AppDatabase
|
||||
import ru.shadowsparky.gigawear.common.AuthRepository
|
||||
@@ -23,7 +23,7 @@ import kotlin.time.toJavaInstant
|
||||
class BackendAuthRepositoryImpl(
|
||||
appDatabase: AppDatabase,
|
||||
private val stringFetcher: StringFetcher,
|
||||
private val loginVerifier: LoginVerifier,
|
||||
private val userVerifier: UserVerifier,
|
||||
private val jwtPreparer: JwtPreparer,
|
||||
private val dispatcherProvider: DispatcherProvider
|
||||
) : AuthRepository {
|
||||
@@ -34,7 +34,7 @@ class BackendAuthRepositoryImpl(
|
||||
val userCode = request.code
|
||||
val user = usersQueries.selectByCode(userCode).executeAsOneOrNull()
|
||||
?: throw BadRequestException(stringFetcher.get(StringResource.UNKNOWN_USER))
|
||||
loginVerifier.verify(user.user_id)
|
||||
userVerifier.verify(user.user_id)
|
||||
create(user.user_id)
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -4,17 +4,17 @@ import kotlinx.coroutines.withContext
|
||||
import org.koin.core.annotation.Factory
|
||||
import ru.shadowsparky.backend.data.StringFetcher
|
||||
import ru.shadowsparky.backend.data.StringResource
|
||||
import ru.shadowsparky.backend.domain.LoginVerifier
|
||||
import ru.shadowsparky.backend.domain.UserVerifier
|
||||
import ru.shadowsparky.domain.DispatcherProvider
|
||||
import ru.shadowsparky.gigawear.backend.AppDatabase
|
||||
import ru.shadowsparky.http.domain.BadRequestException
|
||||
|
||||
@Factory
|
||||
class LoginVerifierImpl(
|
||||
class UserVerifierImpl(
|
||||
private val appDatabase: AppDatabase,
|
||||
private val dispatcherProvider: DispatcherProvider,
|
||||
private val stringFetcher: StringFetcher
|
||||
) : LoginVerifier {
|
||||
) : UserVerifier {
|
||||
|
||||
override suspend fun verify(userId: Long) {
|
||||
withContext(dispatcherProvider.io) {
|
||||
+5
-5
@@ -7,7 +7,7 @@ import ru.shadowsparky.backend.data.JwtPreparer
|
||||
import ru.shadowsparky.backend.data.StringFetcher
|
||||
import ru.shadowsparky.backend.data.StringResource
|
||||
import ru.shadowsparky.backend.data.toTokenHash
|
||||
import ru.shadowsparky.backend.domain.LoginVerifier
|
||||
import ru.shadowsparky.backend.domain.UserVerifier
|
||||
import ru.shadowsparky.domain.Log
|
||||
import ru.shadowsparky.http.domain.BadRequestException
|
||||
import ru.shadowsparky.http.domain.TokenInfo
|
||||
@@ -26,7 +26,7 @@ class AuthTokenRepositoryFactory(
|
||||
private val db: AppDatabase,
|
||||
private val dispatcherProvider: DispatcherProvider,
|
||||
private val jwtPreparer: JwtPreparer,
|
||||
private val loginVerifier: LoginVerifier,
|
||||
private val userVerifier: UserVerifier,
|
||||
private val log: Log,
|
||||
private val stringFetcher: StringFetcher,
|
||||
private val envFetcher: EnvFetcher,
|
||||
@@ -38,7 +38,7 @@ class AuthTokenRepositoryFactory(
|
||||
db,
|
||||
dispatcherProvider,
|
||||
jwtPreparer,
|
||||
loginVerifier,
|
||||
userVerifier,
|
||||
userId,
|
||||
log,
|
||||
stringFetcher,
|
||||
@@ -52,7 +52,7 @@ class BackendAuthTokenRepository(
|
||||
private val db: AppDatabase,
|
||||
private val dispatcherProvider: DispatcherProvider,
|
||||
private val jwtPreparer: JwtPreparer,
|
||||
private val loginVerifier: LoginVerifier,
|
||||
private val userVerifier: UserVerifier,
|
||||
private val userId: Long,
|
||||
private val log: Log,
|
||||
private val stringFetcher: StringFetcher,
|
||||
@@ -132,7 +132,7 @@ class BackendAuthTokenRepository(
|
||||
private suspend fun create(login: String): TokenInfo = withContext(dispatcherProvider.io) {
|
||||
val userInfo = userInfoCache.query(login)
|
||||
?: throw BadRequestException(stringFetcher.get(StringResource.UNKNOWN_USER))
|
||||
loginVerifier.verify(userInfo.userId)
|
||||
userVerifier.verify(userInfo.userId)
|
||||
val rsp = jwtPreparer.prepare(userInfo.userId)
|
||||
val refresh = ByteArray(32)
|
||||
random.nextBytes(refresh)
|
||||
|
||||
+3
-3
@@ -3,15 +3,15 @@ package ru.shadowsparky.vbox.backend.data.auth
|
||||
import org.koin.core.annotation.Factory
|
||||
import ru.shadowsparky.backend.data.StringFetcher
|
||||
import ru.shadowsparky.backend.data.StringResource
|
||||
import ru.shadowsparky.backend.domain.LoginVerifier
|
||||
import ru.shadowsparky.backend.domain.UserVerifier
|
||||
import ru.shadowsparky.backend.domain.VerifyTokenException
|
||||
import ru.shadowsparky.vbox.shared.domain.FLAG_USER_BLOCKED
|
||||
|
||||
@Factory
|
||||
class BackendLoginVerifier(
|
||||
class BackendUserVerifier(
|
||||
private val stringFetcher: StringFetcher,
|
||||
private val userInfoCache: UserInfoCache
|
||||
) : LoginVerifier {
|
||||
) : UserVerifier {
|
||||
override suspend fun verify(userId: Long) {
|
||||
val user = userInfoCache.query(userId)
|
||||
?: throw VerifyTokenException(stringFetcher.get(StringResource.UNKNOWN_USER))
|
||||
@@ -5,7 +5,7 @@ import org.koin.core.annotation.Single
|
||||
import ru.shadowsparky.backend.data.TokenVerifier
|
||||
import ru.shadowsparky.backend.data.event.SessionRegistry
|
||||
import ru.shadowsparky.backend.domain.JwtInfo
|
||||
import ru.shadowsparky.backend.domain.LoginVerifier
|
||||
import ru.shadowsparky.backend.domain.UserVerifier
|
||||
import ru.shadowsparky.backend.domain.RemoteEventHandler
|
||||
import ru.shadowsparky.chat.backend.domain.ProcessUserMessageUseCase
|
||||
import ru.shadowsparky.updater.backend.data.BackendUpdateFetcherFactory
|
||||
@@ -41,7 +41,7 @@ class WebSocketEntryPoint(
|
||||
|
||||
@Single
|
||||
class AuthEntryPoint(
|
||||
val loginVerifier: LoginVerifier,
|
||||
val userVerifier: UserVerifier,
|
||||
val authTokenRepositoryFactory: AuthTokenRepositoryFactory,
|
||||
val jwtInfo: JwtInfo,
|
||||
val tokenVerifier: TokenVerifier
|
||||
|
||||
@@ -7,7 +7,7 @@ import ru.shadowsparky.backend.presentation.obtainUserId
|
||||
import ru.shadowsparky.vbox.backend.di.AuthEntryPoint
|
||||
|
||||
fun Application.configureJwt(authEntryPoint: AuthEntryPoint) = with(authEntryPoint) {
|
||||
configureJwt(jwtInfo, tokenVerifier, loginVerifier)
|
||||
configureJwt(jwtInfo, tokenVerifier, userVerifier)
|
||||
}
|
||||
|
||||
fun ApplicationCall.obtainUserId(): Long {
|
||||
|
||||
Reference in New Issue
Block a user