aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/Console.scala
blob: b3e78043772b0094da43ae6532b94ba17ea7f68c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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())
        }

      }
    }

  }

}