public StatusResponse remindUser( RegisterRequest data, HashMap<String, Connection<?>> connections, HttpServletRequest request, HttpServletResponse response) { StatusResponse result = new StatusResponse(); String string = new String(); try { UserProfile userProfile = loadUserByUsernameOrEmail(data.getEmail()); System.out.println("ProxyHost=" + this.proxyHost); System.out.println("ProxyPort=" + this.proxyPort); System.out.println("recaptchaSecretKey=" + this.recaptchaSecretKey); // Newer versions of Java need a "http." prefix on the system properties System.setProperty("proxyHost", this.proxyHost); System.setProperty("proxyPort", this.proxyPort); System.setProperty("http.proxyHost", this.proxyHost); System.setProperty("http.proxyPort", this.proxyPort); URL url = new URL( "https://www.google.com/recaptcha/api/siteverify?secret=" + this.recaptchaSecretKey + "&response=" + data.getRecaptcha()); System.out.println(url.toString()); Scanner scanner = new Scanner(url.openStream()); while (scanner.hasNext()) { string += scanner.nextLine(); } scanner.close(); result.setLogged(false); result.setProfile(null); result.getResponses().put("reminder", "reminder_sent"); if (string.indexOf("true") == -1) { result.setLogged(false); result.setProfile(null); result.getResponses().put("reminder", "bad_recaptcha"); return result; } // Simple random password with 16 hex digits String newPassword = Long.toHexString(Double.doubleToLongBits(Math.random())); context.getUserProfileDao().setPassword(userProfile, newPassword); List<UserProfile> recipients = new ArrayList<UserProfile>(); recipients.add(userProfile); Mailer mailer = new Mailer(); mailer.sendMail( "Account information", "Hello nQuire-it user,\n\n" + "You (or someone claiming to be you) has requested a new password for your account.\n\n" + "Your username is " + userProfile.getUsername() + "\n" + "Your new password is " + newPassword + "\n\n" + "You should login and change this to something more memorable as soon as possible.\n\n" + "Warm regards,\nnQuire-it team", recipients, false); return result; } catch (UsernameNotFoundException e) { result.setLogged(false); result.setProfile(null); result.getResponses().put("reminder", "email_not_exists"); return result; } catch (java.io.IOException e3) { System.out.println("!!!!!" + e3.toString() + "!!!!!"); result.setLogged(false); result.setProfile(null); result.getResponses().put("reminder", "bad_recaptcha"); return result; } }
public StatusResponse registerUser( RegisterRequest data, HashMap<String, Connection<?>> connections, HttpServletRequest request, HttpServletResponse response) { try { loadUserByUsername(data.getUsername()); StatusResponse result = new StatusResponse(); result.setLogged(false); result.setProfile(null); result.getResponses().put("registration", "username_exists"); return result; } catch (UsernameNotFoundException e) { try { context.getUserProfileDao().loadUserByUsername(data.getEmail()); StatusResponse result = new StatusResponse(); result.setLogged(false); result.setProfile(null); result.getResponses().put("registration", "email_exists"); return result; } catch (UsernameNotFoundException e2) { String string = new String(); try { System.out.println("ProxyHost=" + this.proxyHost); System.out.println("ProxyPort=" + this.proxyPort); System.out.println("recaptchaSecretKey=" + this.recaptchaSecretKey); // Newer versions of Java need a "http." prefix on the system properties System.setProperty("proxyHost", this.proxyHost); System.setProperty("proxyPort", this.proxyPort); System.setProperty("http.proxyHost", this.proxyHost); System.setProperty("http.proxyPort", this.proxyPort); URL url = new URL( "https://www.google.com/recaptcha/api/siteverify?secret=" + this.recaptchaSecretKey + "&response=" + data.getRecaptcha()); System.out.println(url.toString()); Scanner scanner = new Scanner(url.openStream()); while (scanner.hasNext()) { string += scanner.nextLine(); } scanner.close(); } catch (java.io.IOException e3) { System.out.println("!!!!!" + e3.toString() + "!!!!!"); } if (string.indexOf("true") == -1) { StatusResponse result = new StatusResponse(); result.setLogged(false); result.setProfile(null); result.getResponses().put("registration", "bad_recaptcha"); return result; } UserProfile user = context .getUserProfileDao() .createUser(data.getUsername(), data.getPassword(), data.getEmail(), false); login(user, request, response); return status(connections, request.getSession()); } } }