Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
fix: associate default issuer on account registration (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean authored Oct 24, 2023
1 parent c100740 commit 8e3fc18
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/kotlin/id/walt/service/account/AccountsService.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package id.walt.service.account

import id.walt.db.models.Issuers
import id.walt.db.repositories.AccountIssuersRepository
import id.walt.db.repositories.DbAccountIssuers
import id.walt.service.WalletServiceManager
import id.walt.web.generateToken
import id.walt.web.model.AddressLoginRequest
import id.walt.web.model.EmailLoginRequest
import id.walt.web.model.LoginRequest
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.JsonPrimitive
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.transactions.transaction
import java.util.*

object AccountsService {
Expand All @@ -18,12 +24,28 @@ object AccountsService {
}.also {
it.getOrNull()?.let {
runBlocking {
// create a default did
WalletServiceManager.getWalletService(it.id)
.createDid(method = "key", mapOf("alias" to JsonPrimitive("Onboarding")))
// associate the default issuer
//TODO: use issuers-service
queryDefaultIssuer("walt.id")?.let { iss ->
AccountIssuersRepository.insert(
DbAccountIssuers(
account = it.id,
issuer = iss
)
)
}
}
}
}

private fun queryDefaultIssuer(name: String) =
transaction { Issuers.select(Issuers.name eq name) }.singleOrNull()?.let {
it[Issuers.id]
}?.value

fun authenticate(request: LoginRequest): Result<AuthenticationResult> = runCatching {
when (request) {
is EmailLoginRequest -> emailStrategy.authenticate(request)
Expand Down

0 comments on commit 8e3fc18

Please sign in to comment.