当前位置: 首页>>代码示例>>Scala>>正文


Scala DelegableAuthInfoDAO类代码示例

本文整理汇总了Scala中com.mohiva.play.silhouette.persistence.daos.DelegableAuthInfoDAO的典型用法代码示例。如果您正苦于以下问题:Scala DelegableAuthInfoDAO类的具体用法?Scala DelegableAuthInfoDAO怎么用?Scala DelegableAuthInfoDAO使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DelegableAuthInfoDAO类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: PasswordInfoDao

//设置package包名称以及导入依赖的类
package daos

import javax.inject.Inject

import scala.concurrent.{Await, Future}
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.util.PasswordInfo
import com.mohiva.play.silhouette.persistence.daos.DelegableAuthInfoDAO
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.libs.json._
import play.modules.reactivemongo.ReactiveMongoApi
import play.modules.reactivemongo.json._
import reactivemongo.play.json.collection.JSONCollection
import models.User
import User._

import scala.concurrent.duration.Duration

class PasswordInfoDao @Inject() (
                                  val reactiveMongoApi: ReactiveMongoApi
                                ) extends DelegableAuthInfoDAO[PasswordInfo] {
  val users = Await.result(reactiveMongoApi.database.map(_.collection[JSONCollection]("users")), Duration.Inf)

  def find(loginInfo:LoginInfo):Future[Option[PasswordInfo]] = for {
    user <- users.find(Json.obj(
      "profiles.loginInfo" -> loginInfo
    )).one[User]
  } yield user.flatMap(_.profiles.find(_.loginInfo == loginInfo)).flatMap(_.passwordInfo)

  def add(loginInfo:LoginInfo, authInfo:PasswordInfo):Future[PasswordInfo] =
    users.update(Json.obj(
      "profiles.loginInfo" -> loginInfo
    ), Json.obj(
      "$set" -> Json.obj("profiles.$.passwordInfo" -> authInfo)
    )).map(_ => authInfo)

  def update(loginInfo:LoginInfo, authInfo:PasswordInfo):Future[PasswordInfo] =
    add(loginInfo, authInfo)

  def save(loginInfo:LoginInfo, authInfo:PasswordInfo):Future[PasswordInfo] =
    add(loginInfo, authInfo)

  def remove(loginInfo:LoginInfo):Future[Unit] =
    users.update(Json.obj(
      "profiles.loginInfo" -> loginInfo
    ), Json.obj(
      "$pull" -> Json.obj(
        "profiles" -> Json.obj("loginInfo" -> loginInfo)
      )
    )).map(_ => ())
} 
开发者ID:tm-sukehiro,项目名称:play-hands-on,代码行数:52,代码来源:PasswordInfoDao.scala

示例2: OAuth1InfoDao

//设置package包名称以及导入依赖的类
package daos

import javax.inject.Inject

import scala.concurrent.{Await, Future}
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.OAuth1Info
import com.mohiva.play.silhouette.persistence.daos.DelegableAuthInfoDAO
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.libs.json._
import play.modules.reactivemongo.ReactiveMongoApi
import play.modules.reactivemongo.json._
import reactivemongo.play.json.collection.JSONCollection
import models.User
import User._

import scala.concurrent.duration.Duration

class OAuth1InfoDao @Inject() (
                                val reactiveMongoApi: ReactiveMongoApi
                              ) extends DelegableAuthInfoDAO[OAuth1Info] {
  val users = Await.result(reactiveMongoApi.database.map(_.collection[JSONCollection]("users")), Duration.Inf)

  def find(loginInfo:LoginInfo):Future[Option[OAuth1Info]] = for {
    user <- users.find(Json.obj(
      "profiles.loginInfo" -> loginInfo
    )).one[User]
  } yield user.flatMap(_.profiles.find(_.loginInfo == loginInfo)).flatMap(_.oauth1Info)

  def add(loginInfo:LoginInfo, authInfo:OAuth1Info):Future[OAuth1Info] =
    users.update(Json.obj(
      "profiles.loginInfo" -> loginInfo
    ), Json.obj(
      "$set" -> Json.obj("profiles.$.oauth1Info" -> authInfo)
    )).map(_ => authInfo)

  def update(loginInfo:LoginInfo, authInfo:OAuth1Info):Future[OAuth1Info] =
    add(loginInfo, authInfo)

  def save(loginInfo:LoginInfo, authInfo:OAuth1Info):Future[OAuth1Info] =
    add(loginInfo, authInfo)

  def remove(loginInfo:LoginInfo):Future[Unit] =
    users.update(Json.obj(
      "profiles.loginInfo" -> loginInfo
    ), Json.obj(
      "$pull" -> Json.obj(
        "profiles" -> Json.obj("loginInfo" -> loginInfo)
      )
    )).map(_ => ())
} 
开发者ID:tm-sukehiro,项目名称:play-hands-on,代码行数:52,代码来源:OAuth1InfoDao.scala

示例3: PasswordInfoService

//设置package包名称以及导入依赖的类
package services

import java.time.LocalDateTime

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.util.PasswordInfo
import com.mohiva.play.silhouette.persistence.daos.DelegableAuthInfoDAO
import db.DbContext
import repositories.{PasswordInfoRepository, UserPasswordInfo}
import scala.concurrent.{ExecutionContext, Future}

class PasswordInfoService(val ctx: DbContext, userService: UserService)(implicit val executionContext: ExecutionContext) extends DelegableAuthInfoDAO[PasswordInfo] with PasswordInfoRepository {
  import ctx._

  override def add(loginInfo: LoginInfo, authInfo: PasswordInfo) = {
    userService.findUserByProvideKey(loginInfo.providerKey) flatMap {
      case Some(user) => run(pwInfo.insert(lift(
        UserPasswordInfo(
          user.id,
          authInfo.hasher,
          authInfo.password,
           Some("salt"),
          LocalDateTime.now()
        )
      )))
        .map(_ => authInfo)
      case None => Future(authInfo)
    }

  }

  override def find(loginInfo: LoginInfo) = {
    userService.findUserByProvideKey(loginInfo.providerKey) flatMap {
      case Some(user) => {
        for {
          e <- run(byUserId(user.id)).map(_.headOption)
        } yield {
          Some(PasswordInfo(e.get.hasher, e.get.password, e.get.salt))
        }
      }
      case None => Future(None)
    }
  }

  override def remove(loginInfo: LoginInfo) = ???

  override def save(loginInfo: LoginInfo, authInfo: PasswordInfo) = ???

  override def update(loginInfo: LoginInfo, authInfo: PasswordInfo) = ???
} 
开发者ID:iriddhi,项目名称:mis,代码行数:51,代码来源:PasswordInfoService.scala

示例4: DefaultInfoDao

//设置package包名称以及导入依赖的类
package com.dbrsn.auth.play.silhouette

import cats.implicits._
import cats.~>
import com.dbrsn.auth.model.ProviderAuthInfo
import com.mohiva.play.silhouette.api.AuthInfo
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.persistence.daos.DelegableAuthInfoDAO

import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import scala.language.higherKinds
import scala.reflect.ClassTag

trait DelegableAuthInfoDaoComponent extends SilhouetteAuthInfoComponent {

  class DefaultInfoDao[AI <: AuthInfo : ClassTag, F[_], AIC <: GenAuthInfoComponent[LoginInfo, AI]](
    interpreter: F ~> Future
  )(implicit I: AIC#AuthInfoOps[F], ec: ExecutionContext) extends DelegableAuthInfoDAO[AI] {
    override def find(loginInfo: LoginInfo): Future[Option[AI]] = {
      I.find(loginInfo).map(_.map(_.authInfo)).foldMap(interpreter)
    }
    override def add(loginInfo: LoginInfo, authInfo: AI): Future[AI] = {
      I.create(ProviderAuthInfo(loginInfo, authInfo)).map(_.authInfo).foldMap(interpreter)
    }
    override def update(loginInfo: LoginInfo, authInfo: AI): Future[AI] = {
      I.update(loginInfo, authInfo).foldMap(interpreter).map { count =>
        require(count == 1, s"At least one element of $loginInfo must be updated")
        authInfo
      }
    }
    override def save(loginInfo: LoginInfo, authInfo: AI): Future[AI] = {
      I.createOrUpdate(ProviderAuthInfo(loginInfo, authInfo)).foldMap(interpreter).map { count =>
        require(count == 1, s"At least one element of $loginInfo must be updated")
        authInfo
      }
    }
    override def remove(loginInfo: LoginInfo): Future[Unit] = {
      I.delete(loginInfo).foldMap(interpreter).map { count =>
        require(count == 1, s"Element $loginInfo wasn't deleted")
        ()
      }
    }
  }

  class OAuth1Dao[F[_]](interpreter: F ~> Future)(implicit I: OAuth1.AuthInfoOps[F], ec: ExecutionContext)
    extends DefaultInfoDao[OAuth1Info, F, OAuth1.type](interpreter)

  class OAuth2Dao[F[_]](interpreter: F ~> Future)(implicit I: OAuth2.AuthInfoOps[F], ec: ExecutionContext)
    extends DefaultInfoDao[OAuth2Info, F, OAuth2.type](interpreter)

  class OpenIdDao[F[_]](interpreter: F ~> Future)(implicit I: OpenId.AuthInfoOps[F], ec: ExecutionContext)
    extends DefaultInfoDao[OpenIdInfo, F, OpenId.type](interpreter)

  class PasswordDao[F[_]](interpreter: F ~> Future)(implicit I: Password.AuthInfoOps[F], ec: ExecutionContext)
    extends DefaultInfoDao[PasswordInfo, F, Password.type](interpreter)

} 
开发者ID:dborisenko,项目名称:generic-auth,代码行数:59,代码来源:DelegableAuthInfoDaoComponent.scala

示例5: PasswordInfoDao

//设置package包名称以及导入依赖的类
package services.dao

import com.google.inject.Inject
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.util.PasswordInfo
import com.mohiva.play.silhouette.persistence.daos.DelegableAuthInfoDAO
import services.UserService

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

class PasswordInfoDao @Inject()(userService: UserService) extends DelegableAuthInfoDAO[PasswordInfo] {

  override def find(loginInfo: LoginInfo): Future[Option[PasswordInfo]] = {
    userService.retrieve(loginInfo).map(_.flatMap(_.passwordInfo))
  }

  override def add(loginInfo: LoginInfo, passInfo: PasswordInfo): Future[PasswordInfo] = {
    userService.updatePassHash(loginInfo, passInfo).map(_ => passInfo)
  }

  override def update(loginInfo: LoginInfo, passInfo: PasswordInfo): Future[PasswordInfo] = {
    userService.updatePassHash(loginInfo, passInfo).map(_ => passInfo)
  }

  override def save(loginInfo: LoginInfo, passInfo: PasswordInfo): Future[PasswordInfo] = {
    userService.updatePassHash(loginInfo, passInfo).map(_ => passInfo)
  }

  override def remove(loginInfo: LoginInfo): Future[Unit] = {
    userService.remove(loginInfo)
  }
} 
开发者ID:fsanaulla,项目名称:Silh,代码行数:34,代码来源:PasswordInfoDao.scala

示例6: OAuth1InfoDao

//设置package包名称以及导入依赖的类
package services.dao

import javax.inject.Inject

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.OAuth1Info
import com.mohiva.play.silhouette.persistence.daos.DelegableAuthInfoDAO
import services.UserService

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future


class OAuth1InfoDao @Inject()(userService: UserService) extends DelegableAuthInfoDAO[OAuth1Info] {

  override def find(loginInfo: LoginInfo): Future[Option[OAuth1Info]] = {
   userService.find(loginInfo).map(_.flatMap(_.oauth1Info))
  }

  override def add(loginInfo: LoginInfo, authInfo: OAuth1Info): Future[OAuth1Info] = {
    userService.updateOAuthInfo(loginInfo, authInfo).map(_ => authInfo)
  }

  override def update(loginInfo: LoginInfo, authInfo: OAuth1Info): Future[OAuth1Info] = {
    userService.updateOAuthInfo(loginInfo, authInfo).map(_ => authInfo)
  }

  override def save(loginInfo: LoginInfo, authInfo: OAuth1Info): Future[OAuth1Info] = {
    userService.updateOAuthInfo(loginInfo, authInfo).map(_ => authInfo)
  }

  override def remove(loginInfo: LoginInfo): Future[Unit] = {
    userService.remove(loginInfo)
  }
} 
开发者ID:fsanaulla,项目名称:Silh,代码行数:36,代码来源:OAuth1InfoDao.scala

示例7: InMemoryPasswordAuthInfoStore

//设置package包名称以及导入依赖的类
package stores

import com.google.inject.{Singleton, Inject}
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.util.PasswordInfo
import com.mohiva.play.silhouette.persistence.daos.DelegableAuthInfoDAO

import scala.collection.mutable
import scala.concurrent.Future

@Singleton
class InMemoryPasswordAuthInfoStore @Inject()() extends DelegableAuthInfoDAO[PasswordInfo] {
  val store = mutable.Map.empty[LoginInfo, PasswordInfo]

  override def find(loginInfo: LoginInfo): Future[Option[PasswordInfo]] = {
    Future.successful(store.get(loginInfo))
  }

  override def save(loginInfo: LoginInfo, passwordInfo: PasswordInfo): Future[PasswordInfo] = {
    store += (loginInfo -> passwordInfo)
    Future.successful(passwordInfo)
  }

  override def update(loginInfo: LoginInfo, passwordInfo: PasswordInfo): Future[PasswordInfo] = {
    store.get(loginInfo) match {
      case Some(_) =>
        save(loginInfo, passwordInfo)
      case None =>
        Future.failed(new Exception(s"cannot update $loginInfo, it does not exist"))
    }
  }

  override def add(loginInfo: LoginInfo, passwordInfo: PasswordInfo): Future[PasswordInfo] = {
    store.get(loginInfo) match {
      case None =>
        save(loginInfo, passwordInfo)
      case Some(_) =>
        Future.failed(new Exception(s"cannot add $loginInfo, it already exists"))
    }
  }

  override def remove(loginInfo: LoginInfo): Future[Unit] = {
    store -= loginInfo
    Future.successful(())
  }
} 
开发者ID:pequalsnp,项目名称:portroyal,代码行数:47,代码来源:InMemoryPasswordAuthInfoStore.scala

示例8: PersistentPasswordInfo

//设置package包名称以及导入依赖的类
package dao

import javax.inject.Inject

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.util.PasswordInfo
import com.mohiva.play.silhouette.persistence.daos.DelegableAuthInfoDAO
import play.api.libs.json._
import play.modules.reactivemongo.json._
import reactivemongo.api._
import reactivemongo.play.json.collection.JSONCollection

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

case class PersistentPasswordInfo(loginInfo: LoginInfo, authInfo: PasswordInfo)

class PasswordInfoRepository @Inject()(db: DB) extends DelegableAuthInfoDAO[PasswordInfo] {

  implicit val passwordInfoFormat = Json.format[PasswordInfo]
  implicit val persistentPasswordInfoFormat = Json.format[PersistentPasswordInfo]

  def collection: JSONCollection = db.collection[JSONCollection]("password")

  def find(loginInfo: LoginInfo) = {

    val passwordInfo: Future[Option[PersistentPasswordInfo]] = collection
      .find(Json.obj("loginInfo" -> loginInfo))
      .one[PersistentPasswordInfo]

    passwordInfo.flatMap {
      case None =>
        Future.successful(Option.empty[PasswordInfo])
      case Some(persistentPasswordInfo) =>
        Future(Some(persistentPasswordInfo.authInfo))
    }
  }

  def add(loginInfo: LoginInfo, authInfo: PasswordInfo): Future[PasswordInfo] = {
    collection.insert(PersistentPasswordInfo(loginInfo, authInfo))
    Future.successful(authInfo)
  }

  def update(loginInfo: LoginInfo, authInfo: PasswordInfo): Future[PasswordInfo] = {
    Future.successful(authInfo)
  }

  def save(loginInfo: LoginInfo, authInfo: PasswordInfo): Future[PasswordInfo] = {
    find(loginInfo).flatMap {
      case Some(_) => update(loginInfo, authInfo)
      case None => add(loginInfo, authInfo)
    }
  }

  def remove(loginInfo: LoginInfo): Future[Unit] = {
    Future.successful(())
  }
} 
开发者ID:team3,项目名称:Play2-mongodb-silhouette-activator-template,代码行数:59,代码来源:PasswordInfoRepository.scala

示例9: PasswordAuthInfoDAO

//设置package包名称以及导入依赖的类
package models.daos

import javax.inject.Inject

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.util.{PasswordHasher, PasswordInfo}
import com.mohiva.play.silhouette.persistence.daos.DelegableAuthInfoDAO
import org.example.project.schema.{Account, Query}
import xyz.mattclifton.autoquery.components.UpdateValue
import play.api.libs.concurrent.Execution.Implicits._

import scala.concurrent.Future

class PasswordAuthInfoDAO @Inject() (query: Query, passwordHasher: PasswordHasher) extends DelegableAuthInfoDAO[PasswordInfo] {
  def find(loginInfo: LoginInfo): Future[Option[PasswordInfo]] = {
    Future(getAccount(loginInfo).flatMap(toPasswordInfo(_)))
  }

  def update(loginInfo: LoginInfo, authInfo: PasswordInfo): Future[PasswordInfo] = {
    getAccount(loginInfo).map(account => {
      query.updateAccounts(
        filter = _.apply(ids = Seq(account.id)),
        values = _.apply(passwordHash = UpdateValue(Option(authInfo.password)), passwordSalt = UpdateValue(authInfo.salt))).execute()
    })

    Future(authInfo)
  }

  def remove(loginInfo: LoginInfo): Future[Unit] = {
    getAccount(loginInfo).map(account => {
      query.updateAccounts(
        filter = _.apply(ids = Seq(account.id)),
        values = _.apply(passwordHash = UpdateValue(None), passwordSalt = UpdateValue(None))).execute()
    })

    Future({})
  }

  def save(loginInfo: LoginInfo, authInfo: PasswordInfo): Future[PasswordInfo] = {
    update(loginInfo, authInfo)
  }

  def add(loginInfo: LoginInfo, authInfo: PasswordInfo): Future[PasswordInfo] = {
    update(loginInfo, authInfo)
  }

  private def getAccount(loginInfo: LoginInfo): Option[Account] = {
    query.getAccountProviders(
      filter = _.apply(providerIdAndProviderKey = Some(_.apply(Seq(loginInfo.providerID), Seq(loginInfo.providerKey)))),
      include = s => Seq(s.account)).execute().headOption.map(_.account)
  }

  private def toPasswordInfo(account: Account): Option[PasswordInfo] = {
    account.passwordHash.map(hash => PasswordInfo(passwordHasher.id, hash, account.passwordSalt))
  }
} 
开发者ID:lynx44,项目名称:play_autoquery_template,代码行数:57,代码来源:PasswordAuthInfoDAO.scala


注:本文中的com.mohiva.play.silhouette.persistence.daos.DelegableAuthInfoDAO类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。