Minor fixes

Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
Rahul Rudragoudar 2019-04-07 20:50:56 +05:30
parent fe9138dbaf
commit f3f8900fd4
No known key found for this signature in database
GPG Key ID: 5825856C50762765

View File

@ -92,16 +92,15 @@ class Captcha(throttle: Int) {
def getChallenge(param: Parameters): Id = {
val rs = stmt.executeQuery("SELECT token FROM challenge WHERE solved=FALSE LIMIT 1")
var id: String = null
if(rs.next()){
id = rs.getString("token")
val id = if(rs.next()){
rs.getString("token")
} else {
id = generateChallenge(param)
generateChallenge(param)
}
Id(id)
}
def getAnswer(answer: Answer): Boolean = {
def checkAnswer(answer: Answer): Boolean = {
selectPstmt.setString(1, answer.id)
val rs: ResultSet = selectPstmt.executeQuery()
rs.next()
@ -169,7 +168,7 @@ class Server(port: Int){
val body = req.getJson()
val json = parse(body)
val answer = json.extract[Answer]
val result = captcha.getAnswer(answer)
val result = captcha.checkAnswer(answer)
resp.getHeaders().add("Content-Type","application/json")
val responseContent = if(result) """{"result":"True"}""" else """{"result":"False"}"""
resp.send(200,responseContent)