2012-03-20 18:08:32 -06:00
|
|
|
package controllers
|
|
|
|
|
2013-12-27 15:12:20 -07:00
|
|
|
import lila.user.UserContext
|
2018-05-10 16:34:17 -06:00
|
|
|
import lila.common.Form.trueish
|
2018-12-18 20:29:08 -07:00
|
|
|
import lila.common.IsMobile
|
2012-05-11 15:45:45 -06:00
|
|
|
|
2012-04-07 06:22:33 -06:00
|
|
|
import play.api.mvc.RequestHeader
|
2012-03-20 18:08:32 -06:00
|
|
|
|
|
|
|
trait RequestGetter {
|
|
|
|
|
2013-12-27 15:12:20 -07:00
|
|
|
protected def get(name: String)(implicit ctx: UserContext): Option[String] = get(name, ctx.req)
|
2012-05-20 17:18:25 -06:00
|
|
|
|
2012-09-10 02:48:23 -06:00
|
|
|
protected def get(name: String, req: RequestHeader): Option[String] =
|
2014-03-26 15:11:14 -06:00
|
|
|
req.queryString get name flatMap (_.headOption) filter (_.nonEmpty)
|
2012-03-20 18:08:32 -06:00
|
|
|
|
2013-12-27 15:12:20 -07:00
|
|
|
protected def getInt(name: String)(implicit ctx: UserContext) =
|
2019-11-28 18:34:46 -07:00
|
|
|
get(name) flatMap (_.toIntOption)
|
2012-03-20 18:08:32 -06:00
|
|
|
|
2013-05-31 06:27:18 -06:00
|
|
|
protected def getInt(name: String, req: RequestHeader): Option[Int] =
|
2019-11-28 18:34:46 -07:00
|
|
|
req.queryString get name flatMap (_.headOption) flatMap (_.toIntOption)
|
2014-02-11 14:07:28 -07:00
|
|
|
|
2018-03-07 17:20:00 -07:00
|
|
|
protected def getLong(name: String)(implicit ctx: UserContext) =
|
2019-11-28 18:34:46 -07:00
|
|
|
get(name) flatMap (_.toLongOption)
|
2018-03-07 17:20:00 -07:00
|
|
|
|
2018-03-31 19:48:52 -06:00
|
|
|
protected def getLong(name: String, req: RequestHeader) =
|
2019-11-28 18:34:46 -07:00
|
|
|
get(name, req) flatMap (_.toLongOption)
|
2018-03-31 19:48:52 -06:00
|
|
|
|
2014-02-11 14:07:28 -07:00
|
|
|
protected def getBool(name: String)(implicit ctx: UserContext) =
|
2018-04-04 08:06:08 -06:00
|
|
|
(getInt(name) exists trueish) || (get(name) exists trueish)
|
2014-04-26 06:03:02 -06:00
|
|
|
|
|
|
|
protected def getBool(name: String, req: RequestHeader) =
|
2018-04-04 08:06:08 -06:00
|
|
|
(getInt(name, req) exists trueish) || (get(name, req) exists trueish)
|
2014-06-06 03:43:00 -06:00
|
|
|
|
2015-05-04 16:19:27 -06:00
|
|
|
protected def getBoolOpt(name: String)(implicit ctx: UserContext) =
|
2020-05-05 22:11:15 -06:00
|
|
|
(getInt(name) map trueish) orElse (get(name) map trueish)
|
2015-05-04 16:19:27 -06:00
|
|
|
|
2014-06-06 03:43:00 -06:00
|
|
|
protected def getBoolOpt(name: String, req: RequestHeader) =
|
2020-05-05 22:11:15 -06:00
|
|
|
(getInt(name, req) map trueish) orElse (get(name, req) map trueish)
|
2018-12-18 20:29:08 -07:00
|
|
|
|
|
|
|
protected def getMobile(implicit ctx: UserContext) =
|
|
|
|
IsMobile(getBool("mobile"))
|
2012-03-20 18:08:32 -06:00
|
|
|
}
|