mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-12 22:43:20 -05:00
Merge pull request #35 from rr83019/master
Private ID to Public ID mapping
This commit is contained in:
commit
93f7161b6e
@ -16,15 +16,18 @@ import java.util.Base64
|
|||||||
import org.json4s.jackson.Serialization
|
import org.json4s.jackson.Serialization
|
||||||
import org.json4s.jackson.Serialization.{read, write}
|
import org.json4s.jackson.Serialization.{read, write}
|
||||||
import java.util.concurrent._
|
import java.util.concurrent._
|
||||||
|
import java.util.UUID
|
||||||
import scala.Array
|
import scala.Array
|
||||||
|
|
||||||
class Captcha(throttle: Int) {
|
class Captcha(throttle: Int) {
|
||||||
val con: Connection = DriverManager.getConnection("jdbc:h2:./captcha", "sa", "")
|
val con: Connection = DriverManager.getConnection("jdbc:h2:./captcha", "sa", "")
|
||||||
val stmt: Statement = con.createStatement()
|
val stmt: Statement = con.createStatement()
|
||||||
stmt.execute("CREATE TABLE IF NOT EXISTS challenge(token varchar, id varchar, secret varchar, provider varchar, contentType varchar, image blob, solved boolean default False)")
|
stmt.execute("CREATE TABLE IF NOT EXISTS challenge(token varchar, id varchar, secret varchar, provider varchar, contentType varchar, image blob, solved boolean default False, PRIMARY KEY(token))")
|
||||||
|
stmt.execute("CREATE TABLE IF NOT EXISTS mapId(uuid varchar, token varchar, PRIMARY KEY(uuid), FOREIGN KEY(token) REFERENCES challenge(token))")
|
||||||
val insertPstmt: PreparedStatement = con.prepareStatement("INSERT INTO challenge(token, id, secret, provider, contentType, image) VALUES (?, ?, ?, ?, ?, ?)")
|
val insertPstmt: PreparedStatement = con.prepareStatement("INSERT INTO challenge(token, id, secret, provider, contentType, image) VALUES (?, ?, ?, ?, ?, ?)")
|
||||||
|
val mapPstmt: PreparedStatement = con.prepareStatement("INSERT INTO mapId(uuid, token) VALUES (?, ?)")
|
||||||
val selectPstmt: PreparedStatement = con.prepareStatement("SELECT secret, provider FROM challenge WHERE token = ?")
|
val selectPstmt: PreparedStatement = con.prepareStatement("SELECT secret, provider FROM challenge WHERE token = ?")
|
||||||
val imagePstmt: PreparedStatement = con.prepareStatement("SELECT image FROM challenge WHERE token = ?")
|
val imagePstmt: PreparedStatement = con.prepareStatement("SELECT image FROM challenge c, mapId m WHERE c.token=m.token AND m.uuid = ?")
|
||||||
val updatePstmt: PreparedStatement = con.prepareStatement("UPDATE challenge SET solved = True WHERE token = ?")
|
val updatePstmt: PreparedStatement = con.prepareStatement("UPDATE challenge SET solved = True WHERE token = ?")
|
||||||
|
|
||||||
val filters = Map("FilterChallenge" -> new FilterChallenge,
|
val filters = Map("FilterChallenge" -> new FilterChallenge,
|
||||||
@ -97,7 +100,16 @@ class Captcha(throttle: Int) {
|
|||||||
} else {
|
} else {
|
||||||
generateChallenge(param)
|
generateChallenge(param)
|
||||||
}
|
}
|
||||||
Id(id)
|
val uuid = getUUID(id)
|
||||||
|
Id(uuid)
|
||||||
|
}
|
||||||
|
|
||||||
|
def getUUID(id: String): String = {
|
||||||
|
val uuid = UUID.randomUUID().toString
|
||||||
|
mapPstmt.setString(1,uuid)
|
||||||
|
mapPstmt.setString(2,id)
|
||||||
|
mapPstmt.executeUpdate()
|
||||||
|
uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
def checkAnswer(answer: Answer): Boolean = {
|
def checkAnswer(answer: Answer): Boolean = {
|
||||||
@ -183,7 +195,7 @@ class Server(port: Int){
|
|||||||
|
|
||||||
object LCFramework{
|
object LCFramework{
|
||||||
def main(args: scala.Array[String]) {
|
def main(args: scala.Array[String]) {
|
||||||
val captcha = new Captcha(50)
|
val captcha = new Captcha(2)
|
||||||
val server = new Server(8888)
|
val server = new Server(8888)
|
||||||
captcha.beginThread(2)
|
captcha.beginThread(2)
|
||||||
server.start()
|
server.start()
|
||||||
|
Loading…
Reference in New Issue
Block a user