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

Scala CommonSocialProfile类代码示例

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

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



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

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


示例2: SimpleUserService

//设置package包名称以及导入依赖的类
package com.clemble.loveit.user.service

import com.clemble.loveit.common.model.{UserID}
import com.clemble.loveit.user.model._
import com.clemble.loveit.user.service.repository.UserRepository
import javax.inject.{Inject, Singleton}

import com.mohiva.play.silhouette.impl.providers.CommonSocialProfile

import scala.concurrent.{ExecutionContext, Future}

@Singleton
case class SimpleUserService @Inject()(userRepo: UserRepository, implicit val ec: ExecutionContext) extends UserService {

  override def findById(id: UserID): Future[Option[User]] = {
    userRepo.findById(id)
  }

  def createOrUpdateUser(profile: CommonSocialProfile): Future[Either[UserIdentity, UserIdentity]] = {
    for {
      existingUserOpt <- userRepo.retrieve(profile.loginInfo)
      user <- existingUserOpt.
        map(identity => Future.successful(identity)).
        getOrElse(userRepo.save(User from profile).map(_.toIdentity()))
    } yield {
      if (existingUserOpt.isDefined) {
        Left(user)
      } else {
        Right(user)
      }
    }
  }
} 
开发者ID:thankyo,项目名称:thank,代码行数:34,代码来源:SimpleUserService.scala


示例3: UserControllerSpec

//设置package包名称以及导入依赖的类
package com.clemble.loveit.user.controller

import com.clemble.loveit.common.ControllerSpec
import com.clemble.loveit.user.model.User
import com.mohiva.play.silhouette.impl.providers.CommonSocialProfile
import org.junit.runner.RunWith
import org.specs2.concurrent.ExecutionEnv
import org.specs2.runner.JUnitRunner
import play.api.libs.json.Json
import com.clemble.loveit.user.model.User.socialProfileJsonFormat
import play.api.test.FakeRequest

@RunWith(classOf[JUnitRunner])
class UserControllerSpec(implicit ee: ExecutionEnv) extends ControllerSpec {

  "CREATE" should {

    "Support single create" in {
      val socialProfile = someRandom[CommonSocialProfile]
      val user = createUser(socialProfile)

      val savedUser = getMyUser(user)
      val expectedUser = (User from socialProfile).copy(id = savedUser.id, created = savedUser.created)
      savedUser must beEqualTo(expectedUser)
    }

    "Return same user on the same authentication" in {
      val socialProfile = someRandom[CommonSocialProfile]
      val firstUser = createUser(socialProfile)
      val firstAuth = ControllerSpec.getUser(firstUser)

      val secondUser = createUser(socialProfile)
      val secondAuth = ControllerSpec.getUser(secondUser)

      firstAuth shouldNotEqual secondAuth
      secondUser shouldEqual firstUser
    }

    "sets a userId as a cookie" in {
      val json = Json.toJson(someRandom[CommonSocialProfile])
      val req = FakeRequest(POST, "/api/v1/auth/authenticate/test").
        withJsonBody(json)
      val res = await(route(application, req).get)

      ControllerSpec.setUser(res)
      val setCookie = res.header.headers.get(SET_COOKIE)

      setCookie shouldNotEqual None

      val userCookie = setCookie.get
      val userId = setCookie.get.substring(7, userCookie.indexOf(";"))
      val expectedId = getMyUser(userId).id
      userId shouldEqual expectedId
    }

  }

} 
开发者ID:thankyo,项目名称:thank,代码行数:59,代码来源:UserControllerSpec.scala


示例4: someUser

//设置package包名称以及导入依赖的类
package com.clemble.loveit.common

import com.clemble.loveit.common.model.{Resource, UserID}
import com.clemble.loveit.thank.service.ROService
import com.clemble.loveit.user.controller.SocialAuthController
import com.clemble.loveit.user.model.UserIdentity
import com.clemble.loveit.user.service.UserService
import com.clemble.loveit.user.service.repository.UserRepository
import com.mohiva.play.silhouette.impl.providers.CommonSocialProfile

trait ServiceSpec extends ThankSpecification {

  lazy val authController = dependency[SocialAuthController]
  lazy val userService = dependency[UserService]
  lazy val userRep = dependency[UserRepository]

  lazy val resService = dependency[ROService]

  def someUser(socialProfile: CommonSocialProfile = someRandom[CommonSocialProfile]): UserIdentity = {
    await(userService.createOrUpdateUser(socialProfile)) match {
      case Left(user) => user
      case Right(user) => user
    }
  }

  def createUser(socialProfile: CommonSocialProfile = someRandom[CommonSocialProfile]): UserID = {
    val userIdentity = await(userService.createOrUpdateUser(socialProfile))
    userIdentity match {
      case Left(user) => user.id
      case Right(user) => user.id
    }
  }

  def assignOwnership(user: UserID, res: Resource) = await(resService.assignOwnership(user, res))
} 
开发者ID:thankyo,项目名称:thank,代码行数:36,代码来源:ServiceSpec.scala


示例5: ShopIdentityServiceImpl

//设置package包名称以及导入依赖的类
package silhouette.shopify.service

import javax.inject.Singleton

import com.google.inject.Inject
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.CommonSocialProfile
import silhouette.shopify.Shop
import silhouette.shopify.dao.ShopDAO

import scala.concurrent.Future

@Singleton
class ShopIdentityServiceImpl @Inject() (shopDao: ShopDAO) extends ShopIdentityService {
  override def retrieve(loginInfo: LoginInfo) = {
    shopDao.findByLoginInfo(loginInfo)
  }

  override def save(shop: Shop): Future[Shop] = {
    shopDao.save(shop)
  }

  override def save(profile: CommonSocialProfile): Future[Shop] = {
    shopDao.save(Shop(
      loginInfo = profile.loginInfo,
      name = profile.fullName.getOrElse("Unknown Shop Name"),
      myshopifyDomain = profile.loginInfo.providerKey
    ))
  }
} 
开发者ID:pequalsnp,项目名称:play-scala-shopify-app,代码行数:31,代码来源:ShopIdentityServiceImpl.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala SessionKeys类代码示例发布时间:2022-05-23
下一篇:
Scala MatchResult类代码示例发布时间: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