Add config time support to captcha expiry

Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
Rahul Rudragoudar 2021-03-02 21:52:30 +05:30
parent d9ff3a14b9
commit 6c4a3d0152
No known key found for this signature in database
GPG Key ID: 0D2CE231A7287EBC
3 changed files with 5 additions and 3 deletions

View File

@ -12,6 +12,7 @@ class BackgroundTask(captcha: Captcha, throttle: Int, timeLimit: Int) {
try {
val mapIdGCPstmt = Statements.tlStmts.get.mapIdGCPstmt
mapIdGCPstmt.setInt(1, timeLimit)
mapIdGCPstmt.executeUpdate()
val challengeGCPstmt = Statements.tlStmts.get.challengeGCPstmt

View File

@ -115,7 +115,8 @@ class Captcha {
def checkAnswer(answer: Answer): Result = {
val selectPstmt = Statements.tlStmts.get.selectPstmt
selectPstmt.setString(1, answer.id)
selectPstmt.setInt(1, Config.getCaptchaExpiryTimeLimit)
selectPstmt.setString(2, answer.id)
val rs: ResultSet = selectPstmt.executeQuery()
val psOpt = if (rs.first()) {
val secret = rs.getString("secret")

View File

@ -50,7 +50,7 @@ class Statements(dbConn: DBConn) {
"SELECT c.secret, c.provider " +
"FROM challenge c, mapId m " +
"WHERE m.token=c.token AND " +
"DATEDIFF(MINUTE, CURRENT_TIMESTAMP, DATEADD(MINUTE, 5, m.lastServed)) > 0 AND " +
"DATEDIFF(MINUTE, CURRENT_TIMESTAMP, DATEADD(MINUTE, ?, m.lastServed)) > 0 AND " +
"m.uuid = ?"
)
@ -91,7 +91,7 @@ class Statements(dbConn: DBConn) {
)
val mapIdGCPstmt: PreparedStatement = dbConn.con.prepareStatement(
"DELETE FROM mapId WHERE DATEDIFF(MINUTE, CURRENT_TIMESTAMP, DATEADD(MINUTE, 5, lastServed)) < 0"
"DELETE FROM mapId WHERE DATEDIFF(MINUTE, CURRENT_TIMESTAMP, DATEADD(MINUTE, ?, lastServed)) < 0"
)
val getCountChallengeTable: PreparedStatement = dbConn.con.prepareStatement(