mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-27 13:03:12 -05:00
Minor fixes
Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
parent
a63cf3976d
commit
d65d050038
@ -182,6 +182,7 @@ class RateLimiter extends DBConn {
|
|||||||
val allowance = rate
|
val allowance = rate
|
||||||
|
|
||||||
def validateUser(user: Int) : Boolean = {
|
def validateUser(user: Int) : Boolean = {
|
||||||
|
synchronized {
|
||||||
val allow = if(userLastActive.contains(user)){
|
val allow = if(userLastActive.contains(user)){
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
@ -199,6 +200,7 @@ class RateLimiter extends DBConn {
|
|||||||
}
|
}
|
||||||
allow
|
allow
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def checkLimit(user: Int): Boolean = {
|
def checkLimit(user: Int): Boolean = {
|
||||||
synchronized {
|
synchronized {
|
||||||
@ -228,10 +230,9 @@ class Server(port: Int){
|
|||||||
implicit val formats = DefaultFormats
|
implicit val formats = DefaultFormats
|
||||||
|
|
||||||
host.addContext("/v1/captcha",(req, resp) => {
|
host.addContext("/v1/captcha",(req, resp) => {
|
||||||
val accessToken = if(req.getHeaders().get("access-token") != null){
|
val accessToken = Option(req.getHeaders().get("access-token")).map(_.toInt)
|
||||||
req.getHeaders().get("access-token").toInt
|
val access = accessToken.map(t => rateLimiter.validateUser(t) && rateLimiter.checkLimit(t)).getOrElse(false)
|
||||||
} else 0
|
val id = if(access){
|
||||||
val id = if(true == rateLimiter.validateUser(accessToken) && true == rateLimiter.checkLimit(accessToken)){
|
|
||||||
val body = req.getJson()
|
val body = req.getJson()
|
||||||
val json = parse(body)
|
val json = parse(body)
|
||||||
val param = json.extract[Parameters]
|
val param = json.extract[Parameters]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user