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


Scala Flash类代码示例

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


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

示例1: ContactController

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

import javax.inject._

import models.{ContactDB, MongoConnector}
import play.api._
import play.api.i18n.Messages
import play.api.mvc._
import play.api.mvc.{Action, Controller, Flash, Request}
import play.api.data.Form
import play.api.data.Forms._
import play.api.data.Forms.{mapping, nonEmptyText}


import play.api.data.Forms.{longNumber, mapping, nonEmptyText}
import play.api.i18n.Messages.Implicits._
import play.api.Play.current
import scala.concurrent.ExecutionContext.Implicits.global



@Singleton
class ContactController  @Inject() extends Controller{

  val contactForm = Form(tuple(
    "Name" -> text,
      "Email" -> text,
      "Message" -> text
    ))

  def saveContact = Action {
    implicit request =>
      val newContactForm = contactForm.bindFromRequest()
      newContactForm.fold(success = {
        newContact =>
          //Create a contact object using form data
          val newContactID = ContactDB.findNextID()
          print(newContactID)
          println(newContact._2)
          val newContactRequest = new ContactDB(newContactID, newContact._1, newContact._2, newContact._3)

          //Insert into contact collection
          MongoConnector.collectionContact.insert(newContactRequest)
          Ok(views.html.home())
      }, hasErrors = {
        form =>
          Redirect(routes.ContactController.contact()).flashing(Flash(form.data) + ("error" -> Messages("contact.validation.errors")))
      })
      }

  def contact = Action {
    implicit request =>
      val form = if (request2flash.get("error").isDefined)
        contactForm.bind(request2flash.data)
      else
        contactForm
      Ok(views.html.contact(form))
  }


} 
开发者ID:nkaraolis,项目名称:NBGardensNewPlay,代码行数:62,代码来源:ContactController.scala

示例2: Application

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

import com.google.inject.Inject
import lunatech.lunchplanner.common.DBConnection
import lunatech.lunchplanner.models.User
import lunatech.lunchplanner.services.{ MenuPerDayPerPersonService, UserService }
import lunatech.lunchplanner.viewModels.MenuPerDayPerPersonForm
import play.api.i18n.{ I18nSupport, MessagesApi }
import play.api.mvc.{ Controller, Flash }
import play.api.{ Configuration, Environment }

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

class Application @Inject() (
  userService: UserService,
  menuPerDayPerPersonService: MenuPerDayPerPersonService,
  val connection: DBConnection,
  val environment: Environment,
  val messagesApi: MessagesApi,
  val configuration: Configuration)
  extends Controller with Secured with I18nSupport {

  def index = IsAuthenticatedAsync { username =>
    implicit request =>
      userService.getByEmailAddress(username).flatMap(currentUser =>
        getIndex(currentUser))
  }

  private def getIndex(normalUser: Option[User])(implicit flash: Flash) =
    normalUser match {
      case Some(user) => getMenuPerDayPerPerson(user)
      case None => Future.successful(Unauthorized)
    }

  private def getMenuPerDayPerPerson(user: User)(implicit flash: Flash) = {
    val userIsAdmin = userService.isAdminUser(user.emailAddress)
    menuPerDayPerPersonService.getAllMenuWithNamePerDayWithDishesPerPerson(user.uuid).map(_.toArray)
      .map(menusPerDayPerPerson =>
        Ok(views.html.menuPerDayPerPerson(
          user.copy(isAdmin = userIsAdmin),
          menusPerDayPerPerson,
          MenuPerDayPerPersonForm.menuPerDayPerPersonForm)))
  }
} 
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:46,代码来源:Application.scala

示例3: SignupController

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

import javax.inject.{Inject, Singleton}

import com.mohiva.play.silhouette.api.Silhouette
import forms.SignupForm
import play.api.i18n.{I18nSupport, Messages, MessagesApi}
import play.api.mvc.{Action, Controller, Flash}
import utils.auth.DefaultEnv


@Singleton
class SignupController @Inject()
(
  val messagesApi: MessagesApi,
  silhouette: Silhouette[DefaultEnv]
) extends Controller with I18nSupport {

  def createUser = Action { implicit request =>
    println("trying to create!")
    SignupForm.form.bindFromRequest.fold(
      hasErrors = { form =>
        Redirect(routes.SignupController.registerPage())
          .flashing(Flash(form.data) + ("error" -> Messages("validation.errors")))
      },
      success = { signupData =>
        println(s"creating a new user $signupData")
        Redirect(routes.BookmarkController.list())
      }
    )
  }

  
  def registerPage = silhouette.UnsecuredAction { implicit request =>
    Ok(views.html.users.register(SignupForm.form))
  }
} 
开发者ID:lostMohican,项目名称:bookmaarket,代码行数:38,代码来源:SignupController.scala

示例4: UserFeedback

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

import play.api.data.Form
import play.api.mvc.{Flash, RequestHeader}
import UserFeedback.{Feedback, Success, Yes, No}

case class UserFeedback(message: String, isError: Boolean) {
  def toSeq: Seq[(String, String)] = Seq(
    Feedback -> message,
    Success -> (if (isError) No else Yes)
  )
}

object UserFeedback {
  val Feedback = "feedback"
  val Success = "success"
  val Yes = "yes"
  val No = "no"

  def success(message: String) = UserFeedback(message, isError = false)

  def error(message: String) = UserFeedback(message, isError = true)

  def flashed(request: RequestHeader): Option[UserFeedback] =
    flashed(request.flash)

  def flashed(flash: Flash, textKey: String = Feedback): Option[UserFeedback] =
    for {
      message <- flash get textKey
      isError = (flash get Success) contains No
    } yield UserFeedback(message, isError)

  def formed(form: Form[_]) =
    form.globalError.orElse(form.errors.headOption)
      .map(formError => error(formError.message))
} 
开发者ID:malliina,项目名称:logstreams,代码行数:37,代码来源:UserFeedback.scala

示例5: saveChanges

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

import javax.inject._
import models._
import play.api._
import play.api.data.Forms._
import play.api.data.Forms.{longNumber, mapping, nonEmptyText}
import play.api.i18n.Messages
import play.api.i18n.Messages.Implicits._
import play.api.mvc._
import play.api.mvc.{Action, Controller, Flash, Request}
import play.api.Play.current
import play.api.data.Form
import play.api.mvc.Session
import scala.concurrent.ExecutionContext.Implicits.global


  def saveChanges = Action {
    implicit request =>
      val editCustomerForm = updateForm.bindFromRequest()
      editCustomerForm.fold(hasErrors = {
        form =>
          Redirect(routes.UpdateAccountController.updateAccount()).flashing(Flash(form.data) + ("error" -> Messages("updateAccount.validation.errors")))
      }, success = {
        editCustomer =>
          val currentUsername = CustomerDB.findByUsername(request.session.get("username").get).head.getAs[String]("username").get
          if (!(editCustomerForm.data("First Name").length == 0)) {
            CustomerDB.updateUserField(currentUsername, "fName", editCustomerForm.data("First Name"))
          }
          if (!(editCustomerForm.data("Last Name").length == 0)) {
            CustomerDB.updateUserField(currentUsername, "lName", editCustomerForm.data("Last Name"))
          }
          if (!(editCustomerForm.data("Email").length == 0)) {
            CustomerDB.updateUserField(currentUsername, "email", editCustomerForm.data("Email"))
          }
          if (!(editCustomerForm.data("Telephone").length == 0)) {
            CustomerDB.updateUserField(currentUsername, "phone", editCustomerForm.data("Telephone"))
          }
          if (!(editCustomerForm.data("Username").length == 0)) {
            CustomerDB.updateUserField(currentUsername, "username", editCustomerForm.data("Username"))
          }
          if (!(editCustomerForm.data("Password").length == 0)) {
            CustomerDB.updateUserField(currentUsername, "password", editCustomerForm.data("Password"))
          }
          val currentCustomer = CustomerDB.findByUsername(currentUsername).head
          val customerSession = request.session +
            ("customerID" -> currentCustomer.getAs[Int]("customerID").get.toString) +
            ("firstName" -> currentCustomer.getAs[String]("fName").get) +
            ("lastName" -> currentCustomer.getAs[String]("lName").get) +
            ("email" -> currentCustomer.getAs[String]("email").get) +
            ("phone" -> currentCustomer.getAs[String]("phone").get) +
            ("username" -> currentCustomer.getAs[String]("username").get)
          Redirect(routes.UserAccountController.userAccount()).withSession(customerSession)
      })
  }
} 
开发者ID:nkaraolis,项目名称:NBGardensNewPlay,代码行数:57,代码来源:UpdateAccountController.scala

示例6: FormTestController

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

import javax.inject.Inject

import model.{ExampleData, MarriedStatus}
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.{I18nSupport, Messages, MessagesApi}
import play.api.mvc.{Action, Controller, Flash}


class FormTestController @Inject()(val messagesApi: MessagesApi)
  extends Controller with I18nSupport {


  val exampleForm = Form(
    mapping(
      "id" -> longNumber,
      "name" -> nonEmptyText(minLength = 5, maxLength = 20),
      "married" -> mapping(
        "ifMarried" -> boolean,
        "sinceThen" -> optional(date),
        "dateTo"->optional(date),
        "spouseId" -> optional(longNumber)
      )(MarriedStatus.apply)(MarriedStatus.unapply)
    )(ExampleData.apply)(ExampleData.unapply)
  )

  def formTest() = Action { implicit req =>
    Ok(views.html.examples.exampleDataDetails(exampleForm))
  }

  def saveController = Action { implicit req =>
    val newExampleForm = exampleForm.bindFromRequest()

    newExampleForm.fold(
      hasErrors = form => Redirect(routes.FormTestController.formTest()).flashing(Flash(form.data) +
        ("error" -> Messages("validation.error"))),
      example => {
        Redirect(routes.FormTestController.formTest()).flashing("success" -> example.toString)
      }
    )
  }

} 
开发者ID:lszku,项目名称:ProductDatabase,代码行数:46,代码来源:FormTestController.scala

示例7: CatalogueController

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

import javax.inject._

import models.{CatalogueDB, MongoConnector}
import play.api._
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.Messages
import play.api.mvc._
import play.api.mvc.{Action, Controller, Flash, Request}
import play.api.data.Forms.{longNumber, mapping, nonEmptyText}
import play.api.i18n.Messages.Implicits._
import play.api.Play.current
import scala.concurrent.ExecutionContext.Implicits.global


@Singleton
class CatalogueController @Inject() extends Controller{

  val catalogueForm = Form(tuple(
      "Name" -> nonEmptyText,
      "Email" -> nonEmptyText,
      "Address Line 1" -> nonEmptyText,
      "Address Line 2" -> nonEmptyText,
      "Town/City" -> nonEmptyText,
      "Postcode" -> nonEmptyText
    ))

  def saveCatalogue = Action {
    implicit request =>
      val newCatalogueForm = catalogueForm.bindFromRequest()
      newCatalogueForm.fold(success = {
        newCatalogue =>
          //Create a contact object using form data
          val newCatalogueID = CatalogueDB.findNextID()
          print(newCatalogueID)
          println(newCatalogue._2)
          val newCatalogueRequest = new CatalogueDB(newCatalogueID, newCatalogue._1, newCatalogue._2, newCatalogue._3, newCatalogue._4, newCatalogue._5, newCatalogue._6)

          //Insert into contact collection
          MongoConnector.collectionCatalogue.insert(newCatalogueRequest)
          Ok(views.html.home())
      }, hasErrors = {
        form =>
          Redirect(routes.CatalogueController.catalogue()).flashing(Flash(form.data) + ("error" -> Messages("catalogue.validation.errors")))
      })
  }

  def catalogue = Action {
    implicit request =>
      val form = if (request2flash.get("error").isDefined)
        catalogueForm.bind(request2flash.data)
      else
        catalogueForm
      Ok(views.html.catalogue(form))
  }


} 
开发者ID:nkaraolis,项目名称:NBGardensNewPlay,代码行数:61,代码来源:CatalogueController.scala


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