mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-13 06:53:19 -05:00
Add additional filtering on captchas
Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
parent
e931e43bb9
commit
2b617ef75d
@ -24,7 +24,7 @@ object CaptchaProviders {
|
||||
|
||||
private val seed = Config.seed
|
||||
private val random = new scala.util.Random(seed)
|
||||
private val config = Config.captchaConfigMap
|
||||
private val config = Config.captchaConfig
|
||||
|
||||
private def getNextRandomInt(max: Int): Int =
|
||||
random.synchronized {
|
||||
@ -35,21 +35,31 @@ object CaptchaProviders {
|
||||
return providers(id)
|
||||
}
|
||||
|
||||
private def filterProviderByParam(param: Parameters): Iterable[(List[String], List[String])] = {
|
||||
for {
|
||||
configValue <- config.values
|
||||
if configValue("supportedLevels").contains(param.level)
|
||||
if configValue("supportedMedia").contains(param.media)
|
||||
if configValue("supportedinputType").contains(param.input_type)
|
||||
} yield (configValue("name"), configValue("config"))
|
||||
private def filterProviderByParam(param: Parameters): Iterable[(String, String)] = {
|
||||
val configFilter = for {
|
||||
configValue <- config
|
||||
if configValue.allowedLevels.contains(param.level)
|
||||
if configValue.allowedMedia.contains(param.media)
|
||||
if configValue.allowedInputType.contains(param.input_type)
|
||||
} yield (configValue.name, configValue.config)
|
||||
|
||||
val providerFilter = for {
|
||||
providerValue <- configFilter
|
||||
providerConfigMap = providers(providerValue._1).supportedParameters()
|
||||
if providerConfigMap.get(ParametersEnum.SUPPORTEDLEVEL.toString).contains(param.level)
|
||||
if providerConfigMap.get(ParametersEnum.SUPPORTEDMEDIA.toString).contains(param.media)
|
||||
if providerConfigMap.get(ParametersEnum.SUPPORTEDINPUTTYPE.toString).contains(param.input_type)
|
||||
} yield (providerValue._1, providerValue._2)
|
||||
|
||||
providerFilter
|
||||
}
|
||||
|
||||
def getProvider(param: Parameters): ChallengeProvider = {
|
||||
val providerConfig = filterProviderByParam(param).toList
|
||||
val randomIndex = getNextRandomInt(providerConfig.length)
|
||||
val providerIndex = providerConfig(randomIndex)._1
|
||||
val selectedProvider = providers(providerIndex(0))
|
||||
selectedProvider.configure(providerConfig(randomIndex)._2(0))
|
||||
val selectedProvider = providers(providerIndex)
|
||||
selectedProvider.configure(providerConfig(randomIndex)._2)
|
||||
selectedProvider
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user