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

Scala LoginLogout类代码示例

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

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



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

示例1: LoginData

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

import controllers.{ HasConfig, HasUserService, Security }
import javax.inject.{ Inject, Singleton }
import jp.t2v.lab.play2.auth.{ AuthElement, LoginLogout }
import models.document.DocumentService
import models.user.UserService
import play.api.Configuration
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.{ I18nSupport, MessagesApi }
import play.api.mvc.{ Action, Controller }
import scala.concurrent.{ ExecutionContext, Future }

case class LoginData(usernameOrPassword: String, password: String)

@Singleton
class LoginLogoutController @Inject() (    
    val config: Configuration,
    val users: UserService,
    implicit val ctx: ExecutionContext,
    val messagesApi: MessagesApi
  ) extends Controller with AuthElement with HasConfig with HasUserService with Security with LoginLogout with I18nSupport {

  private val MESSAGE = "message"

  private val INVALID_LOGIN = "Invalid Username or Password"

  val loginForm = Form(
    mapping(
      "username" -> nonEmptyText,
      "password" -> nonEmptyText
    )(LoginData.apply)(LoginData.unapply)
  )

  def showLoginForm(destination: Option[String]) = Action { implicit request =>
    destination match {
      case None => Ok(views.html.landing.login(loginForm))
      case Some(dest) => Ok(views.html.landing.login(loginForm)).withSession("access_uri" -> dest)
    }
  }

  def processLogin = Action.async { implicit request =>
    loginForm.bindFromRequest.fold(
      formWithErrors =>
        Future(BadRequest(views.html.landing.login(formWithErrors))),

      loginData =>
        users.validateUser(loginData.usernameOrPassword, loginData.password).flatMap {
          case Some(validUser) => gotoLoginSucceeded(validUser.getUsername)
          case None => Future(Redirect(routes.LoginLogoutController.showLoginForm()).flashing(MESSAGE -> INVALID_LOGIN))
        }
    )
  }

  def logout = Action.async { implicit request =>
    gotoLogoutSucceeded
  }

} 
开发者ID:pelagios,项目名称:recogito2,代码行数:61,代码来源:LoginLogoutController.scala


示例2: Sessions

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

import authes.AuthConfigImpl
import com.github.tototoshi.play2.json4s.Json4s
import com.google.inject.Inject
import jp.t2v.lab.play2.auth.LoginLogout
import org.json4s.DefaultFormats
import play.api.mvc.{Action, Controller}
import queries.LoginEmail
import scalikejdbc.AutoSession

import scala.concurrent.ExecutionContext

class Sessions @Inject() (json4s: Json4s, implicit val ec: ExecutionContext)
    extends Controller
    with AuthConfigImpl
    with LoginLogout {
  import json4s._

  implicit val formats = DefaultFormats

  def login() = Action.async(json) { implicit req =>
    val result = for {
      login <- req.body.extractOpt[LoginEmail]
      account <- login.authenticate()(AutoSession)
    } yield account
    result.fold(authenticationFailed(req)) { account => gotoLoginSucceeded(account.id) }
  }

  def logout() = Action.async { implicit req =>
    gotoLogoutSucceeded
  }
} 
开发者ID:ponkotuy,项目名称:train-stamp-rally,代码行数:34,代码来源:Sessions.scala


示例3: AuthenticateController

//设置package包名称以及导入依赖的类
package controllers.api.auth

import javax.inject.{Inject, Singleton}

import akka.actor.ActorSystem
import com.github.sample.dto.AccountDTO
import jp.t2v.lab.play2.auth.LoginLogout
import play.api.libs.json.JsValue
import play.api.mvc._

import scala.concurrent.{ExecutionContext, Future}

@Singleton
class AuthenticateController @Inject() (actorSystem: ActorSystem) extends Controller with LoginLogout with AuthConfigImpl {

  implicit val myExecutionContext: ExecutionContext = actorSystem.dispatcher

  private def authenticate(dto: AccountDTO): Either[Result, MyUser] = {
    AuthService.authenticate(dto.id, dto.password) match {
      case None => Left(Unauthorized("authentication failed"))
      case Some(user) => Right(user)
    }
  }

  private def jsonDecode(request: Request[JsValue]): Either[Result, AccountDTO] = {
    request.body.validate[AccountDTO].asOpt match {
      case None => Left(BadRequest("bad request"))
      case Some(v) => Right(v)
    }
  }

  def login() = Action.async(BodyParsers.parse.json) { implicit request =>

    val myUser = for{
      account <- jsonDecode(request).right
      myUser <- authenticate(account).right
    } yield myUser

    myUser match {
      case Left(r) => Future{r}
      case Right(user) => gotoLoginSucceeded(user.id).map(_.withCookies(Cookie("userId", user.id), Cookie("userRole", user.role.toString)))
    }
  }

  def logout() = Action.async { implicit request =>
    gotoLogoutSucceeded
  }
} 
开发者ID:tm-sukehiro,项目名称:play2-sandbox,代码行数:49,代码来源:AuthenticateController.scala


示例4: Application

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

import jp.t2v.lab.play2.auth.LoginLogout
import models.Account
import play.api._
import play.api.data.Form
import play.api.mvc._
import views.html

import play.api.data.Form
import play.api.data.Forms._

import scala.concurrent.Future
import play.api.libs.concurrent.Execution.Implicits.defaultContext

class Application extends Controller with LoginLogout with AuthConfigImpl {

  def index = Action {
    Ok(views.html.index("Your new application is ready."))
  }

  
  def authenticate = Action.async { implicit request =>
    loginForm.bindFromRequest.fold(
      formWithErrors => Future.successful(BadRequest(html.login(formWithErrors))),
      user => gotoLoginSucceeded(user.get.id)
    )
  }

} 
开发者ID:sakamotodesu,项目名称:play24auth,代码行数:31,代码来源:Application.scala


示例5: SessionController

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

import authes.AuthConfigImpl
import com.github.tototoshi.play2.json4s.native.Json4s
import com.google.inject.Inject
import com.ponkotuy.queries.LoginEmail
import jp.t2v.lab.play2.auth.LoginLogout
import models.User
import org.json4s.DefaultFormats
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import play.api.mvc.{Action, Controller}
import scalikejdbc._

import scala.concurrent.ExecutionContext

class SessionController @Inject()(_ec: ExecutionContext, json4s: Json4s)
    extends Controller
    with AuthConfigImpl
    with LoginLogout {
  import json4s._
  import SessionController._
  implicit val ec = _ec
  implicit def formats = DefaultFormats

  def login() = Action.async(json) { implicit req =>
    val result = for {
      auth <- req.body.extractOpt[LoginEmail]
      user <- authenticate(auth)(AutoSession)
    } yield user
    result.fold(authenticationFailed(req)) { user => gotoLoginSucceeded(user.id) }
  }

  def logout() = Action.async { implicit req =>
    gotoLogoutSucceeded
  }
}

object SessionController {
  val bcrypt = new BCryptPasswordEncoder(10)
  def authenticate(le: LoginEmail)(implicit session: DBSession): Option[User] = {
    User.findBy(sqls.eq(User.column.email, le.email)).filter { user =>
      bcrypt.matches(le.password, user.password)
    }
  }
} 
开发者ID:ponkotuy,项目名称:aggregate-exif,代码行数:46,代码来源:SessionController.scala


示例6: Sessions

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

import jp.t2v.lab.play2.auth.LoginLogout
import model.Account
import play.api.data.Form
import play.api.data.Forms._
import play.api.mvc.{Action, Controller}
import views.html
import scala.language.postfixOps
import scala.concurrent.Future
import play.api.libs.concurrent.Execution.Implicits.defaultContext

class Sessions extends Controller with LoginLogout with AuthConfigImpl {

  val loginForm = Form {
    mapping("email" -> email, "password" -> text)(Account.authenticate)(_.map(u => (u.email, "")))
      .verifying("Invalid email or password", result => result.isDefined)
  }
  val remembermeForm = Form {
    "rememberme" -> boolean
  }

  def login = Action { implicit request =>
    Ok(html.rememberme.login(loginForm, remembermeForm.fill(request.session.get("rememberme").exists("true" ==))))
  }

  def logout = Action.async { implicit request =>
    gotoLogoutSucceeded.map(_.flashing(
      "success" -> "You've been logged out"
    ))
  }

  def authenticate = Action.async { implicit request =>
    val rememberme = remembermeForm.bindFromRequest()
    loginForm.bindFromRequest.fold(
      formWithErrors => Future.successful(BadRequest(html.rememberme.login(formWithErrors, rememberme))),
      { user =>
        val req = request.copy(tags = request.tags + ("rememberme" -> rememberme.get.toString))
        gotoLoginSucceeded(user.get.id)(req, defaultContext).map(_.withSession("rememberme" -> rememberme.get.toString))
      }
    )
  }

} 
开发者ID:phosphene,项目名称:play2.x-basic-auth-demo,代码行数:45,代码来源:Sessions.scala


示例7: Sessions

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

import jp.t2v.lab.play2.auth.LoginLogout
import model.Account
import play.api.data.Form
import play.api.data.Forms._
import play.api.mvc.{Action, Controller}
import views.html

import scala.concurrent.Future
import play.api.libs.concurrent.Execution.Implicits.defaultContext

class Sessions  extends Controller with LoginLogout with AuthConfigImpl {

  val loginForm = Form {
    mapping("email" -> email, "password" -> text)(Account.authenticate)(_.map(u => (u.email, "")))
      .verifying("Invalid email or password", result => result.isDefined)
  }

  def login = Action { implicit request =>
    Ok(html.csrf.login(loginForm))
  }

  def logout = Action.async { implicit request =>
    gotoLogoutSucceeded.map(_.flashing(
      "success" -> "You've been logged out"
    ))
  }

  def authenticate = Action.async { implicit request =>
    loginForm.bindFromRequest.fold(
      formWithErrors => Future.successful(BadRequest(html.csrf.login(formWithErrors))),
      user           => gotoLoginSucceeded(user.get.id)
    )
  }

} 
开发者ID:phosphene,项目名称:play2.x-basic-auth-demo,代码行数:38,代码来源:Sessions.scala


示例8: Sessions

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

import jp.t2v.lab.play2.auth.LoginLogout
import model.Account
import play.api.data.Form
import play.api.data.Forms._
import play.api.mvc.{Action, Controller}
import views.html

import scala.concurrent.Future
import play.api.libs.concurrent.Execution.Implicits.defaultContext

class Sessions extends Controller with LoginLogout with AuthConfigImpl {

  val loginForm = Form {
    mapping("email" -> email, "password" -> text)(Account.authenticate)(_.map(u => (u.email, "")))
      .verifying("Invalid email or password", result => result.isDefined)
  }

  def login = Action { implicit request =>
    Ok(html.stateless.login(loginForm))
  }

  def logout = Action.async { implicit request =>
    gotoLogoutSucceeded.map(_.flashing(
      "success" -> "You've been logged out"
    ))
  }

  def authenticate = Action.async { implicit request =>
    loginForm.bindFromRequest.fold(
      formWithErrors => Future.successful(BadRequest(html.stateless.login(formWithErrors))),
      user           => gotoLoginSucceeded(user.get.id)
    )
  }

} 
开发者ID:phosphene,项目名称:play2.x-basic-auth-demo,代码行数:38,代码来源:Sessions.scala


示例9: Sessions

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

import jp.t2v.lab.play2.auth.LoginLogout
import model.Account
import play.api.data.Form
import play.api.data.Forms._
import play.api.mvc.{Action, Controller}
import views.html

import scala.concurrent.Future
import play.api.libs.concurrent.Execution.Implicits.defaultContext

class Sessions extends Controller with LoginLogout with AuthConfigImpl {

  val loginForm = Form {
    mapping("email" -> email, "password" -> text)(Account.authenticate)(_.map(u => (u.email, "")))
      .verifying("Invalid email or password", result => result.isDefined)
  }

  def login = Action { implicit request =>
    Ok(html.standard.login(loginForm))
  }

  def logout = Action.async { implicit request =>
    gotoLogoutSucceeded.map(_.flashing(
      "success" -> "You've been logged out"
    ).removingFromSession("rememberme"))
  }

  def authenticate = Action.async { implicit request =>
    loginForm.bindFromRequest.fold(
      formWithErrors => Future.successful(BadRequest(html.standard.login(formWithErrors))),
      user           => gotoLoginSucceeded(user.get.id)
    )
  }

} 
开发者ID:phosphene,项目名称:play2.x-basic-auth-demo,代码行数:38,代码来源:Sessions.scala


示例10: Sessions

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

import jp.t2v.lab.play2.auth.LoginLogout
import model.Account
import play.api.data.Form
import play.api.data.Forms._
import play.api.mvc.{Action, Controller}
import views.html

import scala.concurrent.Future
import play.api.libs.concurrent.Execution.Implicits.defaultContext

class Sessions extends Controller with LoginLogout with AuthConfigImpl {

  val loginForm = Form {
    mapping("email" -> email, "password" -> text)(Account.authenticate)(_.map(u => (u.email, "")))
      .verifying("Invalid email or password", result => result.isDefined)
  }

  def login = Action { implicit request =>
    Ok(html.builder.login(loginForm))
  }

  def logout = Action.async { implicit request =>
    gotoLogoutSucceeded.map(_.flashing(
      "success" -> "You've been logged out"
    ))
  }

  def authenticate = Action.async { implicit request =>
    loginForm.bindFromRequest.fold(
      formWithErrors => Future.successful(BadRequest(html.builder.login(formWithErrors))),
      user           => gotoLoginSucceeded(user.get.id)
    )
  }

} 
开发者ID:phosphene,项目名称:play2.x-basic-auth-demo,代码行数:38,代码来源:Sessions.scala


示例11: Sessions

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

import jp.t2v.lab.play2.auth.LoginLogout
import model.Account
import play.api.data.Form
import play.api.data.Forms._
import play.api.mvc.{Action, Controller}
import views.html

import scala.concurrent.Future
import play.api.libs.concurrent.Execution.Implicits.defaultContext

class Sessions  extends Controller with LoginLogout with AuthConfigImpl {

  val loginForm = Form {
    mapping("email" -> email, "password" -> text)(Account.authenticate)(_.map(u => (u.email, "")))
      .verifying("Invalid email or password", result => result.isDefined)
  }

  def login = Action { implicit request =>
    Ok(html.ephemeral.login(loginForm))
  }

  def logout = Action.async { implicit request =>
    gotoLogoutSucceeded.map(_.flashing(
      "success" -> "You've been logged out"
    ))
  }

  def authenticate = Action.async { implicit request =>
    loginForm.bindFromRequest.fold(
      formWithErrors => Future.successful(BadRequest(html.ephemeral.login(formWithErrors))),
      user           => gotoLoginSucceeded(user.get.id)
    )
  }

} 
开发者ID:phosphene,项目名称:play2.x-basic-auth-demo,代码行数:38,代码来源:Sessions.scala


示例12: SessionController

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

import com.google.inject.Inject
import forms.Login
import jp.t2v.lab.play2.auth.LoginLogout
import models.Account
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, Controller, RequestHeader, Result}
import utils.Tools

import scala.concurrent.{ExecutionContext, Future}

class SessionController @Inject()(val messagesApi: MessagesApi, implicit val ec: ExecutionContext) extends Controller with LoginLogout with AuthConfigImpl with I18nSupport {
  def view() = Action {
    Ok(views.html.login(Login.form))
  }

  def login() = Action.async { implicit req =>
    Login.form.bindFromRequest().fold(
      errors => Future.successful(BadRequest(errors.errors.mkString("\n"))),
      authenticate
    )
  }

  private def authenticate(login: Login)(implicit req: RequestHeader): Future[Result] = {
    Account.where('name -> login.name).apply().headOption.flatMap { account =>
      if(Tools.toHash(login.password, account.salt) sameElements account.hash) Some(gotoLoginSucceeded(account.id)) else None
    }.getOrElse(Future.successful(Unauthorized("Authentication failed")))
  }
} 
开发者ID:ponkotuy,项目名称:mission-recommender,代码行数:31,代码来源:SessionController.scala


示例13: AuthenticateController

//设置package包名称以及导入依赖的类
package controllers.api.auth

import javax.inject.{Inject, Singleton}

import akka.actor.ActorSystem
import com.github.uryyyyyyy.dto.AccountDTO
import jp.t2v.lab.play2.auth.LoginLogout
import play.api.libs.json.JsValue
import play.api.mvc._

import scala.concurrent.{ExecutionContext, Future}

@Singleton
class AuthenticateController @Inject() (actorSystem: ActorSystem) extends Controller with LoginLogout with AuthConfigImpl {

  implicit val myExecutionContext: ExecutionContext = actorSystem.dispatcher

  private def authenticate(dto: AccountDTO): Either[Result, MyUser] = {
    AuthService.authenticate(dto.id, dto.password) match {
      case None => Left(Unauthorized("authentication failed"))
      case Some(user) => Right(user)
    }
  }

  private def jsonDecode(request: Request[JsValue]): Either[Result, AccountDTO] = {
    request.body.validate[AccountDTO].asOpt match {
      case None => Left(BadRequest("bad request"))
      case Some(v) => Right(v)
    }
  }

  def login() = Action.async(BodyParsers.parse.json) { implicit request =>

    val myUser = for{
      account <- jsonDecode(request).right
      myUser <- authenticate(account).right
    } yield myUser

    myUser match {
      case Left(r) => Future{r}
      case Right(user) => gotoLoginSucceeded(user.id).map(_.withCookies(Cookie("userId", user.id), Cookie("userRole", user.role.toString)))
    }
  }

  def logout() = Action.async { implicit request =>
    gotoLogoutSucceeded
  }
} 
开发者ID:uryyyyyyy,项目名称:play2sample,代码行数:49,代码来源:AuthenticateController.scala


示例14: LoginData

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

import controllers.{ HasConfig, HasUserService, Security }
import javax.inject.Inject
import jp.t2v.lab.play2.auth.{ AuthElement, LoginLogout }
import play.api.Configuration
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.{ I18nSupport, MessagesApi }
import play.api.mvc.{ Action, Controller }
import scala.concurrent.{ ExecutionContext, Future }
import services.user.UserService

case class LoginData(usernameOrPassword: String, password: String)

class LoginLogoutController @Inject() (    
    val config: Configuration,
    val users: UserService,
    val messagesApi: MessagesApi,
    implicit val ctx: ExecutionContext
  ) extends Controller with AuthElement with HasConfig with HasUserService with Security with LoginLogout with I18nSupport {

  private val MESSAGE = "message"

  private val INVALID_LOGIN = "Invalid Username or Password"

  val loginForm = Form(
    mapping(
      "username" -> nonEmptyText,
      "password" -> nonEmptyText
    )(LoginData.apply)(LoginData.unapply)
  )

  def showLoginForm(destination: Option[String]) = Action { implicit request =>
    destination match {
      case None => Ok(views.html.admin.login(loginForm))
      case Some(dest) => Ok(views.html.admin.login(loginForm)).withSession("access_uri" -> dest)
    }
  }

  def processLogin = Action.async { implicit request =>
    loginForm.bindFromRequest.fold(
      formWithErrors =>
        Future(BadRequest(views.html.admin.login(formWithErrors))),

      loginData =>
        users.validateUser(loginData.usernameOrPassword, loginData.password).flatMap {
          case Some(validUser) => gotoLoginSucceeded(validUser.username)
          case None => Future(Redirect(routes.LoginLogoutController.showLoginForm()).flashing(MESSAGE -> INVALID_LOGIN))
        }
    )
  }

  def logout = Action.async { implicit request =>
    gotoLogoutSucceeded
  }

} 
开发者ID:pelagios,项目名称:peripleo2,代码行数:59,代码来源:LoginLogoutController.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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