|
|
@ -1,8 +1,5 @@ |
|
|
|
package org.airsonic.player.controller; |
|
|
|
package org.airsonic.player.controller; |
|
|
|
|
|
|
|
|
|
|
|
import net.tanesha.recaptcha.ReCaptcha; |
|
|
|
|
|
|
|
import net.tanesha.recaptcha.ReCaptchaFactory; |
|
|
|
|
|
|
|
import net.tanesha.recaptcha.ReCaptchaResponse; |
|
|
|
|
|
|
|
import org.airsonic.player.domain.User; |
|
|
|
import org.airsonic.player.domain.User; |
|
|
|
import org.airsonic.player.service.SecurityService; |
|
|
|
import org.airsonic.player.service.SecurityService; |
|
|
|
import org.airsonic.player.service.SettingsService; |
|
|
|
import org.airsonic.player.service.SettingsService; |
|
|
@ -49,21 +46,13 @@ public class RecoverController { |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
|
String usernameOrEmail = StringUtils.trimToNull(request.getParameter("usernameOrEmail")); |
|
|
|
String usernameOrEmail = StringUtils.trimToNull(request.getParameter("usernameOrEmail")); |
|
|
|
ReCaptcha captcha = ReCaptchaFactory.newSecureReCaptcha("6LcZ3OMSAAAAANkKMdFdaNopWu9iS03V-nLOuoiH", |
|
|
|
|
|
|
|
"6LcZ3OMSAAAAAPaFg89mEzs-Ft0fIu7wxfKtkwmQ", false); |
|
|
|
|
|
|
|
boolean showCaptcha = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (usernameOrEmail != null) { |
|
|
|
if (usernameOrEmail != null) { |
|
|
|
|
|
|
|
|
|
|
|
map.put("usernameOrEmail", usernameOrEmail); |
|
|
|
map.put("usernameOrEmail", usernameOrEmail); |
|
|
|
User user = getUserByUsernameOrEmail(usernameOrEmail); |
|
|
|
User user = getUserByUsernameOrEmail(usernameOrEmail); |
|
|
|
String challenge = request.getParameter("recaptcha_challenge_field"); |
|
|
|
|
|
|
|
String uresponse = request.getParameter("recaptcha_response_field"); |
|
|
|
|
|
|
|
ReCaptchaResponse captchaResponse = captcha.checkAnswer(request.getRemoteAddr(), challenge, uresponse); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!captchaResponse.isValid()) { |
|
|
|
if (user == null) { |
|
|
|
map.put("error", "recover.error.invalidcaptcha"); |
|
|
|
|
|
|
|
} else if (user == null) { |
|
|
|
|
|
|
|
map.put("error", "recover.error.usernotfound"); |
|
|
|
map.put("error", "recover.error.usernotfound"); |
|
|
|
} else if (user.getEmail() == null) { |
|
|
|
} else if (user.getEmail() == null) { |
|
|
|
map.put("error", "recover.error.noemail"); |
|
|
|
map.put("error", "recover.error.noemail"); |
|
|
@ -74,17 +63,12 @@ public class RecoverController { |
|
|
|
user.setLdapAuthenticated(false); |
|
|
|
user.setLdapAuthenticated(false); |
|
|
|
user.setPassword(password); |
|
|
|
user.setPassword(password); |
|
|
|
securityService.updateUser(user); |
|
|
|
securityService.updateUser(user); |
|
|
|
showCaptcha = false; |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
map.put("error", "recover.error.sendfailed"); |
|
|
|
map.put("error", "recover.error.sendfailed"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (showCaptcha) { |
|
|
|
|
|
|
|
map.put("captcha", captcha.createRecaptchaHtml(null, null)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ModelAndView("recover", "model", map); |
|
|
|
return new ModelAndView("recover", "model", map); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|