• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala LoginInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: save

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

import java.util.UUID

import models.slick.TableDefinitions
import com.mohiva.play.silhouette.api.LoginInfo
import models.User
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import slick.dbio.DBIOAction
import javax.inject.Inject

import daos.util.UserDAO
import models.slick.SlickDAO
import play.api.db.slick.DatabaseConfigProvider

import scala.concurrent.Future


  def save(user: User) = {
    val userID = user.userID.toString
    val balance = 0
    val userType = user.userType.toInt
    val email = user.email
    val dbUser = DBUser(userID, balance, userType, email)
    val dbLoginInfo = DBLoginInfo(None, user.loginInfo.providerID, user.loginInfo.providerKey)
    // We don't have the LoginInfo id so we try to get it first.
    // If there is no LoginInfo yet for this user we retrieve the id on insertion.
    val loginInfoAction = {
      val retrieveLoginInfo = slickLoginInfos.filter(
        info => info.providerID === user.loginInfo.providerID &&
          info.providerKey === user.loginInfo.providerKey).result.headOption
      val insertLoginInfo = slickLoginInfos.returning(slickLoginInfos.map(_.id)).
        into((info, id) => info.copy(id = Some(id))) += dbLoginInfo
      for {
        loginInfoOption <- retrieveLoginInfo
        loginInfo <- loginInfoOption.map(DBIO.successful(_)).getOrElse(insertLoginInfo)
      } yield loginInfo
    }
    // combine database actions to be run sequentially
    val actions = (for {
      _ <- slickUsers.insertOrUpdate(dbUser)
      loginInfo <- loginInfoAction
      _ <- slickUserLoginInfos += DBUserLoginInfo(dbUser.userID, loginInfo.id.get)
    } yield ()).transactionally
    // run actions and return user afterwards
    db.run(actions).map(_ => user)
  }
} 
开发者ID:Bakuchi,项目名称:certification,代码行数:49,代码来源:UserDAOImpl.scala


示例2: User

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

import java.util.UUID

import com.mohiva.play.silhouette.api.{ Identity, LoginInfo }

import utils.misc.Glicko

case class User(
  userID: UUID,
  loginInfo: LoginInfo,
  handle: Option[String],
  regpass: Option[String],
  firstName: Option[String],
  lastName: Option[String],
  fullName: Option[String],
  email: Option[String],
  avatarURL: Option[String],
  activated: Boolean,
  admin: Boolean = false,
  rating: Double = Glicko.rating0,
  rd: Double = Glicko.rd0,
  lastrated: Double = 0.0
) extends Identity {

  def name = fullName.orElse {
    firstName -> lastName match {
      case (Some(f), Some(l)) => Some(f + " " + l)
      case (Some(f), None) => Some(f)
      case (None, Some(l)) => Some(l)
      case _ => None
    }
  }

  def setActivated(a: Boolean) = this.copy(activated = a)
} 
开发者ID:serversideapps,项目名称:silhmojs,代码行数:37,代码来源:User.scala


示例3: AuthenticatorQueries

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

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import jdub.async.{ Statement, Row, FlatSingleRowQuery }
import jdub.async.queries.BaseQueries
import org.joda.time.LocalDateTime

object AuthenticatorQueries extends BaseQueries[CookieAuthenticator] {
  override protected val tableName = "session_info"
  override protected val columns = Seq("id", "provider", "key", "last_used", "expiration", "fingerprint", "created")
  override protected val searchColumns = Seq("id::text", "key")

  val insert = Insert
  val getById = GetById
  val removeById = RemoveById

  case class FindSessionInfoByLoginInfo(l: LoginInfo) extends FlatSingleRowQuery[CookieAuthenticator] {
    override val sql = getSql(Some("provider = ? and key = ?"))
    override val values = Seq(l.providerID, l.providerKey)
    override def flatMap(row: Row) = Some(fromRow(row))
  }

  case class UpdateAuthenticator(ca: CookieAuthenticator) extends Statement {
    override val sql = updateSql(Seq("provider", "key", "last_used", "expiration", "fingerprint"))
    override val values = Seq(
      ca.loginInfo.providerID,
      ca.loginInfo.providerKey,
      ca.lastUsedDateTime.toLocalDateTime,
      ca.expirationDateTime.toLocalDateTime,
      ca.fingerprint,
      ca.id
    )
  }

  override protected def fromRow(row: Row) = {
    val id = row.as[String]("id")
    val provider = row.as[String]("provider")
    val key = row.as[String]("key")
    val lastUsed = row.as[LocalDateTime]("last_used").toDateTime
    val expiration = row.as[LocalDateTime]("expiration").toDateTime
    val idleTimeout = None
    val cookieMaxAge = None
    val fingerprint = row.asOpt[String]("fingerprint")
    CookieAuthenticator(id, LoginInfo(provider, key), lastUsed, expiration, idleTimeout, cookieMaxAge, fingerprint)
  }

  override protected def toDataSeq(ca: CookieAuthenticator) = Seq(
    ca.id,
    ca.loginInfo.providerID,
    ca.loginInfo.providerKey,
    ca.lastUsedDateTime.toLocalDateTime,
    ca.expirationDateTime.toLocalDateTime,
    ca.fingerprint,
    new LocalDateTime()
  )
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:58,代码来源:AuthenticatorQueries.scala


示例4: OAuth1InfoQueries

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

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.OAuth1Info
import jdub.async.{ Row, Statement }
import jdub.async.queries.BaseQueries
import org.joda.time.LocalDateTime

object OAuth1InfoQueries extends BaseQueries[OAuth1Info] {
  override protected val tableName = "oauth1_info"
  override protected val columns = Seq("provider", "key", "token", "secret", "created")
  override protected val idColumns = Seq("provider", "key")
  override protected val searchColumns = Seq("key", "token")

  val getById = GetById
  val removeById = RemoveById

  case class CreateOAuth1Info(l: LoginInfo, o: OAuth1Info) extends Statement {
    override val sql = insertSql
    override val values = Seq(l.providerID, l.providerKey) ++ toDataSeq(o)
  }

  case class UpdateOAuth1Info(l: LoginInfo, o: OAuth1Info) extends Statement {
    override val sql = s"update $tableName set token = ?, secret = ?, created = ? where provider = ? and key = ?"
    override val values = toDataSeq(o) ++ Seq(l.providerID, l.providerKey)
  }

  override protected def fromRow(row: Row) = {
    val token = row.as[String]("token")
    val secret = row.as[String]("secret")
    OAuth1Info(token, secret)
  }

  override protected def toDataSeq(o: OAuth1Info) = Seq(o.token, o.secret, new LocalDateTime())
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:36,代码来源:OAuth1InfoQueries.scala


示例5: ProfileQueries

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

import java.util.UUID

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.CommonSocialProfile
import jdub.async.queries.BaseQueries
import jdub.async.{ Query, Row, FlatSingleRowQuery }
import org.joda.time.LocalDateTime

object ProfileQueries extends BaseQueries[CommonSocialProfile] {
  override protected val tableName = "user_profiles"
  override protected val columns = Seq("provider", "key", "email", "first_name", "last_name", "full_name", "avatar_url", "created")
  override protected val searchColumns = Seq("key", "email", "first_name", "last_name", "full_name")

  val insert = Insert
  val remove = RemoveById

  case class FindProfile(provider: String, key: String) extends FlatSingleRowQuery[CommonSocialProfile] {
    override val sql = getSql(Some("provider = ? and key = ?"))
    override val values = Seq(provider, key)
    override def flatMap(row: Row) = Some(fromRow(row))
  }

  case class FindProfilesByUser(id: UUID) extends Query[List[CommonSocialProfile]] {
    override val sql = s"select ${columns.mkString(", ")} from $tableName p " +
      "where (p.provider || ':' || p.key) in (select unnest(profiles) from users where users.id = ?)"
    override val values = Seq(id)
    override def reduce(rows: Iterator[Row]) = rows.map(fromRow).toList
  }

  override protected def fromRow(row: Row) = {
    val loginInfo = LoginInfo(
      providerID = row.as[String]("provider"),
      providerKey = row.as[String]("key")
    )
    val firstName = row.asOpt[String]("first_name")
    val lastName = row.asOpt[String]("last_name")
    val fullName = row.asOpt[String]("full_name")
    val email = row.asOpt[String]("email")
    val avatarUrl = row.asOpt[String]("avatar_url")

    CommonSocialProfile(loginInfo, firstName, lastName, fullName, email, avatarUrl)
  }

  override protected def toDataSeq(p: CommonSocialProfile) = Seq(
    p.loginInfo.providerID, p.loginInfo.providerKey, p.email, p.firstName, p.lastName, p.fullName, p.avatarURL, new LocalDateTime()
  )
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:50,代码来源:ProfileQueries.scala


示例6: OpenIdInfoQueries

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

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.OpenIDInfo
import jdub.async.{ Row, Statement }
import jdub.async.queries.BaseQueries
import org.joda.time.LocalDateTime
import play.api.libs.json.{ JsValue, Json }

object OpenIdInfoQueries extends BaseQueries[OpenIDInfo] {
  override protected val tableName = "openid_info"
  override protected val columns = Seq("provider", "key", "id", "attributes", "created")
  override protected val idColumns = Seq("provider", "key")
  override protected val searchColumns = Seq("key")

  val getById = GetById
  val removeById = RemoveById

  case class CreateOpenIdInfo(l: LoginInfo, o: OpenIDInfo) extends Statement {
    override val sql = insertSql
    override val values = Seq(l.providerID, l.providerKey) ++ toDataSeq(o)
  }

  case class UpdateOpenIdInfo(l: LoginInfo, o: OpenIDInfo) extends Statement {
    override val sql = s"update $tableName set id = ?, attributes = ?, created = ? where provider = ? and key = ?"
    val attributes = Json.prettyPrint(Json.toJson(o.attributes))
    override val values = toDataSeq(o) ++ Seq(l.providerID, l.providerKey)
  }

  override protected def fromRow(row: Row) = {
    val id = row.as[String]("id")
    val attributesString = row.as[String]("attributes")
    val attributes = Json.parse(attributesString).as[Map[String, JsValue]].map(x => x._1 -> x._2.as[String])
    OpenIDInfo(id, attributes)
  }

  override protected def toDataSeq(o: OpenIDInfo) = {
    val attributes = Json.prettyPrint(Json.toJson(o.attributes))
    Seq(o.id, attributes, new LocalDateTime())
  }
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:42,代码来源:OpenIdInfoQueries.scala


示例7: PasswordInfoQueries

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

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.util.PasswordInfo
import jdub.async.{ Row, Statement }
import jdub.async.queries.BaseQueries
import org.joda.time.LocalDateTime

object PasswordInfoQueries extends BaseQueries[PasswordInfo] {
  override protected val tableName = "password_info"
  override protected val columns = Seq("provider", "key", "hasher", "password", "salt", "created")
  override protected def idColumns = Seq("provider", "key")
  override protected val searchColumns = Seq("key")

  val getById = GetById
  val removeById = RemoveById

  case class CreatePasswordInfo(l: LoginInfo, p: PasswordInfo) extends Statement {
    override val sql = insertSql
    override val values = Seq(l.providerID, l.providerKey) ++ toDataSeq(p)
  }

  case class UpdatePasswordInfo(l: LoginInfo, p: PasswordInfo) extends Statement {
    override val sql = s"update $tableName set hasher = ?, password = ?, salt = ?, created = ? where provider = ? and key = ?"
    override val values = toDataSeq(p) ++ Seq(l.providerID, l.providerKey)
  }

  override protected def fromRow(row: Row) = PasswordInfo(
    hasher = row.as[String]("hasher"),
    password = row.as[String]("password"),
    salt = row.asOpt[String]("salt")
  )

  override protected def toDataSeq(p: PasswordInfo) = Seq(p.hasher, p.password, p.salt, new LocalDateTime())
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:36,代码来源:PasswordInfoQueries.scala


示例8: OAuth2InfoQueries

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

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.OAuth2Info
import jdub.async.{ Row, Statement }
import jdub.async.queries.BaseQueries
import org.joda.time.LocalDateTime
import play.api.libs.json.{ JsValue, Json }

object OAuth2InfoQueries extends BaseQueries[OAuth2Info] {
  override protected val tableName = "oauth2_info"
  override protected val columns = Seq("provider", "key", "access_token", "token_type", "expires_in", "refresh_token", "params", "created")
  override protected val idColumns = Seq("provider", "key")
  override protected val searchColumns = Seq("key", "access_token")

  val getById = GetById
  val removeById = RemoveById

  case class CreateOAuth2Info(l: LoginInfo, o: OAuth2Info) extends Statement {
    override val sql = insertSql
    override val values = Seq(l.providerID, l.providerKey) ++ toDataSeq(o)
  }

  case class UpdateOAuth2Info(l: LoginInfo, o: OAuth2Info) extends Statement {
    override val sql = {
      s"update $tableName set access_token = ?, token_type = ?, expires_in = ?, refresh_token = ?, params = ?, created = ? where provider = ? and key = ?"
    }
    override val values = toDataSeq(o) ++ Seq(l.providerID, l.providerKey)
  }

  override protected def fromRow(row: Row) = {
    val params = row.asOpt[String]("params").map { p =>
      Json.parse(p).as[Map[String, JsValue]].map(x => x._1 -> x._2.as[String])
    }
    OAuth2Info(
      accessToken = row.as[String]("access_token"),
      tokenType = row.asOpt[String]("token_type"),
      expiresIn = row.asOpt[Int]("expires_in"),
      refreshToken = row.asOpt[String]("refresh_token"),
      params = params
    )
  }

  override protected def toDataSeq(o: OAuth2Info) = {
    val params = o.params.map(p => Json.prettyPrint(Json.toJson(p)))
    Seq(o.accessToken, o.tokenType, o.expiresIn, o.refreshToken, params, new LocalDateTime())
  }
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:49,代码来源:OAuth2InfoQueries.scala


示例9: User

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

import java.util.UUID

import com.mohiva.play.silhouette.api.{ Identity, LoginInfo }
import org.joda.time.LocalDateTime

case class User(
    id: UUID,
    username: Option[String],
    profiles: Seq[LoginInfo],
    roles: Set[Role] = Set(Role.User),
    created: LocalDateTime
) extends Identity {
  def isGuest = profiles.isEmpty
  def isAdmin = roles.contains(models.user.Role.Admin)
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:18,代码来源:User.scala


示例10: PasswordInfoService

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

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.util.PasswordInfo
import com.mohiva.play.silhouette.impl.daos.DelegableAuthInfoDAO
import jdub.async.Database
import models.queries.PasswordInfoQueries
import play.api.libs.concurrent.Execution.Implicits.defaultContext

import scala.concurrent.Future

object PasswordInfoService extends DelegableAuthInfoDAO[PasswordInfo] {
  override def find(loginInfo: LoginInfo) = Database.query(PasswordInfoQueries.getById(Seq(loginInfo.providerID, loginInfo.providerKey)))

  override def save(loginInfo: LoginInfo, authInfo: PasswordInfo) = {
    Database.transaction { conn =>
      Database.execute(PasswordInfoQueries.UpdatePasswordInfo(loginInfo, authInfo), Some(conn)).flatMap { rowsAffected =>
        if (rowsAffected == 0) {
          Database.execute(PasswordInfoQueries.CreatePasswordInfo(loginInfo, authInfo), Some(conn)).map(x => authInfo)
        } else {
          Future.successful(authInfo)
        }
      }
    }
  }

  override def add(loginInfo: LoginInfo, authInfo: PasswordInfo): Future[PasswordInfo] = {
    Database.execute(PasswordInfoQueries.CreatePasswordInfo(loginInfo, authInfo)).map(x => authInfo)
  }

  override def update(loginInfo: LoginInfo, authInfo: PasswordInfo): Future[PasswordInfo] = {
    Database.execute(PasswordInfoQueries.UpdatePasswordInfo(loginInfo, authInfo)).map(x => authInfo)
  }

  override def remove(loginInfo: LoginInfo) = {
    Database.execute(PasswordInfoQueries.removeById(Seq(loginInfo.providerID, loginInfo.providerKey))).map(x => Unit)
  }
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:39,代码来源:PasswordInfoService.scala


示例11: OpenIdInfoService

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

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.daos.DelegableAuthInfoDAO
import com.mohiva.play.silhouette.impl.providers.OpenIDInfo
import jdub.async.Database
import models.queries.OpenIdInfoQueries
import play.api.libs.concurrent.Execution.Implicits.defaultContext

import scala.concurrent.Future

object OpenIdInfoService extends DelegableAuthInfoDAO[OpenIDInfo] {
  override def find(loginInfo: LoginInfo) = Database.query(OpenIdInfoQueries.getById(Seq(loginInfo.providerID, loginInfo.providerKey)))

  override def save(loginInfo: LoginInfo, authInfo: OpenIDInfo) = {
    Database.transaction { conn =>
      Database.execute(OpenIdInfoQueries.UpdateOpenIdInfo(loginInfo, authInfo), Some(conn)).flatMap { rowsAffected =>
        if (rowsAffected == 0) {
          Database.execute(OpenIdInfoQueries.CreateOpenIdInfo(loginInfo, authInfo), Some(conn)).map(x => authInfo)
        } else {
          Future.successful(authInfo)
        }
      }
    }
  }

  override def add(loginInfo: LoginInfo, authInfo: OpenIDInfo) = {
    Database.execute(OpenIdInfoQueries.CreateOpenIdInfo(loginInfo, authInfo)).map(x => authInfo)
  }

  override def update(loginInfo: LoginInfo, authInfo: OpenIDInfo) = {
    Database.execute(OpenIdInfoQueries.UpdateOpenIdInfo(loginInfo, authInfo)).map(x => authInfo)
  }

  override def remove(loginInfo: LoginInfo) = {
    Database.execute(OpenIdInfoQueries.removeById(Seq(loginInfo.providerID, loginInfo.providerKey))).map(x => Unit)
  }
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:39,代码来源:OpenIdInfoService.scala


示例12: OAuth2InfoService

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

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.daos.DelegableAuthInfoDAO
import com.mohiva.play.silhouette.impl.providers.OAuth2Info
import jdub.async.Database
import models.queries.OAuth2InfoQueries
import play.api.libs.concurrent.Execution.Implicits.defaultContext

import scala.concurrent.Future

object OAuth2InfoService extends DelegableAuthInfoDAO[OAuth2Info] {
  override def find(loginInfo: LoginInfo) = Database.query(OAuth2InfoQueries.getById(Seq(loginInfo.providerID, loginInfo.providerKey)))

  override def save(loginInfo: LoginInfo, authInfo: OAuth2Info) = {
    Database.transaction { conn =>
      Database.execute(OAuth2InfoQueries.UpdateOAuth2Info(loginInfo, authInfo), Some(conn)).flatMap { rowsAffected =>
        if (rowsAffected == 0) {
          Database.execute(OAuth2InfoQueries.CreateOAuth2Info(loginInfo, authInfo), Some(conn)).map(x => authInfo)
        } else {
          Future.successful(authInfo)
        }
      }
    }
  }

  override def add(loginInfo: LoginInfo, authInfo: OAuth2Info) = {
    Database.execute(OAuth2InfoQueries.CreateOAuth2Info(loginInfo, authInfo)).map(x => authInfo)
  }

  override def update(loginInfo: LoginInfo, authInfo: OAuth2Info) = {
    Database.execute(OAuth2InfoQueries.UpdateOAuth2Info(loginInfo, authInfo)).map(x => authInfo)
  }

  override def remove(loginInfo: LoginInfo) = {
    Database.execute(OAuth2InfoQueries.removeById(Seq(loginInfo.providerID, loginInfo.providerKey))).map(x => Unit)
  }
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:39,代码来源:OAuth2InfoService.scala


示例13: OAuth1InfoService

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

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.daos.DelegableAuthInfoDAO
import com.mohiva.play.silhouette.impl.providers.OAuth1Info
import jdub.async.Database
import models.queries.OAuth1InfoQueries
import play.api.libs.concurrent.Execution.Implicits.defaultContext

import scala.concurrent.Future

object OAuth1InfoService extends DelegableAuthInfoDAO[OAuth1Info] {
  override def find(loginInfo: LoginInfo) = Database.query(OAuth1InfoQueries.getById(Seq(loginInfo.providerID, loginInfo.providerKey)))

  override def save(loginInfo: LoginInfo, authInfo: OAuth1Info) = {
    Database.transaction { conn =>
      Database.execute(OAuth1InfoQueries.UpdateOAuth1Info(loginInfo, authInfo), Some(conn)).flatMap { rowsAffected =>
        if (rowsAffected == 0) {
          Database.execute(OAuth1InfoQueries.CreateOAuth1Info(loginInfo, authInfo), Some(conn)).map(x => authInfo)
        } else {
          Future.successful(authInfo)
        }
      }
    }
  }

  override def add(loginInfo: LoginInfo, authInfo: OAuth1Info) = {
    Database.execute(OAuth1InfoQueries.CreateOAuth1Info(loginInfo, authInfo)).map(x => authInfo)
  }

  override def update(loginInfo: LoginInfo, authInfo: OAuth1Info) = {
    Database.execute(OAuth1InfoQueries.UpdateOAuth1Info(loginInfo, authInfo)).map(x => authInfo)
  }

  override def remove(loginInfo: LoginInfo) = {
    Database.execute(OAuth1InfoQueries.removeById(Seq(loginInfo.providerID, loginInfo.providerKey))).map(x => Unit)
  }
} 
开发者ID:laurinka,项目名称:golfmit,代码行数:39,代码来源:OAuth1InfoService.scala


示例14: 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


示例15: 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


示例16: Profile

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

import java.util.UUID

import play.api.libs.json.Json
import com.mohiva.play.silhouette.api.{Identity, LoginInfo}
import com.mohiva.play.silhouette.api.util.PasswordInfo
import com.mohiva.play.silhouette.impl.providers.OAuth1Info

case class Profile(
                    loginInfo:LoginInfo,
                    confirmed: Boolean,
                    email:Option[String],
                    firstName: Option[String],
                    lastName: Option[String],
                    fullName: Option[String],
                    passwordInfo:Option[PasswordInfo],
                    oauth1Info: Option[OAuth1Info],
                    avatarUrl: Option[String]) {
}

case class User(id: UUID, profiles: List[Profile]) extends Identity {
  def profileFor(loginInfo:LoginInfo) = profiles.find(_.loginInfo == loginInfo)
  def fullName(loginInfo:LoginInfo) = profileFor(loginInfo).flatMap(_.fullName)
}

object User {
  implicit val passwordInfoJsonFormat = Json.format[PasswordInfo]
  implicit val oauth1InfoJsonFormat = Json.format[OAuth1Info]
  implicit val profileJsonFormat = Json.format[Profile]
  implicit val userJsonFormat = Json.format[User]
} 
开发者ID:tm-sukehiro,项目名称:play-hands-on,代码行数:33,代码来源:User.scala


示例17: UserService

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

import java.util.UUID
import javax.inject._

import scala.concurrent.Future

import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.services.IdentityService
import com.mohiva.play.silhouette.impl.providers.CommonSocialProfile

import play.api.Play.current
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.modules.reactivemongo.ReactiveMongoApi
import play.modules.reactivemongo.json.collection.JSONCollection

import daos.UserDao
import models.{User,Profile}

class UserService @Inject() (userDao:UserDao) extends IdentityService[User] {
  def retrieve(loginInfo:LoginInfo):Future[Option[User]] = userDao.find(loginInfo)
  def save(user:User) = userDao.save(user)
  def find(id:UUID) = userDao.find(id)
  def confirm(loginInfo:LoginInfo) = userDao.confirm(loginInfo)
  def link(user:User, socialProfile:CommonSocialProfile) = {
    val profile = toProfile(socialProfile)
    if (user.profiles.exists(_.loginInfo == profile.loginInfo)) Future.successful(user) else userDao.link(user, profile)
  }

  def save(socialProfile:CommonSocialProfile) = {
    val profile = toProfile(socialProfile)
    userDao.find(profile.loginInfo).flatMap {
      case None => userDao.save(User(UUID.randomUUID(), List(profile)))
      case Some(user) => userDao.update(profile)
    }
  }

  private def toProfile(p:CommonSocialProfile) = Profile(
    loginInfo = p.loginInfo,
    confirmed = true,
    email = p.email,
    firstName = p.firstName,
    lastName = p.lastName,
    fullName = p.fullName,
    passwordInfo = None,
    oauth1Info = None,
    avatarUrl = p.avatarURL
  )
} 
开发者ID:tm-sukehiro,项目名称:play-hands-on,代码行数:50,代码来源:UserService.scala


示例18: UserDaoSpec

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

import com.mohiva.play.silhouette.api.LoginInfo

import scala.concurrent.Await
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.test._
import play.api.test.Helpers._
import org.specs2.mutable.Specification

class UserDaoSpec extends Specification with DaoSpecResources {

  "UserDao" should {
    "save users and find them by userId" in withUserDao { userDao =>
      val future = for {
        _ <- userDao.save(credentialsTestUser)
        maybeUser <- userDao.find(credentialsTestUser.id)
      } yield maybeUser.map(_ == credentialsTestUser)
      Await.result(future, timeout) must beSome(true)
    }

    "save users and find them by loginInfo" in withUserDao { userDao =>
      val future = for {
        _ <- userDao.save(credentialsTestUser)
        maybeUser <- userDao.find(LoginInfo("credentials","[email protected]"))
      } yield maybeUser.map(_ == credentialsTestUser)
      Await.result(future, timeout) must beSome(true)
    }

    "confirm a profile" in withUserDao { userDao =>
      val future = for {
        user <- userDao.save(credentialsTestUser)
        user <- userDao.confirm(loginInfo)
      } yield user
      val user = Await.result(future, timeout)
      user.profiles(0).confirmed === true
    }

    "link a new profile to an existing user" in withUserDao { userDao =>
      val future = for {
        user <- userDao.save(credentialsTestUser)
        user <- userDao.link(user, testOauth1Profile)
      } yield user
      val user = Await.result(future, timeout)
      user.profiles.length mustEqual 2
      user.profiles.map(_.loginInfo) must contain(loginInfo, oauth1LoginInfo)
    }

    "update an existing profile" in withUserDao { userDao =>
      val copy = testPasswordProfile.copy(firstName = Some("Johnny"))
      val future = for {
        user <- userDao.save(credentialsTestUser)
        user <- userDao.update(copy)
      } yield user
      val user = Await.result(future, timeout)
      user.profiles(0).firstName === Some("Johnny")
    }
  }
} 
开发者ID:tm-sukehiro,项目名称:play-hands-on,代码行数:60,代码来源:UserDaoSpec.scala


示例19: PersistentJWTAuthenticator

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

import com.mohiva.play.silhouette.api.{ ExpirableAuthenticator, LoginInfo, StorableAuthenticator }
import com.mohiva.play.silhouette.api.util.CacheLayer

import scala.concurrent.Future
import scala.concurrent.duration.{ Duration, FiniteDuration }
import scala.reflect.ClassTag
import javax.inject.Inject

import com.mohiva.play.silhouette.impl.authenticators.{ JWTAuthenticator, JWTAuthenticatorSettings }
import com.mohiva.play.silhouette.impl.daos.AuthenticatorDAO
import org.joda.time.DateTime
import play.api.libs.json._

import scala.concurrent.ExecutionContext.Implicits.global
import reactivemongo.api._
import play.modules.reactivemongo.json._
import play.modules.reactivemongo.json.collection._

case class PersistentJWTAuthenticator(
  id: String,
  loginInfo: LoginInfo,
  lastUsedDateTime: DateTime,
  expirationDateTime: DateTime,
  idleTimeout: Option[FiniteDuration])
    extends StorableAuthenticator with ExpirableAuthenticator {

  
  override def remove(id: String): Future[Unit] = {
    collection.remove(Json.obj("id" -> id))
    Future.successful(() => Unit)
  }
} 
开发者ID:pawank,项目名称:play-silhouette-mongodb-multi-project-sbt,代码行数:36,代码来源:AuthDbDAO.scala


示例20: UserServiceImpl

//设置package包名称以及导入依赖的类
package scalafiddle.server.models.services
import java.util.UUID
import javax.inject.{Inject, Named}

import akka.actor._
import akka.pattern.ask
import akka.util.Timeout
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.CommonSocialProfile
import play.api.Logger

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.concurrent.duration._
import scala.util.{Success, Try}
import scalafiddle.server._
import scalafiddle.server.models.User

class UserServiceImpl @Inject()(@Named("persistence") persistence: ActorRef) extends UserService {
  implicit val timeout = Timeout(15.seconds)
  val log              = Logger(getClass)

  
  override def save(profile: CommonSocialProfile): Future[User] = {
    log.debug(s"User $profile logged in")
    val user = User(UUID.randomUUID().toString,
                    profile.loginInfo,
                    profile.firstName,
                    profile.lastName,
                    profile.fullName,
                    profile.email,
                    profile.avatarURL,
                    true)
    ask(persistence, AddUser(user)).mapTo[Try[User]].map {
      case Success(u) =>
        u
      case _ =>
        throw new Exception("Unable to save user")
    }
  }

  override def retrieve(loginInfo: LoginInfo): Future[Option[User]] = {
    ask(persistence, FindUserLogin(loginInfo)).mapTo[Try[User]].map {
      case Success(user) =>
        Some(user)
      case _ =>
        None
    }
  }
} 
开发者ID:scalafiddle,项目名称:scalafiddle-editor,代码行数:51,代码来源:UserServiceImpl.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala TableName类代码示例发布时间:2022-05-23
下一篇:
Scala Word2Vec类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap