当前位置: 首页>>代码示例>>Scala>>正文


Scala _类代码示例

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


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

示例1: LoginController

//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import models.{LoginData, UserData}
import play.api.cache._
import play.api.data.Forms._
import play.api.data._
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, _}
import services.ImpConfService
import services.MD5

@Singleton
class LoginController @Inject()(cache: CacheApi,statusService: ImpConfService)(implicit val messagesApi: MessagesApi) extends Controller with I18nSupport  {

  val loginForm = Form(
    mapping(
      "name" -> text,
      "pass"-> text
    )(LoginData.apply)(LoginData.unapply)
  )

  def index = Action { implicit request =>

    Ok(views.html.login())
  }
  def login = Action{ implicit request=>
    loginForm.bindFromRequest.fold(
      errorForm=>{

        BadRequest(views.html.login())
      },
      validForm=> {

        val user = cache.get[UserData](validForm.name)
       user match {
         case Some(UserData(name,fname,mname,lname,age,pass,mobile,gender,hobbies,status,isSuspended))=>if(isSuspended=="true")  Redirect(routes.LoginController.index()).flashing("success" -> "you has been blocked ")
          else {
            if(pass== MD5.hash(validForm.pass))  Redirect(routes.ProfileController.index())withSession (request.session + ("mySession" -> s"${validForm.name}"))
                                                else Redirect(routes.LoginController.index()).flashing("success" -> "please enter correct password")}
          case None=>  Redirect(routes.LoginController.index()).flashing("success" -> "you are not valid user")
        }
      }

    )

  }

} 
开发者ID:SHUB9914,项目名称:AjaxPlay-SHUBHAM,代码行数:49,代码来源:LoginController.scala

示例2: I019_datetime_constructor_Spec

//设置package包名称以及导入依赖的类
import org.scalatestplus.play._
import play.api.mvc.{AnyContentAsEmpty, _}
import play.api.test.{FakeHeaders, _}
import play.api.test.Helpers._
import play.api.libs.json._

class I019_datetime_constructor_Spec extends PlaySpec with OneAppPerSuite {

  val exptectedContentType = "application/json"

  val headers = FakeHeaders(Seq("Accept" -> exptectedContentType))

  "I09" should {

    "be able to construct datetime objects from string" in {
      val stringRequest =
        """{
          |  "complete_before": "2016-07-25T13:15:53.208Z",
          |  "complete_after": "2016-07-25T13:15:53.208Z"
          |}""".stripMargin

      val fromString = route(app, FakeRequest(POST, "/019", headers, Json.parse(stringRequest))).get
      status(fromString) mustBe OK
      contentType(fromString) mustBe Some(exptectedContentType)
      contentAsString(fromString) must include("\"complete_before\":")
      contentAsString(fromString) must include("\"complete_after\":")
    }

    "be able to construct datetime objects from long" in {
      val longRequest =
        """{
          |  "complete_before": 1469452060,
          |  "complete_after": 1469452060
          |}""".stripMargin

      val fromLong = route(app, FakeRequest(POST, "/019", headers, Json.parse(longRequest))).get
      status(fromLong) mustBe OK
      contentType(fromLong) mustBe Some(exptectedContentType)
      contentAsString(fromLong) must include("\"complete_before\":")
      contentAsString(fromLong) must include("\"complete_after\":")
    }

    "be able to construct datetime objects from string in header and path" in {
      val request = "2016-07-25T13:15:53.208Z"
      val withHeader = FakeHeaders(("header", request) +: headers.data)
      val fromString = route(app, FakeRequest(GET, s"/019/$request", withHeader, AnyContentAsEmpty)).get
      contentAsString(fromString) must include("\"complete_before\":")
      contentAsString(fromString) must include("\"complete_after\":")
      status(fromString) mustBe OK
      contentType(fromString) mustBe Some(exptectedContentType)
    }

    "NOT be able to construct datetime objects from long in header and path" in {
      val request = 1469452060
      val withHeader = FakeHeaders(("header", request.toString) +: headers.data)
      val fromLong = route(app, FakeRequest(GET, s"/019/$request", withHeader, AnyContentAsEmpty)).get
      status(fromLong) mustBe BAD_REQUEST
    }
  }
} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:61,代码来源:I019_datetime_constructor_Spec.scala

示例3: UserSignUpData

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

import model.Account
import play.api.data.Forms._
import play.api.data._
import play.api.mvc.{Action, _}
import play.api.i18n.Messages.Implicits._
import play.api.Play.current


case class UserSignUpData(email:String,password:String,confirm:String)

class SignupController extends Controller{


  val userForm=Form(
    mapping(
      "email" -> email,
      "password" -> nonEmptyText,
      "confirm-password"->nonEmptyText
    )(UserSignUpData.apply)(UserSignUpData.unapply)
      .verifying("Invalid user name or password",result => check(result)
    )
  )


  def check(data: UserSignUpData):Boolean = {
    if(data.password == data.confirm)
      true
    else
      false
  }


  def showSignUpPage =Action { implicit request =>
    Ok(views.html.sign_up(userForm))
  }

  def createUser = Action { implicit request =>
      userForm.bindFromRequest.fold(
        formWithErrors =>{
          BadRequest(views.html.sign_up(formWithErrors))
          //
         },
        UsersData => {
          Ok("User Created")

          Account.createUser(UsersData.email,UsersData.password)
           Redirect(routes.AccountController.showAccountsPage).withSession(
             "connected" -> UsersData.email)


        })
  }

} 
开发者ID:SangeetaGulia,项目名称:Loginapp-sang-Geet,代码行数:57,代码来源:SignupController.scala

示例4: PetsController

//设置package包名称以及导入依赖的类
package com.wunder.pets.web.controllers

import java.util.UUID
import javax.inject.{Inject, Singleton}

import com.wunder.pets.entity.Entity.{All, Create, Find}
import com.wunder.pets.pets.{CreatePetForm, Pet}
import com.wunder.pets.web.Serializers._
import play.api.libs.json._
import play.api.mvc.{Controller, _}

import scala.concurrent.ExecutionContext

@Singleton
class PetsController @Inject()(findPet: Find[Pet], createPet: Create[CreatePetForm, Pet], allPets: All[Pet])
                              (implicit ec: ExecutionContext) extends Controller with CrudController {

  def all() = Action.async {
//    Future.successful(Ok("Pets"))
    allPets().map(pets => Ok(Json.toJson(pets)))
  }

  def find(id: UUID) = Action.async {
    findPet(id).map {
      case Some(pet) =>
        Ok(Json.toJson(pet))
      case None =>
        NotFound
    }
  }

  def create = Action.async(parse.json) { request =>
    createEntity(request, createPet)
  }
} 
开发者ID:wunderteam,项目名称:battle-pets-api,代码行数:36,代码来源:PetsController.scala

示例5: UserController

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

import play.api.Play.current
import play.api.cache.Cache
import play.api.libs.json._
import play.api.mvc.{Action, Controller, _}

object UserController extends Controller {

  def authenticatedAction(f: Request[AnyContent] => Result) = Action {
    request => {
      (request.session.get("idToken").flatMap { idToken =>
        Cache.getAs[JsValue](idToken + "profile")
      } map {
        profile => f(request)
      }).orElse {
        Some(Redirect(routes.IndexController.index()))
      }.get
    }
  }

  def index = authenticatedAction {
    request => {
      val idToken = request.session.get("idToken").get
      val profile = Cache.getAs[JsValue](idToken + "profile").get
      Ok(views.html.user(profile))
    }
  }

} 
开发者ID:Krasnyanskiy,项目名称:auth0-scala-sample,代码行数:31,代码来源:UserController.scala

示例6: Application

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

import javax.inject.{Inject, _}

import actors.WebSocketActor
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import play.api.Play.current
import play.api.mvc.{Action, Controller, _}


@Singleton
class Application @Inject()(implicit system: ActorSystem) extends Controller {
    implicit val mat = ActorMaterializer()

    val index = Action {
        Ok(views.html.index("1"))
    }

    def socket = WebSocket.acceptWithActor[String, String] { request => out =>
        WebSocketActor.props(out, mat)
    }
} 
开发者ID:jw3,项目名称:example-play-sse,代码行数:24,代码来源:Application.scala

示例7: LoginController

//设置package包名称以及导入依赖的类
package controllers
import javax.inject._

import models.LoginData
import play.api.data.Forms._
import play.api.data._
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, _}
import play.api.cache._
import  models.UserData
@Singleton
class LoginController @Inject() (cache: CacheApi)(implicit val messagesApi: MessagesApi) extends Controller with I18nSupport  {

  val loginForm = Form(
    mapping(
      "name" -> text,
      "pass"-> text
    )(LoginData.apply)(LoginData.unapply)
  )

  def index = Action { implicit request =>

    Ok(views.html.login())
  }
  def login = Action{ implicit request=>
    loginForm.bindFromRequest.fold(
      errorForm=>{
        BadRequest(views.html.login())
      },
      validForm=> {
        val user = cache.get[UserData](validForm.name)
       user match {
          case Some(UserData(name,fname,mname,lname,age,pass,mobile,gender,hobbies))=> if(pass==validForm.pass)  Redirect(routes.ProfileController.index())withSession (request.session + ("mySession" -> s"${validForm.name}"))
                                                else Redirect(routes.LoginController.index()).flashing("success" -> "please enter correct password")
          case None=>  Redirect(routes.LoginController.index()).flashing("success" -> "you are not valid user")
        }
      }

    )

  }

} 
开发者ID:SHUB9914,项目名称:Play-FirstAssignment-Shubham,代码行数:44,代码来源:LoginController.scala

示例8: SignupController

//设置package包名称以及导入依赖的类
package controllers
import javax.inject._
import play.api.data.Forms._
import play.api.data._
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, _}
import play.api.cache._
import models.UserData

@Singleton
class SignupController @Inject()(cache: CacheApi)(implicit val messagesApi: MessagesApi) extends Controller with I18nSupport {

  val loginForm: Form[UserData] = Form(
    mapping(
      "username" -> nonEmptyText,
      "firstname" -> nonEmptyText,
      "middlename" -> text,
      "lastname" -> nonEmptyText,
      "age" -> number(min = 18, max = 75),
      "pass"-> nonEmptyText,
      "mobile" -> nonEmptyText,
      "gender" -> nonEmptyText,
      "hobbies"-> list(text)



    )(UserData.apply)(UserData.unapply)
  )

  def index = Action { implicit request =>
    Ok(views.html.singup("",loginForm))
  }

  def createUser = Action{ implicit request=>
    loginForm.bindFromRequest.fold(
      errorForm => {
        BadRequest(views.html.singup("", errorForm))
      }, validForm => {
        val user = cache.get[models.UserData](validForm.name)

        user match {
          case Some(userdata)=>Redirect(routes.LoginController.index()).flashing("success" -> "User already exist please Login")
          case None =>cache.set(validForm.name,validForm)
            Redirect(routes.ProfileController.index())withSession (request.session + ("mySession" -> s"${validForm.name}"))
        }
      }
    )
  }
} 
开发者ID:SHUB9914,项目名称:Play-FirstAssignment-Shubham,代码行数:50,代码来源:SignupController.scala

示例9: CandidatesListController

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

import com.google.inject.Inject
import play.api.cache.Cached
import play.api.mvc.{Controller, _}
import rendering.{CandidateListSection, PlainTextRendering}
import repos.CandidatesRepo

import scala.concurrent.duration._

import scala.concurrent.ExecutionContext.Implicits.global

class CandidatesListController @Inject()(candidatesRepo: CandidatesRepo, cached: Cached) extends Controller {

  def list() = cached("candidate-list").default(6.hours) {
    Action.async { request =>
      candidatesRepo.findAllCandidates().map { candidates =>
        val sections = candidates.map { candidate =>
          new CandidateListSection(candidate) with PlainTextRendering
        }
        Ok(views.txt.candidate_list(sections))
      }
    }
  }
} 
开发者ID:sdkman,项目名称:sdkman-candidates,代码行数:26,代码来源:CandidatesListController.scala

示例10: User

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

import javax.inject.Inject

import play.api.cache.CacheApi
import play.api.libs.json._
import play.api.libs.ws.WSClient
import play.api.mvc.{Action, Controller, _}

class User @Inject()(cache: CacheApi, ws: WSClient) extends Controller {
  def AuthenticatedAction(f: Request[AnyContent] => Result): Action[AnyContent] = {
    Action { request =>
      (request.session.get("idToken").flatMap { idToken =>
        cache.get[JsValue](idToken + "profile")
      } map { profile =>
        f(request)
      }).orElse {
        Some(Redirect(routes.Application.index()))
      }.get
    }
  }

  def index = AuthenticatedAction { request =>
    val idToken = request.session.get("idToken").get
    val profile = cache.get[JsValue](idToken + "profile").get
    Ok(views.html.user(profile))
  }
} 
开发者ID:griffio,项目名称:oidc_starter_seed,代码行数:29,代码来源:User.scala

示例11: FormController

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

import javax.inject._

import model.UserData
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.I18nSupport
import play.api.mvc.{Action, _}


@Singleton
class FormController @Inject()(cc: ControllerComponents) extends AbstractController(cc) with I18nSupport {

  def form = Action {implicit request =>
    Ok(views.html.form(FormController.userForm))
  }

  def submit = Action { implicit request =>
    FormController.userForm.bindFromRequest.fold(
      formWithErrors => {
        // binding failure, you retrieve the form containing errors:
        BadRequest(views.html.form(formWithErrors))
      },
      userData => {
        
        val newUser = model.UserData(userData.name, userData.age)
        val id = 1
        Ok(views.html.formconfirm(userData))
      }
    )
  }
}

object FormController {
  val userForm = Form(
    mapping(
      "name" -> nonEmptyText,
      "age" -> number(min = 0, max = 100)
    )(UserData.apply)(UserData.unapply)
  )
} 
开发者ID:pbernet,项目名称:play-scala-starter-example,代码行数:43,代码来源:FormController.scala


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