Check if keys exist in map. Fixes: #736 (#737)

Check if keys exist in map. Fixes: #736
This commit is contained in:
Henrique Dias 2019-05-21 08:46:50 +01:00 committed by GitHub
commit 2527bdbfe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 13 deletions

View File

@ -89,25 +89,24 @@ func getAuthentication(flags *pflag.FlagSet, defaults ...interface{}) (settings.
secret := mustGetString(flags, "recaptcha.secret") secret := mustGetString(flags, "recaptcha.secret")
if key == "" { if key == "" {
kmap := defaultAuther["recaptcha"].(map[string]interface{}) if kmap, ok := defaultAuther["recaptcha"].(map[string]interface{}); ok {
key = kmap["key"].(string) key = kmap["key"].(string)
}
} }
if secret == "" { if secret == "" {
smap := defaultAuther["recaptcha"].(map[string]interface{}) if smap, ok := defaultAuther["recaptcha"].(map[string]interface{}); ok {
secret = smap["secret"].(string) secret = smap["secret"].(string)
}
} }
if key == "" || secret == "" { if key != "" && secret != "" {
checkErr(nerrors.New("you must set the flag 'recaptcha.key' and 'recaptcha.secret' for method 'json'")) jsonAuth.ReCaptcha = &auth.ReCaptcha{
Host: host,
Key: key,
Secret: secret,
}
} }
jsonAuth.ReCaptcha = &auth.ReCaptcha{
Host: host,
Key: key,
Secret: secret,
}
auther = jsonAuth auther = jsonAuth
} }