diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/Console.scala | 54 |
1 files changed, 52 insertions, 2 deletions
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 @@ | |||
1 | package controllers | 1 | package controllers |
2 | 2 | ||
3 | import java.sql.Timestamp | ||
4 | |||
3 | import play.api._ | 5 | import play.api._ |
6 | import play.api.data._ | ||
7 | import play.api.data.Forms._ | ||
4 | import play.api.mvc._ | 8 | import play.api.mvc._ |
5 | 9 | ||
10 | import play.api.db.slick._ | ||
11 | import play.api.db.slick.Config.driver.simple._ | ||
12 | import play.api.Play.current | ||
13 | |||
14 | import scala.concurrent.Future | ||
15 | |||
16 | import models._ | ||
17 | |||
18 | |||
19 | case class CommandData(command: String) | ||
20 | |||
6 | object Console extends Controller { | 21 | object Console extends Controller { |
7 | 22 | ||
8 | def console = Action { | 23 | val commandForm = Form( |
9 | Redirect("/") | 24 | mapping( |
25 | "command" -> nonEmptyText | ||
26 | )(CommandData.apply)(CommandData.unapply) | ||
27 | ) | ||
28 | |||
29 | def console = Auth { implicit request => | ||
30 | if (request.account.isEmpty) { | ||
31 | Redirect(routes.Application.index()) | ||
32 | } else { | ||
33 | |||
34 | DB.withSession { implicit session => | ||
35 | val commandData = commandForm.bindFromRequest.get | ||
36 | |||
37 | val grant = commandData.command match { | ||
38 | case "kaching" => 1000 | ||
39 | case "motherlode" => 5000 | ||
40 | case _ => 0 | ||
41 | } | ||
42 | |||
43 | if (grant > 0) { | ||
44 | Tables.Transactions += Tables.Transaction( | ||
45 | uuid = java.util.UUID.randomUUID.toString, | ||
46 | userUuid = request.account.get.userUuid.get, | ||
47 | transactionDate = new Timestamp(new java.util.Date().getTime), | ||
48 | amount = grant, | ||
49 | label = commandData.command | ||
50 | ) | ||
51 | |||
52 | Redirect(routes.Application.index()).flashing("success" -> commandData.command) | ||
53 | } else { | ||
54 | Redirect(routes.Application.index()) | ||
55 | } | ||
56 | |||
57 | } | ||
58 | } | ||
59 | |||
10 | } | 60 | } |
11 | 61 | ||
12 | } | 62 | } |