本文整理汇总了Scala中com.mohiva.play.silhouette.api.repositories.AuthInfoRepository类的典型用法代码示例。如果您正苦于以下问题:Scala AuthInfoRepository类的具体用法?Scala AuthInfoRepository怎么用?Scala AuthInfoRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AuthInfoRepository类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ChangePasswordController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.api.exceptions.ProviderException
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.util.{ Credentials, PasswordHasherRegistry, PasswordInfo }
import com.mohiva.play.silhouette.impl.providers.CredentialsProvider
import models.services.UserService
import play.api.i18n.{ I18nSupport, Messages, MessagesApi }
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc.Controller
import utils.auth.{ DefaultEnv, WithProvider }
import scala.concurrent.Future
class ChangePasswordController @Inject() (
val messagesApi: MessagesApi,
silhouette: Silhouette[DefaultEnv],
userService: UserService,
credentialsProvider: CredentialsProvider,
authInfoRepository: AuthInfoRepository,
passwordHasherRegistry: PasswordHasherRegistry
)
extends Controller with I18nSupport {
def view = silhouette.SecuredAction(WithProvider[DefaultEnv#A](CredentialsProvider.ID)) { implicit request =>
Ok(views.html.changePassword(new myform.MyChangePasswordForm(), request.identity))
}
def submit = silhouette.SecuredAction(WithProvider[DefaultEnv#A](CredentialsProvider.ID)).async { implicit request =>
new myform.MyChangePasswordForm().bindFromRequest match {
case form: myform.MyChangePasswordForm => Future.successful(BadRequest(views.html.changePassword(form, request.identity)))
case data: myform.MyChangePasswordFormData => {
val (currentPassword, newPassword) = (data.currentPassword, data.newPassword)
val credentials = Credentials(request.identity.email.getOrElse(""), currentPassword)
credentialsProvider.authenticate(credentials).flatMap { loginInfo =>
val passwordInfo = passwordHasherRegistry.current.hash(newPassword)
authInfoRepository.update[PasswordInfo](loginInfo, passwordInfo).map { _ =>
Redirect(routes.ChangePasswordController.view()).flashing("success" -> Messages("password.changed"))
}
}.recover {
case e: ProviderException =>
Redirect(routes.ChangePasswordController.view()).flashing("error" -> Messages("current.password.invalid"))
}
}
}
}
}
示例2: ResetPasswordController
//设置package包名称以及导入依赖的类
package controllers
import java.util.UUID
import javax.inject.Inject
import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.util.{ PasswordHasherRegistry, PasswordInfo }
import com.mohiva.play.silhouette.impl.providers.CredentialsProvider
import models.services.{ AuthTokenService, UserService }
import play.api.i18n.{ I18nSupport, Messages, MessagesApi }
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc.Controller
import utils.auth.DefaultEnv
import scala.concurrent.Future
class ResetPasswordController @Inject() (
val messagesApi: MessagesApi,
silhouette: Silhouette[DefaultEnv],
userService: UserService,
authInfoRepository: AuthInfoRepository,
passwordHasherRegistry: PasswordHasherRegistry,
authTokenService: AuthTokenService
)
extends Controller with I18nSupport {
def view(token: UUID) = silhouette.UnsecuredAction.async { implicit request =>
authTokenService.validate(token).map {
case Some(authToken) => Ok(views.html.resetPassword(new myform.MyResetPasswordForm(), token))
case None => Redirect(routes.SignInController.view()).flashing("error" -> Messages("invalid.reset.link"))
}
}
def submit(token: UUID) = silhouette.UnsecuredAction.async { implicit request =>
authTokenService.validate(token).flatMap {
case Some(authToken) =>
new myform.MyResetPasswordForm().bindFromRequest match {
case form: myform.MyResetPasswordForm => Future.successful(BadRequest(views.html.resetPassword(form, token)))
case data: myform.MyResetPasswordFormData => userService.retrieve(authToken.userID).flatMap {
case Some(user) if user.loginInfo.providerID == CredentialsProvider.ID =>
val passwordInfo = passwordHasherRegistry.current.hash(data.password)
authInfoRepository.update[PasswordInfo](user.loginInfo, passwordInfo).map { _ =>
Redirect(routes.SignInController.view()).flashing("success" -> Messages("password.reset"))
}
case _ => Future.successful(Redirect(routes.SignInController.view()).flashing("error" -> Messages("invalid.reset.link")))
}
}
case None => Future.successful(Redirect(routes.SignInController.view()).flashing("error" -> Messages("invalid.reset.link")))
}
}
}
示例3: 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
}
示例4: 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]
}
示例5: 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))
}
)
}
}
示例6: 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"))
}
})
}
示例7: Startup
//设置package包名称以及导入依赖的类
package jobs
import java.util.UUID
import javax.inject.Inject
import javax.inject.Singleton
import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.util.PasswordHasherRegistry
import com.mohiva.play.silhouette.impl.providers._
import models.{ User, UserMajor }
import models.MajorType._
import models.services.{ AuthTokenService, UserService, MajorService, UserMajorService }
import utils.auth.DefaultEnv
import shared.Util.reverseEffect
import play.api.libs.concurrent.Execution.Implicits._
@Singleton
class Startup @Inject() (
silhouette: Silhouette[DefaultEnv],
userService: UserService,
majorService: MajorService,
userMajorService: UserMajorService,
authInfoRepository: AuthInfoRepository,
authTokenService: AuthTokenService,
passwordHasherRegistry: PasswordHasherRegistry) {
//Create Sample user
//Major: ??2013, ??2013
//
val loginInfo = LoginInfo(CredentialsProvider.ID, "[email protected]")
val authInfo = passwordHasherRegistry.current.hash("asdf")
for {
fmOption <- majorService.find("??????", FirstMajor, 2013)
smOption <- majorService.find("????????", SecondMajor, 2013)
userData = User(
userID = UUID.fromString("42944783-ee3f-4a92-85b9-777c94d9dc5e"),
loginInfo = loginInfo,
email = Some("[email protected]"),
classYear = 2013,
semester = 5,
activated = true
)
userMajors = Seq(fmOption, smOption).filterNot(_.isEmpty).map(_.get).map(m => UserMajor(userData.userID, m.id))
savedUserMajors <- reverseEffect(userMajors.map(userMajor => userMajorService.save(userMajor)))
user <- userService.save(userData)
authInfo <- authInfoRepository.add(loginInfo, authInfo)
authToken <- authTokenService.create(user.userID)
} yield ()
}
示例8: SignUp
//设置package包名称以及导入依赖的类
package controllers
import java.util.UUID
import javax.inject.Inject
import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.util.PasswordHasher
import com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator
import com.mohiva.play.silhouette.impl.providers._
import forms.SignUpForm
import models.User
import models.daos.UserDAO
import play.api.i18n.{Messages, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc.Action
import scala.concurrent.Future
class SignUp @Inject()(val messagesApi: MessagesApi,
val env: Environment[User, SessionAuthenticator],
userDAO: UserDAO,
authInfoRepository: AuthInfoRepository,
passwordHasher: PasswordHasher)
extends Silhouette[User, SessionAuthenticator] {
def signUp = Action.async { implicit request =>
SignUpForm.form.bindFromRequest.fold(
form => Future.successful(BadRequest(views.html.signUp(form))),
data => {
val loginInfo = LoginInfo(CredentialsProvider.ID, data.email)
userDAO.retrieve(loginInfo).flatMap {
case Some(_) =>
Future.successful(Redirect(routes.Application.signUp()).flashing("error" -> Messages("user.exists")))
case None =>
val authInfo = passwordHasher.hash(data.password)
val user = User(
id = UUID.randomUUID(),
name = data.name,
email = data.email
)
for {
user <- userDAO.save(user)
_ <- authInfoRepository.add(loginInfo, authInfo)
authenticator <- env.authenticatorService.create(loginInfo)
value <- env.authenticatorService.init(authenticator)
result <- env.authenticatorService.embed(value, Redirect(routes.Application.dashboard()))
} yield {
env.eventBus.publish(SignUpEvent(user, request, request2Messages))
env.eventBus.publish(LoginEvent(user, request, request2Messages))
result
}
}
}
)
}
}
示例9: AuthenticationController
//设置package包名称以及导入依赖的类
package controllers
import java.util.UUID
import javax.inject.Inject
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.api.util.PasswordHasher
import com.mohiva.play.silhouette.api.{LoginEvent, LoginInfo, SignUpEvent, Silhouette}
import com.mohiva.play.silhouette.impl.providers.CredentialsProvider
import model.{LoginUser, User}
import modules.JWTEnv
import play.api.i18n.MessagesApi
import play.api.libs.json.{JsError, Json}
import play.api.mvc.{Action, Controller}
import service.UserService
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
class AuthenticationController @Inject()(val messagesApi: MessagesApi,
silhouette: Silhouette[JWTEnv],
userService: UserService,
authInfoRepository: AuthInfoRepository,
passwordHasher: PasswordHasher) extends Controller {
implicit val signUpFormat = Json.format[LoginUser]
def signUp = Action.async(parse.json) { implicit request =>
request.body.validate[LoginUser].map { credentials =>
val user = User(userID = UUID.randomUUID(), name = credentials.email, LoginInfo(CredentialsProvider.ID, credentials.email))
userService.retrieve(user.loginInfo).flatMap {
case Some(u) => Future.successful(Conflict(Json.obj("error" -> ("user " + credentials.email + " already registered"))))
case None =>
for {
user <- userService.save(user).map(_ => user)
authInfo <- authInfoRepository.add(user.loginInfo, passwordHasher.hash(credentials.password))
authenticator <- silhouette.env.authenticatorService.create(user.loginInfo)
token <- silhouette.env.authenticatorService.init(authenticator)
result <- silhouette.env.authenticatorService.embed(token, Ok(Json.toJson(token)))
} yield {
silhouette.env.eventBus.publish(SignUpEvent(user, request))
silhouette.env.eventBus.publish(LoginEvent(user, request))
result
}
}
}.recoverTotal {
case error => Future.successful(BadRequest(JsError.toJson(error)))
}
}
}
开发者ID:team3,项目名称:Play2-mongodb-silhouette-activator-template,代码行数:52,代码来源:AuthenticationController.scala
示例10: HomeController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import com.kylegalloway.evescala.EveScalaBuilder
import com.mohiva.play.silhouette.api.Silhouette
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import com.mohiva.play.silhouette.impl.providers.OAuth2Info
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc._
import play.api.routing._
import silhouette.SessionEnv
import scala.concurrent.Future
@Singleton
class HomeController @Inject()(
val messagesApi: MessagesApi,
silhouette: Silhouette[SessionEnv],
authInfoRepository: AuthInfoRepository,
eveScalaBuilder: EveScalaBuilder
) extends Controller with I18nSupport {
def index = silhouette.SecuredAction.async { implicit request =>
authInfoRepository.find[OAuth2Info](request.identity.loginInfo).flatMap { authInfoOpt: Option[OAuth2Info] =>
authInfoOpt match {
case None => Future.successful(Redirect(routes.HomeController.login()))
case Some(authInfo) => {
Future.successful(Ok(views.html.home()))
}
}
}
}
def login = silhouette.UnsecuredAction { implicit request =>
Ok(views.html.login())
}
def walletJournal = silhouette.SecuredAction { implicit request =>
Ok(views.html.walletJournal())
}
def javascriptRoutes = Action { implicit request =>
Ok(
JavaScriptReverseRouter("jsRoutes")(
routes.javascript.EveSSOAuthController.authenticate,
routes.javascript.Assets.versioned
)
).as("text/javascript")
}
}
示例11: EveSSOAuthController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.{Inject, Singleton}
import com.kylegalloway.evescala.EveScalaBuilder
import com.mohiva.play.silhouette.api.exceptions.ProviderException
import com.mohiva.play.silhouette.api.{Logger, LoginEvent, Silhouette}
import com.mohiva.play.silhouette.api.repositories.AuthInfoRepository
import play.api.i18n.{I18nSupport, Messages, MessagesApi}
import play.api.libs.concurrent.Execution.Implicits._
import play.api.libs.json._
import play.api.mvc.Controller
import silhouette.SessionEnv
import silhouette.evesso.EveSSOProvider
import silhouette.evesso.service.EveCharacterIdentityService
import scala.concurrent.Future
@Singleton
class EveSSOAuthController @Inject()(
val messagesApi: MessagesApi,
silhouette: Silhouette[SessionEnv],
eveSSOProvider: EveSSOProvider,
eveCharacterIdentityService: EveCharacterIdentityService,
authInfoRepository: AuthInfoRepository,
eveScalaBuilder: EveScalaBuilder
) extends Controller with I18nSupport with Logger {
def authenticate() = silhouette.UserAwareAction.async { implicit request =>
eveSSOProvider.authenticate().flatMap {
case Left(result) => Future.successful(result)
case Right(authInfo) => request.identity match {
case None =>
for {
profile <- eveSSOProvider.retrieveProfile (authInfo)
character <- eveCharacterIdentityService.save(profile)
_ <- authInfoRepository.save (profile.loginInfo, authInfo)
authenticator <- silhouette.env.authenticatorService.create (profile.loginInfo)
value <- silhouette.env.authenticatorService.init(authenticator)
result <- silhouette.env.authenticatorService.embed(value, Redirect (routes.HomeController.index () ) )
} yield {
silhouette.env.eventBus.publish (LoginEvent (character, request) )
result
}
case Some(eveCharacter) =>
for {
profile <- eveSSOProvider.retrieveProfile(authInfo)
globalUserID = eveCharacter.globalUserID
character <- eveCharacterIdentityService.addToUser(globalUserID, profile)
_ <- authInfoRepository.save(profile.loginInfo, authInfo)
} yield {
Redirect (routes.HomeController.index () )
}
}
}.recover {
case e: ProviderException =>
logger.error("Unexpected provider error", e)
Redirect(routes.HomeController.index()).flashing("error" -> Messages("could.not.authenticate"))
}
}
}