From fd5ae4b50e326097194280ad05f19445531338b4 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sun, 8 Feb 2015 11:10:16 +0100 Subject: Implement money cheat codes --- app/controllers/Console.scala | 54 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/Console.scala b/app/controllers/Console.scala index 93bc5d5..58a2478 100644 --- a/app/controllers/Console.scala +++ b/app/controllers/Console.scala @@ -1,12 +1,62 @@ package controllers +import java.sql.Timestamp + 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 { - def console = Action { - Redirect("/") + 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 _ => 0 + } + + if (grant > 0) { + Tables.Transactions += Tables.Transaction( + uuid = java.util.UUID.randomUUID.toString, + userUuid = request.account.get.userUuid.get, + transactionDate = new Timestamp(new java.util.Date().getTime), + amount = grant, + label = commandData.command + ) + + Redirect(routes.Application.index()).flashing("success" -> commandData.command) + } else { + Redirect(routes.Application.index()) + } + + } + } + } } -- cgit v1.2.3