Check reCAPTCHA v2 responses when enabled

Signed-off-by: Peter Marheine <peter@taricorp.net>
This commit is contained in:
Peter Marheine
2018-08-11 21:05:07 +10:00
parent 1b833003fb
commit 8b4037b549
2 changed files with 19 additions and 1 deletions
@@ -1,5 +1,6 @@
package org.airsonic.player.controller;
import de.triology.recaptchav2java.ReCaptcha;
import org.airsonic.player.domain.User;
import org.airsonic.player.service.SecurityService;
import org.airsonic.player.service.SettingsService;
@@ -52,7 +53,18 @@ public class RecoverController {
map.put("usernameOrEmail", usernameOrEmail);
User user = getUserByUsernameOrEmail(usernameOrEmail);
if (user == null) {
boolean captchaOk;
if (settingsService.isCaptchaEnabled()) {
String recaptchaResponse = request.getParameter("g-recaptcha-response");
ReCaptcha captcha = new ReCaptcha(settingsService.getRecaptchaSecretKey());
captchaOk = recaptchaResponse != null && captcha.isValid(recaptchaResponse);
} else {
captchaOk = true;
}
if (!captchaOk) {
map.put("error", "recover.error.invalidcaptcha");
} else if (user == null) {
map.put("error", "recover.error.usernotfound");
} else if (user.getEmail() == null) {
map.put("error", "recover.error.noemail");