mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-03-18 09:48:24 -04:00
renamed Captcha to CaptchaManager
Signed-off-by: hrj <harshad.rj@gmail.com>
This commit is contained in:
parent
497b88f0d3
commit
52b071d680
@ -1,6 +1,6 @@
|
|||||||
package lc
|
package lc
|
||||||
|
|
||||||
import lc.core.{CaptchaProviders, Captcha, Config}
|
import lc.core.{CaptchaProviders, CaptchaManager, Config}
|
||||||
import lc.server.Server
|
import lc.server.Server
|
||||||
import lc.background.BackgroundTask
|
import lc.background.BackgroundTask
|
||||||
import lc.database.Statements
|
import lc.database.Statements
|
||||||
@ -15,13 +15,13 @@ object LCFramework {
|
|||||||
val config = new Config(configFilePath)
|
val config = new Config(configFilePath)
|
||||||
Statements.maxAttempts = config.maxAttempts
|
Statements.maxAttempts = config.maxAttempts
|
||||||
val captchaProviders = new CaptchaProviders(config = config)
|
val captchaProviders = new CaptchaProviders(config = config)
|
||||||
val captcha = new Captcha(config = config, captchaProviders = captchaProviders)
|
val captchaManager = new CaptchaManager(config = config, captchaProviders = captchaProviders)
|
||||||
val backgroundTask = new BackgroundTask(config = config, captcha = captcha)
|
val backgroundTask = new BackgroundTask(config = config, captchaManager = captchaManager)
|
||||||
backgroundTask.beginThread(delay = config.threadDelay)
|
backgroundTask.beginThread(delay = config.threadDelay)
|
||||||
val server = new Server(
|
val server = new Server(
|
||||||
address = config.address,
|
address = config.address,
|
||||||
port = config.port,
|
port = config.port,
|
||||||
captcha = captcha,
|
captchaManager = captchaManager,
|
||||||
playgroundEnabled = config.playgroundEnabled,
|
playgroundEnabled = config.playgroundEnabled,
|
||||||
corsHeader = config.corsHeader
|
corsHeader = config.corsHeader
|
||||||
)
|
)
|
||||||
|
@ -2,11 +2,11 @@ package lc.background
|
|||||||
|
|
||||||
import lc.database.Statements
|
import lc.database.Statements
|
||||||
import java.util.concurrent.{ScheduledThreadPoolExecutor, TimeUnit}
|
import java.util.concurrent.{ScheduledThreadPoolExecutor, TimeUnit}
|
||||||
import lc.core.{Captcha, Config}
|
import lc.core.{CaptchaManager, Config}
|
||||||
import lc.core.{Parameters, Size}
|
import lc.core.{Parameters, Size}
|
||||||
import lc.misc.HelperFunctions
|
import lc.misc.HelperFunctions
|
||||||
|
|
||||||
class BackgroundTask(config: Config, captcha: Captcha) {
|
class BackgroundTask(config: Config, captchaManager: CaptchaManager) {
|
||||||
|
|
||||||
private val task = new Runnable {
|
private val task = new Runnable {
|
||||||
def run(): Unit = {
|
def run(): Unit = {
|
||||||
@ -28,7 +28,7 @@ class BackgroundTask(config: Config, captcha: Captcha) {
|
|||||||
val throttle = (config.throttle * 1.1).toInt - imageNum
|
val throttle = (config.throttle * 1.1).toInt - imageNum
|
||||||
|
|
||||||
for (i <- 0 until throttle) {
|
for (i <- 0 until throttle) {
|
||||||
captcha.generateChallenge(getRandomParam())
|
captchaManager.generateChallenge(getRandomParam())
|
||||||
}
|
}
|
||||||
} catch { case exception: Exception => println(exception) }
|
} catch { case exception: Exception => println(exception) }
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import java.io.ByteArrayInputStream
|
|||||||
import java.sql.{Blob, ResultSet}
|
import java.sql.{Blob, ResultSet}
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
class Captcha(config: Config, captchaProviders: CaptchaProviders) {
|
class CaptchaManager(config: Config, captchaProviders: CaptchaProviders) {
|
||||||
|
|
||||||
def getCaptcha(id: Id): Either[Error, Image] = {
|
def getCaptcha(id: Id): Either[Error, Image] = {
|
||||||
val blob = getImage(id.id)
|
val blob = getImage(id.id)
|
@ -2,7 +2,7 @@ package lc.server
|
|||||||
|
|
||||||
import org.json4s.jackson.JsonMethods.parse
|
import org.json4s.jackson.JsonMethods.parse
|
||||||
import org.json4s.jvalue2extractable
|
import org.json4s.jvalue2extractable
|
||||||
import lc.core.Captcha
|
import lc.core.CaptchaManager
|
||||||
import lc.core.ErrorMessageEnum
|
import lc.core.ErrorMessageEnum
|
||||||
import lc.core.{Answer, ByteConvert, Error, Id, Parameters}
|
import lc.core.{Answer, ByteConvert, Error, Id, Parameters}
|
||||||
import lc.core.Config.formats
|
import lc.core.Config.formats
|
||||||
@ -13,7 +13,7 @@ import java.net.InetSocketAddress
|
|||||||
import java.util
|
import java.util
|
||||||
import scala.jdk.CollectionConverters._
|
import scala.jdk.CollectionConverters._
|
||||||
|
|
||||||
class Server(address: String, port: Int, captcha: Captcha, playgroundEnabled: Boolean, corsHeader: String) {
|
class Server(address: String, port: Int, captchaManager: CaptchaManager, playgroundEnabled: Boolean, corsHeader: String) {
|
||||||
var headerMap: util.Map[String, util.List[String]] = _
|
var headerMap: util.Map[String, util.List[String]] = _
|
||||||
if (corsHeader.nonEmpty) {
|
if (corsHeader.nonEmpty) {
|
||||||
headerMap = Map("Access-Control-Allow-Origin" -> List(corsHeader).asJava).asJava
|
headerMap = Map("Access-Control-Allow-Origin" -> List(corsHeader).asJava).asJava
|
||||||
@ -27,7 +27,7 @@ class Server(address: String, port: Int, captcha: Captcha, playgroundEnabled: Bo
|
|||||||
(request) => {
|
(request) => {
|
||||||
val json = parse(request.getBodyString())
|
val json = parse(request.getBodyString())
|
||||||
val param = json.extract[Parameters]
|
val param = json.extract[Parameters]
|
||||||
val id = captcha.getChallenge(param)
|
val id = captchaManager.getChallenge(param)
|
||||||
getResponse(id, headerMap)
|
getResponse(id, headerMap)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -38,7 +38,7 @@ class Server(address: String, port: Int, captcha: Captcha, playgroundEnabled: Bo
|
|||||||
val result = if (params.containsKey("id")) {
|
val result = if (params.containsKey("id")) {
|
||||||
val paramId = params.get("id").get(0)
|
val paramId = params.get("id").get(0)
|
||||||
val id = Id(paramId)
|
val id = Id(paramId)
|
||||||
captcha.getCaptcha(id)
|
captchaManager.getCaptcha(id)
|
||||||
} else {
|
} else {
|
||||||
Left(Error(ErrorMessageEnum.INVALID_PARAM.toString + "=> id"))
|
Left(Error(ErrorMessageEnum.INVALID_PARAM.toString + "=> id"))
|
||||||
}
|
}
|
||||||
@ -50,7 +50,7 @@ class Server(address: String, port: Int, captcha: Captcha, playgroundEnabled: Bo
|
|||||||
(request) => {
|
(request) => {
|
||||||
val json = parse(request.getBodyString())
|
val json = parse(request.getBodyString())
|
||||||
val answer = json.extract[Answer]
|
val answer = json.extract[Answer]
|
||||||
val result = captcha.checkAnswer(answer)
|
val result = captchaManager.checkAnswer(answer)
|
||||||
getResponse(result, headerMap)
|
getResponse(result, headerMap)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user