Add additional filtering on captchas

Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
Rahul Rudragoudar 2021-03-11 21:25:33 +05:30
parent e931e43bb9
commit 2b617ef75d
No known key found for this signature in database
GPG Key ID: 0D2CE231A7287EBC

View File

@ -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
}
}