public UserProfile providerSignIn(String username, String providerId, String providerUserId) { UserProfile existingUser = context.getUserProfileDao().loadUserByProviderUserId(providerId, providerUserId); if (existingUser != null) { return existingUser; } else { String email = null; if (username.matches("^\\S+@\\S+\\.\\S+$")) { email = username; username = username.substring(0, username.indexOf('@')); } String initialUsername = username; for (int i = 1; !usernameIsAvailable(initialUsername); i++) { initialUsername = String.format("%s_%d", username, i); } UserProfile user = context.getUserProfileDao().createUser(initialUsername, null, email, email != null); newUser(user.getUsername()); return user; } }
public boolean mergeAccount(UserProfile user, UserProfile mergedUser, String provider) { if (context.getUserProfileDao().deleteConnection(mergedUser, provider)) { context.getLogManager().usersMerged(user, mergedUser); context.getVotableDao().transferContent(mergedUser, user); context.getVoteDao().transferVotes(mergedUser, user); context.getRoleDao().transferRoles(mergedUser, user); context.getUserProfileDao().deleteUser(mergedUser); return true; } else { return false; } }
public boolean deleteConnection(StatusResponse currentStatus, String providerId) { if (((currentStatus.getProfile().getPassword() != null && currentStatus.getProfile().getPassword().length() > 0) || currentStatus.getConnections().size() > 1) && context.getUserProfileDao().deleteConnection(currentStatus.getProfile(), providerId)) { currentStatus.getConnections().remove(providerId); return true; } return false; }
public boolean updateProfile(StatusResponse currentStatus, ProfileRequest data) { if (data.getUsername() != null) { if (!data.getUsername().equals(currentStatus.getProfile().getUsername())) { if (data.getUsername().length() == 0) { currentStatus.getResponses().put("username", "username_empty"); } else if (!usernameIsAvailable(data.getUsername())) { currentStatus.getResponses().put("username", "username_not_available"); } else { context .getUserProfileDao() .updateUsername(currentStatus.getProfile(), data.getUsername()); } } } if (!data.getEmail().isEmpty() && !data.getEmail().equals(currentStatus.getProfile().getEmail())) { context.getUserProfileDao().updateEmail(currentStatus.getProfile(), data.getEmail()); } if (!data.getNotify1().equals(currentStatus.getProfile().getNotify1())) { context.getUserProfileDao().updateNotify1(currentStatus.getProfile(), data.getNotify1()); } if (!data.getNotify2().equals(currentStatus.getProfile().getNotify2())) { context.getUserProfileDao().updateNotify2(currentStatus.getProfile(), data.getNotify2()); } if (!data.getNotify3().equals(currentStatus.getProfile().getNotify3())) { context.getUserProfileDao().updateNotify3(currentStatus.getProfile(), data.getNotify3()); } if (!data.getNotify4().equals(currentStatus.getProfile().getNotify4())) { context.getUserProfileDao().updateNotify4(currentStatus.getProfile(), data.getNotify4()); } if (!data.getNotify5().equals(currentStatus.getProfile().getNotify5())) { context.getUserProfileDao().updateNotify5(currentStatus.getProfile(), data.getNotify5()); } context .getUserProfileDao() .updateUserInformation( currentStatus.getProfile(), data.getMetadata(), data.getVisibility()); return true; }
public PublicProfileResponse getPublicProfile(Long userId) { PublicProfileResponse response = new PublicProfileResponse(); UserProfile profile = context.getUserProfileDao().loadUserById(userId); if (profile != null) { response.setId(profile.getId()); response.setUsername(profile.getUsername()); response.setImage(profile.getImage()); if (profile.getVisibility().get("metadata") && profile.getMetadata() != null) { response.getMetadata().putAll(profile.getMetadata()); } boolean joined = profile.getVisibility().get("projectsJoined"); boolean created = profile.getVisibility().get("projectsCreated"); response.setProjects(context.getProjectDao().getMyProjects(profile, joined, created)); } return response; }
public UserProfile loadUserByUsernameOrEmail(String s) throws UsernameNotFoundException { return context.getUserProfileDao().loadUserByUsernameOrEmail(s, s); }
@Override public UserProfile loadUserByUsername(String s) throws UsernameNotFoundException { return context.getUserProfileDao().loadUserByUsername(s); }
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()); } } }
public boolean updateProfileImage(StatusResponse currentStatus, FileMapUpload files) { return context.getUserProfileDao().updateProfileImage(currentStatus.getProfile(), files); }
public void setPassword(UserProfile user, String password) { context.getUserProfileDao().setPassword(user, password); }
public boolean matchPassword(UserProfile user, String password) { return context.getUserProfileDao().matchPassword(user, password); }
public Boolean login( String username, String password, HttpServletRequest request, HttpServletResponse response) { UserProfile user = context.getUserProfileDao().loadUserByUsername(username); return user != null && initSession(user, password, true, request, response); }
public UserProfile currentUser() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); return auth != null && auth.getPrincipal() != null && auth.getPrincipal() instanceof UserProfile ? context.getUserProfileDao().user(((UserProfile) auth.getPrincipal())) : null; }