Minor fixes

Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
Rahul Rudragoudar 2019-06-20 11:45:29 +05:30
parent a63cf3976d
commit d65d050038
No known key found for this signature in database
GPG Key ID: EC2AAF721D545305

View File

@ -182,6 +182,7 @@ class RateLimiter extends DBConn {
val allowance = rate
def validateUser(user: Int) : Boolean = {
synchronized {
val allow = if(userLastActive.contains(user)){
true
} else {
@ -199,6 +200,7 @@ class RateLimiter extends DBConn {
}
allow
}
}
def checkLimit(user: Int): Boolean = {
synchronized {
@ -228,10 +230,9 @@ class Server(port: Int){
implicit val formats = DefaultFormats
host.addContext("/v1/captcha",(req, resp) => {
val accessToken = if(req.getHeaders().get("access-token") != null){
req.getHeaders().get("access-token").toInt
} else 0
val id = if(true == rateLimiter.validateUser(accessToken) && true == rateLimiter.checkLimit(accessToken)){
val accessToken = Option(req.getHeaders().get("access-token")).map(_.toInt)
val access = accessToken.map(t => rateLimiter.validateUser(t) && rateLimiter.checkLimit(t)).getOrElse(false)
val id = if(access){
val body = req.getJson()
val json = parse(body)
val param = json.extract[Parameters]