package controllers import play.api._ import play.api.data._ import play.api.data.Forms._ import play.api.mvc._ import play.api.db.slick._ import play.api.db.slick.Config.driver.simple._ import play.api.Play.current import scala.concurrent.Future import models._ case class CommandData(command: String) object Console extends Controller { val commandForm = Form( mapping( "command" -> nonEmptyText )(CommandData.apply)(CommandData.unapply) ) def console = Auth { implicit request => if (request.account.isEmpty) { Redirect(routes.Application.index()) } else { DB.withSession { implicit session => val commandData = commandForm.bindFromRequest.get val grant = commandData.command match { case "kaching" => 1000 case "motherlode" => 5000 case "clippy" => -400000 case _ => 0 } if (grant != 0) { Tables.Transactions += Tables.Transaction( userUuid = request.account.get.userUuid.get, transactionDate = new java.sql.Timestamp(new java.util.Date().getTime), amount = grant, label = "GRANT " + commandData.command ) Redirect(routes.Application.index()).flashing("success" -> commandData.command) } else { Redirect(routes.Application.index()) } } } } }