mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-12 22:43:20 -05:00
Merge pull request #16 from rr83019/master
Added GET request support to media end point and contentType field in DB
This commit is contained in:
commit
28e4a62707
@ -7,7 +7,7 @@ import java.awt.Font
|
|||||||
import java.awt.Color
|
import java.awt.Color
|
||||||
|
|
||||||
class FilterChallenge extends ChallengeProvider {
|
class FilterChallenge extends ChallengeProvider {
|
||||||
def getId = "filter"
|
def getId = "FilterChallenge"
|
||||||
def returnChallenge(): Challenge = {
|
def returnChallenge(): Challenge = {
|
||||||
val filterTypes = List(new FilterType1, new FilterType2)
|
val filterTypes = List(new FilterType1, new FilterType2)
|
||||||
val r = new scala.util.Random
|
val r = new scala.util.Random
|
||||||
|
@ -18,8 +18,8 @@ import scala.Array
|
|||||||
class Captcha {
|
class Captcha {
|
||||||
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, image blob)")
|
stmt.execute("CREATE TABLE IF NOT EXISTS challenge(token varchar, id varchar, secret varchar, provider varchar, contentType varchar, image blob)")
|
||||||
val insertPstmt: PreparedStatement = con.prepareStatement("INSERT INTO challenge(token, id, secret, provider, image) VALUES (?, ?, ?, ?, ?)")
|
val insertPstmt: PreparedStatement = con.prepareStatement("INSERT INTO challenge(token, id, secret, provider, contentType, image) 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 WHERE token = ?")
|
||||||
|
|
||||||
@ -48,7 +48,8 @@ class Captcha {
|
|||||||
insertPstmt.setString(2, provider.getId)
|
insertPstmt.setString(2, provider.getId)
|
||||||
insertPstmt.setString(3, challenge.secret)
|
insertPstmt.setString(3, challenge.secret)
|
||||||
insertPstmt.setString(4, providerMap)
|
insertPstmt.setString(4, providerMap)
|
||||||
insertPstmt.setBlob(5, blob)
|
insertPstmt.setString(5, challenge.contentType)
|
||||||
|
insertPstmt.setBlob(6, blob)
|
||||||
insertPstmt.executeUpdate()
|
insertPstmt.executeUpdate()
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
@ -65,7 +66,8 @@ class Captcha {
|
|||||||
insertPstmt.setString(2, provider.getId)
|
insertPstmt.setString(2, provider.getId)
|
||||||
insertPstmt.setString(3, challenge.secret)
|
insertPstmt.setString(3, challenge.secret)
|
||||||
insertPstmt.setString(4, providerMap)
|
insertPstmt.setString(4, providerMap)
|
||||||
insertPstmt.setBlob(5, blob)
|
insertPstmt.setString(5, challenge.contentType)
|
||||||
|
insertPstmt.setBlob(6, blob)
|
||||||
insertPstmt.executeUpdate()
|
insertPstmt.executeUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,14 +126,20 @@ class Server(port: Int){
|
|||||||
},"POST")
|
},"POST")
|
||||||
|
|
||||||
host.addContext("/v1/media",(req, resp) => {
|
host.addContext("/v1/media",(req, resp) => {
|
||||||
val body = req.getJson()
|
var id = Id(null)
|
||||||
val json = parse(body)
|
if ("GET" == req.getMethod()){
|
||||||
val id = json.extract[Id]
|
val params = req.getParams()
|
||||||
|
id = Id(params.get("id"))
|
||||||
|
} else {
|
||||||
|
val body = req.getJson()
|
||||||
|
val json = parse(body)
|
||||||
|
id = json.extract[Id]
|
||||||
|
}
|
||||||
val image = captcha.getCaptcha(id)
|
val image = captcha.getCaptcha(id)
|
||||||
resp.getHeaders().add("Content-Type","image/png")
|
resp.getHeaders().add("Content-Type","image/png")
|
||||||
resp.send(200, image)
|
resp.send(200, image)
|
||||||
0
|
0
|
||||||
},"POST")
|
},"POST", "GET")
|
||||||
|
|
||||||
host.addContext("/v1/answer",(req, resp) => {
|
host.addContext("/v1/answer",(req, resp) => {
|
||||||
val body = req.getJson()
|
val body = req.getJson()
|
||||||
|
Loading…
Reference in New Issue
Block a user