Create external accounts independent from signup config

Refs: #1619, #1621
This commit is contained in:
eikek 2022-07-07 15:25:04 +02:00
parent 2c9e012c96
commit 508ad5bc03
2 changed files with 26 additions and 31 deletions

View File

@ -20,8 +20,10 @@ trait OSignup[F[_]] {
def register(cfg: Config)(data: RegisterData): F[SignupResult] def register(cfg: Config)(data: RegisterData): F[SignupResult]
/** Creates the given account if it doesn't exist. */ /** Creates the given account if it doesn't exist. This is independent from signup
def setupExternal(cfg: Config)(data: ExternalAccount): F[SignupResult] * configuration.
*/
def setupExternal(data: ExternalAccount): F[SignupResult]
def newInvite(cfg: Config)(password: Password): F[NewInviteResult] def newInvite(cfg: Config)(password: Password): F[NewInviteResult]
} }
@ -77,36 +79,31 @@ object OSignup {
} }
} }
def setupExternal(cfg: Config)(data: ExternalAccount): F[SignupResult] = def setupExternal(data: ExternalAccount): F[SignupResult] =
cfg.mode match { if (data.source == AccountSource.Local)
case Config.Mode.Closed => SignupResult
SignupResult.signupClosed.pure[F] .failure(new Exception("Account source must not be LOCAL!"))
case _ => .pure[F]
if (data.source == AccountSource.Local) else
SignupResult for {
.failure(new Exception("Account source must not be LOCAL!")) recs <- makeRecords(data.collName, data.login, Password(""), data.source)
.pure[F] cres <- store.add(
else RCollective.insert(recs._1),
for { RCollective.existsById(data.collName)
recs <- makeRecords(data.collName, data.login, Password(""), data.source) )
cres <- store.add( ures <- store.add(RUser.insert(recs._2), RUser.exists(data.login))
RCollective.insert(recs._1), res = cres match {
RCollective.existsById(data.collName) case AddResult.Failure(ex) =>
) SignupResult.failure(ex)
ures <- store.add(RUser.insert(recs._2), RUser.exists(data.login)) case _ =>
res = cres match { ures match {
case AddResult.Failure(ex) => case AddResult.Failure(ex) =>
SignupResult.failure(ex) SignupResult.failure(ex)
case _ => case _ =>
ures match { SignupResult.success
case AddResult.Failure(ex) =>
SignupResult.failure(ex)
case _ =>
SignupResult.success
}
} }
} yield res }
} } yield res
private def retryInvite(res: SignupResult): Boolean = private def retryInvite(res: SignupResult): Boolean =
res match { res match {

View File

@ -105,9 +105,7 @@ object OpenId {
import dsl._ import dsl._
for { for {
setup <- backend.signup.setupExternal(cfg.backend.signup)( setup <- backend.signup.setupExternal(ExternalAccount(accountId))
ExternalAccount(accountId)
)
res <- setup match { res <- setup match {
case SignupResult.Failure(ex) => case SignupResult.Failure(ex) =>
logger.error(ex)(s"Error when creating external account!") *> logger.error(ex)(s"Error when creating external account!") *>