public void handle(Context ctx) throws Exception { UserModel targetUser = (UserModel) getAndCheckFromUrl(UserModel.class); UserEmailForm form = new UserEmailForm( path + "/actions/SaveEmailAddresses/" + targetUser.getId(), requestParams); Message m = form.validate(); String primaryEmail = form.getParameter("Email"); UserModel userForEmail = UserModel.getUserForEmail(primaryEmail); if ((m == null) && (userForEmail != null) && (!userForEmail.equals(targetUser))) { if (userForEmail.getUsername().equals("")) { targetUser.mergeRolesWithMailAccount(userForEmail); } else { m = new ErrorMessage( "Primary email address is already linked to user " + userForEmail.getUsername()); form.setError("Email", "Please use a different email"); } } // No messages: changes are valid if (m != null) { // Display error and prompt user to fix throw getValidationException(form, m, path + "/chapter/MemberInfo/" + targetUser.getId()); } String emailText = form.getParameter("Emails"); String[] splitEmails = emailText.split("\n"); HashSet<String> emails = new HashSet<String>(); Vector<String> errors = new Vector<String>(); for (int i = 0; i < splitEmails.length; i++) { String email = splitEmails[i].trim(); if (!email.equals("")) { userForEmail = UserModel.getUserForEmail(email); if ((userForEmail != null) && (!userForEmail.equals(targetUser))) { if (userForEmail.getUsername().equals("")) { targetUser.mergeRolesWithMailAccount(userForEmail); emails.add(email); } else { errors.add(email + " is already linked to user " + userForEmail.getUsername()); } } else { emails.add(email); } } } emails.add(primaryEmail); targetUser.saveEmails(primaryEmail, emails); setSessionMessage((errors.isEmpty() ? "Basic info updated!" : getExceptionString(errors))); throw new RedirectionException(path + "/chapter/MemberInfo/" + targetUser.getId()); }
public void handle(Context ctx) throws Exception { ApplicationContactInfoForm form = new ApplicationContactInfoForm( path + "/actions/SaveApplicationContactInfo/" + urlParams.getParam(), requestParams); Message m = form.validate(); String email = form.getParameter("Email"); UserModel userForEmail = UserModel.getUserForEmail(email); if ((m == null) && (userForEmail != null) && (!userForEmail.equals(currentUser))) { if (userForEmail.getUsername().equals("")) { currentUser.mergeRolesWithMailAccount(userForEmail); } else { m = new ErrorMessage( "That email address is already linked to another account.<br/>" + "The system administrator has been notified and will contact you shortly to resolve the situation."); form.setError("Email", "Please use a different email"); log.warn( currentUser.getUsername() + " (" + currentUser.getEmail() + ") failed email change: " + email + " is already in use by " + userForEmail.getUsername()); } } // No messages: changes are valid if (m != null) { throw getValidationException( form, m, path + "/volunteering/ApplicationContactInfo/" + urlParams.getParam()); } String firstname = form.getParameter("Firstname"); String lastname = form.getParameter("Lastname"); String phone = form.getParameter("Phone"); int englishWriting = Integer.parseInt(form.getParameter("En1")); int englishReading = Integer.parseInt(form.getParameter("En2")); int englishSpeaking = Integer.parseInt(form.getParameter("En3")); int frenchWriting = Integer.parseInt(form.getParameter("Fr1")); int frenchReading = Integer.parseInt(form.getParameter("Fr2")); int frenchSpeaking = Integer.parseInt(form.getParameter("Fr3")); String schooling = form.getParameter("Schooling"); String resume = form.getParameter("Resume"); String references = form.getParameter("References"); float gpa = Float.parseFloat(form.getParameter("GPA")); currentUser.saveApplicationData(firstname, lastname, email, phone); ApplicationSessionModel session = (ApplicationSessionModel) getAndCheckFromUrl(ApplicationSessionModel.class); ApplicationModel app = currentUser.getAppForSession(session); if (app == null) { app = currentUser.applyToSession(session); } app.save( englishWriting, englishReading, englishSpeaking, frenchWriting, frenchReading, frenchSpeaking, schooling, resume, references, gpa); setSessionMessage(("Contact Information Saved")); int sessionID = session.getId(); ApplicationQuestionModel nextQ = session.getNextQuestion(null); if (nextQ == null) { throw new RedirectionException(path + "/volunteering/ApplicationFinished/" + sessionID); } else { int questionID = nextQ.getId(); throw new RedirectionException( path + "/volunteering/AnswerApplicationQuestion/" + sessionID + "/" + questionID); } }