本文整理汇总了Scala中com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry类的典型用法代码示例。如果您正苦于以下问题:Scala SocialProviderRegistry类的具体用法?Scala SocialProviderRegistry怎么用?Scala SocialProviderRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SocialProviderRegistry类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Application
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import scala.concurrent.Future
import com.mohiva.play.silhouette.api.Silhouette
import com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry
import play.api.mvc._
import play.api.i18n.{I18nSupport, MessagesApi}
import utils.auth.CookieEnv
class Application @Inject() (
val messagesApi: MessagesApi,
silhouette: Silhouette[CookieEnv],
socialProviderRegistry: SocialProviderRegistry,
implicit val webJarAssets: WebJarAssets) extends Controller with I18nSupport {
import silhouette._
def index = UserAwareAction.async { implicit request =>
Future.successful(Ok(views.html.index(request.identity, request.authenticator.map(_.loginInfo))))
}
def profile = SecuredAction { implicit request =>
Ok(views.html.profile(request.identity, request.authenticator.loginInfo, socialProviderRegistry))
}
}
示例2: messagesApi
//设置package包名称以及导入依赖的类
package controllers
import com.mohiva.play.silhouette.api.actions._
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.services.AvatarService
import com.mohiva.play.silhouette.api.util.{ Clock, PasswordHasher }
import com.mohiva.play.silhouette.impl.providers.{ CredentialsProvider, SocialProviderRegistry }
import com.softwaremill.macwire._
import models.daos.AuthTokenDAOImpl
import models.services.{ AuthTokenServiceImpl, UserService }
import play.api.Configuration
import play.api.i18n.MessagesApi
import utils.auth.{ CustomSecuredErrorHandler, CustomUnsecuredErrorHandler }
trait ControllerModule {
lazy val authToken = new AuthTokenDAOImpl
lazy val authTokenService = new AuthTokenServiceImpl(authToken, clock)
lazy val securedErrorHandler: SecuredErrorHandler = wire[CustomSecuredErrorHandler]
lazy val unSecuredErrorHandler: UnsecuredErrorHandler = wire[CustomUnsecuredErrorHandler]
lazy val userAwareAction = new DefaultUserAwareAction(new DefaultUserAwareRequestHandler)
lazy val securedAction: SecuredAction = new DefaultSecuredAction(new DefaultSecuredRequestHandler(securedErrorHandler))
lazy val unsecuredAction: UnsecuredAction = new DefaultUnsecuredAction(new DefaultUnsecuredRequestHandler(unSecuredErrorHandler))
def messagesApi: MessagesApi
def socialProviderRegistry: SocialProviderRegistry
def userService: UserService
def authInfoRepository: AuthInfoRepository
def credentialsProvider: CredentialsProvider
def configuration: Configuration
def clock: Clock
def avatarService: AvatarService
def passwordHasher: PasswordHasher
}
示例3: messagesApi
//设置package包名称以及导入依赖的类
package com.github.jacobono.modules
import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.services.AvatarService
import com.mohiva.play.silhouette.api.util.Clock
import com.mohiva.play.silhouette.api.util.PasswordHasher
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import com.mohiva.play.silhouette.impl.providers.{ CredentialsProvider, SocialProviderRegistry }
import com.softwaremill.macwire._
import play.api.Configuration
import play.api.i18n.MessagesApi
import com.github.jacobono.controllers._
import com.github.jacobono.models.User
import com.github.jacobono.models.services.UserService
import com.github.jacobono.utils.CSRFHelper
trait ControllerModule {
def messagesApi: MessagesApi
def silhouetteEnvironment: Environment[User, CookieAuthenticator]
def socialProviderRegistry: SocialProviderRegistry
def csrfHelper: CSRFHelper
def userService: UserService
def authInfoRepository: AuthInfoRepository
def credentialsProvider: CredentialsProvider
def configuration: Configuration
def clock: Clock
def avatarService: AvatarService
def passwordHasher: PasswordHasher
lazy val applicationController: Application = wire[Application]
lazy val credentialsAuthController: CredentialsAuthController = wire[CredentialsAuthController]
lazy val signUpController: SignUpController = wire[SignUpController]
lazy val socialAuthController: SocialAuthController = wire[SocialAuthController]
}
示例4: ProductController
//设置package包名称以及导入依赖的类
package controllers
import scala.concurrent.Future
import javax.inject._
import com.mohiva.play.silhouette.api.Silhouette
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.util.Clock
import com.mohiva.play.silhouette.impl.providers.{CredentialsProvider, SocialProviderRegistry}
import forms.ProductForm
import models.Product
import models.daos.ProductDAO
import models.services.UserService
import play.api.Configuration
import play.api.i18n.I18nSupport
import play.api.i18n.MessagesApi
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc.Controller
import utils.auth.DefaultEnv
@Singleton
class ProductController @Inject()(val messagesApi: MessagesApi,
silhouette: Silhouette[DefaultEnv],
userService: UserService,
authInfoRepository: AuthInfoRepository,
credentialsProvider: CredentialsProvider,
socialProviderRegistry: SocialProviderRegistry,
configuration: Configuration,
clock: Clock,
productDAO: ProductDAO,
implicit val webJarAssets: WebJarAssets)
extends Controller with I18nSupport {
private val logger = org.slf4j.LoggerFactory.getLogger(this.getClass)
def list = silhouette.SecuredAction.async { implicit request =>
productDAO.all().map { products =>
logger.info(s"Calling index: products = ${products}")
Ok(views.html.products.list(request.identity, ProductForm.form, products))
}
}
def add = silhouette.SecuredAction.async { implicit request =>
ProductForm.form.bindFromRequest.fold(
form => Future.successful(BadRequest(views.html.products.details(request.identity,ProductForm.form))),
data => {
val product = Product(
ean = data.ean,
name = data.name,
description = data.description
)
productDAO.insert(product).map(_ => Redirect(routes.ProductController.list))
}
)
}
}
示例5: InvitationController
//设置package包名称以及导入依赖的类
package com.clemble.loveit.user.controller
import javax.inject.{Inject, Singleton}
import com.clemble.loveit.common.util.AuthEnv
import com.clemble.loveit.user.model.Invitation
import com.clemble.loveit.user.service.InvitationService
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.{Logger, Silhouette}
import com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry
import play.api.libs.json._
import play.api.mvc.Controller
import scala.concurrent.{ExecutionContext, Future}
@Singleton
case class InvitationController @Inject()(
invitationService: InvitationService,
silhouette: Silhouette[AuthEnv],
authInfoRepository: AuthInfoRepository,
socialProviderRegistry: SocialProviderRegistry,
implicit val ec: ExecutionContext
) extends Controller with Logger {
def invite() = silhouette.SecuredAction.async(parse.json[JsObject].map(_ \ "linkOrEmail"))(implicit req => {
req.body match {
case JsDefined(JsString(linkOrEmail)) =>
val inv = Invitation(linkOrEmail, req.identity.id)
invitationService.
save(inv).
map(res => Ok(Json.toJson(res)))
case _ =>
Future.successful(BadRequest("linkOrEmail field is missing"))
}
})
}
示例6: SignInView
//设置package包名称以及导入依赖的类
package views
import com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry
import controllers.routes
import play.api.i18n.{Lang, Messages}
import play.api.mvc.RequestHeader
import play.twirl.api.Html
import views.styles.SignInStyleSheet
import scala.concurrent.{ExecutionContext, Future}
import scalacss.DevDefaults._
import scalacss.ScalatagsCss._
import scalatags.Text
import scalatags.Text.all._
object SignInView {
def apply(socialProviderRegistry: SocialProviderRegistry)
(implicit request: RequestHeader, messages: Messages, lang: Lang): Html = {
val headers = Seq(
SignInStyleSheet.render[scalatags.Text.TypedTag[String]]
)
val errorSpot: Frag = request.flash.get("error") match {
case Some(errorMessage) => div(`class` := "alert alert-danger center-block", maxWidth := 480)(
errorMessage
)
case None => UnitFrag(Unit)
}
val body: Frag = div(`class` := "container", paddingTop := 100)(
div(`class` := "panel panel-default center-block", maxWidth := 480)(
div(`class` := "panel-heading")(messages("sign-in")),
div(`class` := "panel-body")(
a(href := routes.AuthController.authenticate("google").url)(
img(src := "/assets/images/google_sign_in.png", `class` := "img-responsive center-block")
),
div(`class` := "text-center")(messages("or")),
a(href := routes.AuthController.authenticate("facebook").url)(
img(src := "/assets/images/facebook_sign_in.png", `class` := "img-responsive center-block")
)
)
),
errorSpot
)
MainTemplate(messages("sign-in"), "sign-in", headers, body, None)
}
}
示例7: CookieCredentialsTestController
//设置package包名称以及导入依赖的类
package controllers.authentication
import javax.inject.Inject
import com.mohiva.play.silhouette.api.{ Environment, LogoutEvent, Silhouette }
import com.mohiva.play.silhouette.impl.authenticators.{JWTAuthenticator, CookieAuthenticator}
import com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry
import models.tenant.AuthCrewUser
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent}
import scala.concurrent.Future
class CookieCredentialsTestController @Inject()(
val messagesApi: MessagesApi,
val env: Environment[AuthCrewUser, CookieAuthenticator],
socialProviderRegistry: SocialProviderRegistry
)
extends Silhouette[AuthCrewUser, CookieAuthenticator]
{
def index: Action[AnyContent] = SecuredAction.async { implicit request =>
Future.successful(Ok(Json.obj("message" -> Messages("authentication.successful"))))
}
}
示例8: JWTCredentialsTestController
//设置package包名称以及导入依赖的类
package controllers.authentication
import javax.inject.Inject
import com.mohiva.play.silhouette.api.{ Environment, LogoutEvent, Silhouette }
import com.mohiva.play.silhouette.impl.authenticators.JWTAuthenticator
import com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry
import models.tenant.AuthCrewUser
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.json.Json
import play.api.mvc.{Action, AnyContent}
import scala.concurrent.Future
class JWTCredentialsTestController @Inject()(
val messagesApi: MessagesApi,
val env: Environment[AuthCrewUser, JWTAuthenticator],
socialProviderRegistry: SocialProviderRegistry
)
extends Silhouette[AuthCrewUser, JWTAuthenticator]
{
def index: Action[AnyContent] = SecuredAction.async { implicit request =>
Future.successful(Ok(Json.obj("message" -> Messages("authentication.successful"))))
}
}
示例9: ChildController
//设置package包名称以及导入依赖的类
package controllers.api
import java.util.UUID
import com.google.inject.Inject
import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.impl.authenticators.{JWTAuthenticator, CookieAuthenticator}
import com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry
import dao.RepoFor
import models.tenant.{AuthCrewUser, Child}
import models.tenant.persistable.PersistableChild
import play.api._
import play.api.db.slick.DatabaseConfigProvider
import play.api.i18n.MessagesApi
import play.api.libs.json._
class ChildController @Inject()(dbConfigProvider: DatabaseConfigProvider,
messagesApi: MessagesApi,
env: Environment[AuthCrewUser, JWTAuthenticator],
socialProviderRegistry: SocialProviderRegistry)
extends GenericSecureApiController(dbConfigProvider, messagesApi, env, socialProviderRegistry)
{
override type Id = UUID
override type Model = Child
override type PersistedModel = PersistableChild
override val repo: RepoFor[PersistableChild, Id] = dao.tenant.ChildRepo
override def convertToDisplayable: PersistableChild => Child = _.convert
override def convertToPersistable: Child => PersistableChild = PersistableChild.build
override implicit val reads: Reads[Model] = models.tenant.json.ChildJson.childReads
override implicit val writes: Writes[Model] = models.tenant.json.ChildJson.childWrites
}
示例10: GenericSecureApiController
//设置package包名称以及导入依赖的类
package controllers.api
import com.mohiva.play.silhouette.api.{Silhouette, Environment}
import com.mohiva.play.silhouette.impl.authenticators.JWTAuthenticator
import com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry
import models.tenant.AuthCrewUser
import org.postgresql.util.PSQLException
import play.api.db.slick.DatabaseConfigProvider
import play.api.i18n.MessagesApi
import play.api.libs.json.Json
import play.api.mvc.{AnyContent, Action}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
abstract class GenericSecureApiController(dbConfigProvider: DatabaseConfigProvider,
messagesApi: MessagesApi,
env: Environment[AuthCrewUser, JWTAuthenticator],
socialProviderRegistry: SocialProviderRegistry)
extends GenericApiController(dbConfigProvider, messagesApi, env, socialProviderRegistry)
with Silhouette[AuthCrewUser, JWTAuthenticator]
{
import dbConfig.driver.api._
override def update: Action[Model] = SecuredAction.async(parse.json(reads)) {
entity =>
db.run(convertToPersistable(entity.body).update).map(updated => Ok(Json.toJson(convertToDisplayable(updated))))
}
override def delete(id: Id): Action[AnyContent] = SecuredAction.async {
db.run(repo.filterById(id).delete).map {
i =>
if (i == 0) NotFound else Ok
}
}
override def getById(id: Id): Action[AnyContent] = SecuredAction.async {
db.run(repo.findById(id)).map(entity => Ok(Json.toJson(convertToDisplayable(entity))))
}
override def getAll: Action[AnyContent] = SecuredAction.async {
val all = db.run(repo.tableQuery.result)
all.map(all => Ok(Json.toJson(all.map(convertToDisplayable))))
}
override def create: Action[Model] = SecuredAction.async(parse.json(reads)) {
parsed =>
db.run(convertToPersistable(parsed.body).save.asTry).map {
case Success(created) => Ok(Json.toJson(convertToDisplayable(created)))
case Failure(e: PSQLException) if e.getSQLState == "23505" => InternalServerError("Unique key violation: unique key already exists in the database.")
case Failure(t: PSQLException) => InternalServerError("PSQL error.")
}
}
}
示例11: CrewController
//设置package包名称以及导入依赖的类
package controllers.api
import java.util.UUID
import com.google.inject.Inject
import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.impl.authenticators.JWTAuthenticator
import com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry
import dao.RepoFor
import models.tenant.persistable.PersistableCrew
import models.tenant.{Crew, AuthCrewUser}
import play.api._
import play.api.db.slick.DatabaseConfigProvider
import play.api.i18n.MessagesApi
import play.api.libs.json.{Writes, Reads}
import play.api.mvc._
class CrewController @Inject()(dbConfigProvider: DatabaseConfigProvider,
messagesApi: MessagesApi,
env: Environment[AuthCrewUser, JWTAuthenticator],
socialProviderRegistry: SocialProviderRegistry)
extends GenericSecureApiController(dbConfigProvider, messagesApi, env, socialProviderRegistry)
{
override type Id = UUID
override type Model = Crew
override type PersistedModel = PersistableCrew
override def convertToPersistable = PersistableCrew.build
override def convertToDisplayable = _.convert
override val repo: RepoFor[PersistedModel, Id] = dao.tenant.CrewRepo
override implicit val reads: Reads[Model] = models.tenant.json.CrewJson.crewReads
override implicit val writes: Writes[Model] = models.tenant.json.CrewJson.crewWrites
}
示例12: TenantController
//设置package包名称以及导入依赖的类
package controllers.api
import java.util.UUID
import com.google.inject.Inject
import com.mohiva.play.silhouette.api.Environment
import com.mohiva.play.silhouette.impl.authenticators.{JWTAuthenticator, CookieAuthenticator}
import com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry
import dao.RepoFor
import models.admin.Tenant
import models.tenant.AuthCrewUser
import play.api.db.slick.DatabaseConfigProvider
import play.api.i18n.MessagesApi
import play.api.libs.json._
class TenantController @Inject()(dbConfigProvider: DatabaseConfigProvider,
messagesApi: MessagesApi,
env: Environment[AuthCrewUser, JWTAuthenticator],
socialProviderRegistry: SocialProviderRegistry)
extends GenericApiController(dbConfigProvider, messagesApi, env, socialProviderRegistry)
{
override type Id = UUID
override type Model = Tenant
override type PersistedModel = Tenant
override def convertToPersistable = identity
override def convertToDisplayable = identity
override val repo: RepoFor[Tenant, Id] = dao.admin.TenantRepo
override implicit val reads: Reads[Model] = models.admin.json.TenantJson.tenantReads
override implicit val writes: Writes[Model] = models.admin.json.TenantJson.tenantWrites
}