本文整理汇总了Scala中com.mohiva.play.silhouette.api.LogoutEvent类的典型用法代码示例。如果您正苦于以下问题:Scala LogoutEvent类的具体用法?Scala LogoutEvent怎么用?Scala LogoutEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LogoutEvent类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SignOutController
//设置package包名称以及导入依赖的类
package controllers
import com.google.inject.Inject
import com.mohiva.play.silhouette.api.{LogoutEvent, Silhouette}
import play.api.mvc.{AbstractController, ControllerComponents}
import utils.JsonResults
import utils.auth.DefaultEnv
class SignOutController @Inject() (
components: ControllerComponents,
silhouette: Silhouette[DefaultEnv]
) extends AbstractController(components) {
def submit = silhouette.SecuredAction.async { implicit request =>
silhouette.env.eventBus.publish(
LogoutEvent(request.identity, request)
)
silhouette.env.authenticatorService.discard(
request.authenticator,
Ok(JsonResults.success("User signed out"))
)
}
}
示例2: Application
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Inject
import com.mohiva.play.silhouette.api.{Environment, LogoutEvent, Silhouette}
import com.mohiva.play.silhouette.impl.authenticators.SessionAuthenticator
import forms._
import models.User
import play.api.i18n.MessagesApi
import scala.concurrent.Future
class Application @Inject()(val messagesApi: MessagesApi, val env: Environment[User, SessionAuthenticator])
extends Silhouette[User, SessionAuthenticator] {
def index = UserAwareAction { implicit request =>
Ok(views.html.index(request.identity))
}
def dashboard = SecuredAction { implicit request =>
Ok(views.html.dashboard(request.identity))
}
def signIn = UserAwareAction.async { implicit request =>
request.identity match {
case Some(_) => Future.successful(Redirect(routes.Application.index()))
case None => Future.successful(Ok(views.html.signIn(SignInForm.form)))
}
}
def signUp = SecuredAction { implicit request =>
Ok(views.html.signUp(SignUpForm.form))
}
def signOut = SecuredAction.async { implicit request =>
val result = Redirect(routes.Application.index())
env.eventBus.publish(LogoutEvent(request.identity, request, request2Messages))
env.authenticatorService.discard(request.authenticator, result)
}
}