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


Scala IdentityService类代码示例

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


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

示例1: UserService

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

import java.util.UUID

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.services.IdentityService
import db.DbContext
import repositories.{UserPasswordInfo, User, UserLoginInfo, UserRepository}

import scala.concurrent.{ExecutionContext, Future}


class UserService(val ctx: DbContext)(implicit val ec: ExecutionContext) extends UserRepository with IdentityService[User] {
  import ctx._
  override def createUserWithRole(role: String): Future[UUID] = {
    val id = UUID.randomUUID()
    val created = java.time.LocalDateTime.now()
    run(users.insert(lift(User(id, role, created)))).map(_ => id)
  }

  override def createLoginInfo(userLoginInfo: UserLoginInfo): Future[UUID] = {
    run(loginInfos.insert(lift(userLoginInfo))).map(_ => userLoginInfo.userId)
  }

  override def createPasswordInfo(passwordInfo: UserPasswordInfo): Future[UUID] = {
    run(pwInfo.insert(lift(passwordInfo))).map(_ => passwordInfo.userId)
  }

  def findUserByProvideKey(providerKey: String): Future[Option[User]] = {
    run(findLoginInfoByProviderKey(providerKey))
      .map(_.headOption).flatMap {
        case Some(userLoginInfo) => run(byId(userLoginInfo.userId)).map(_.headOption)
        case None => Future(None)
      }
  }

  def retrieve(loginInfo: LoginInfo): Future[Option[User]] = findUserByProvideKey(loginInfo.providerKey)

} 
开发者ID:iriddhi,项目名称:mis,代码行数:40,代码来源:UserService.scala

示例2: UserService

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

import javax.inject.Inject

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.services.IdentityService
import models.ServiceProfile

import scala.concurrent.Future


class UserService @Inject() (userMicroServiceRegistry: UserMicroServiceRegistry) extends IdentityService[ServiceProfile] {
  override def retrieve(loginInfo: LoginInfo): Future[Option[ServiceProfile]] = userMicroServiceRegistry.getUserMicroService[ServiceProfile](loginInfo.providerID).map(_.retrieve(loginInfo)).getOrElse(Future.successful(None)) //Future.sequence(userMicroServiceRegistry.services.map {s => s.retrieve(loginInfo)}).map(_.flatten.headOption)
  def save[T <: ServiceProfile](profile: T): Future[T] = userMicroServiceRegistry.getUserMicroService[T](profile.service).map(_.save(profile)).getOrElse(Future.failed(new NoSuchElementException("None.get")))
}

case class UserMicroServiceRegistry @Inject() (services: Seq[UserMicroService[_]]) {
  def getUserMicroService[T <: ServiceProfile](tag: String): Option[UserMicroService[T]] = {
    println(s"$tag UserService.scala")
    services.foreach(s => println(s.tag))
    services.find(_.tag == tag).map(_.asInstanceOf[UserMicroService[T]])
  }
} 
开发者ID:hnrklssn,项目名称:game-check-match,代码行数:24,代码来源:UserService.scala

示例3: UserDao

//设置package包名称以及导入依赖的类
package org.intracer.finance.slick

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.services.IdentityService
import org.intracer.finance.User
import play.api.libs.Codecs

class UserDao() extends BaseDao with IdentityService[User] {

  import driver.api._

  val query = TableQuery[Users]

  def insert(user: User): Int = run {
    query returning query.map(_.id) += user
  }

  def insertAll(users: Seq[User]): Unit = run {
    query.forceInsertAll(users)
  }

  def list: Seq[User] = run {
    query.sortBy(_.fullname).result
  }

  def count: Int = run {
    query.countDistinct.result
  }

  def byEmail(email: String): Option[User] = run {
    query.filter(_.email === email).result.headOption
  }

  def byId(id: Int): Option[User] = run {
    query.filter(_.id === id).result.headOption
  }

  def login(username: String, password: String): Option[User] = {
    byEmail(username).filter(user => {
      val passwordTrimmed = password.trim
      val inputHash = hash(user, passwordTrimmed)
      val dbHash = user.password.get
      inputHash == dbHash
    })
  }

  def hash(user: User, password: String): String =
    sha1(password)

  def sha1(input: String) = Codecs.sha1(input.getBytes)

  override def retrieve(loginInfo: LoginInfo) = {
    db.run {
      query
        .filter(_.email === loginInfo.providerKey)
        .result.headOption
    }
  }
} 
开发者ID:intracer,项目名称:wmua-finance,代码行数:60,代码来源:UserDao.scala

示例4: UserService

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

import benchq.Config
import benchq.model.User
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.services.IdentityService

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

class UserService(config: Config) extends IdentityService[User] {
  val users: mutable.HashMap[String, User] = mutable.HashMap.empty

  def retrieve(loginInfo: LoginInfo): Future[Option[User]] = {
    Future.successful(users.get(loginInfo.providerKey))
  }

  def save(profile: GithubProfile): Future[User] = {
    if (config.silhouette.allowedUsers(profile.login)) {
      val r = User(profile.id, profile.login, profile.name)
      users += profile.loginInfo.providerKey -> r
      Future.successful(r)
    } else
      Future.failed(UnauthorizedUserException(profile.login))
  }
}

case class UnauthorizedUserException(login: String)
    extends Exception(s"User $login is not authorized") 
开发者ID:scala,项目名称:compiler-benchq,代码行数:30,代码来源:UserService.scala


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