All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aoindustries.website.signup.SignupTechnicalActionHelper Maven / Gradle / Ivy

/*
 * Copyright 2007-2013, 2015, 2016 by AO Industries, Inc.,
 * 7262 Bull Pen Cir, Mobile, Alabama, 36695, U.S.A.
 * All rights reserved.
 */
package com.aoindustries.website.signup;

import com.aoindustries.aoserv.client.AOServConnector;
import com.aoindustries.aoserv.client.PasswordGenerator;
import com.aoindustries.encoding.ChainWriter;
import com.aoindustries.website.SiteSettings;
import static com.aoindustries.website.signup.ApplicationResources.accessor;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.validator.GenericValidator;

/**
 * Managed4Action and Dedicated4Action both use this to setup the request attributes.  This is implemented
 * here because inheritance is not possible and neither one is logically above the other.
 *
 * @author  AO Industries, Inc.
 */
final public class SignupTechnicalActionHelper {

	/**
	 * Make no instances.
	 */
	private SignupTechnicalActionHelper() {}

	public static void setRequestAttributes(
		ServletContext servletContext,
		HttpServletRequest request,
		SignupTechnicalForm signupTechnicalForm
	) throws IOException, SQLException {
		AOServConnector rootConn=SiteSettings.getInstance(servletContext).getRootAOServConnector();

		// Build the list of countries
		List countryOptions = SignupBusinessActionHelper.getCountryOptions(rootConn);

		// Generate random passwords, keeping the selected password at index 0
		List passwords = new ArrayList(16);
		if(!GenericValidator.isBlankOrNull(signupTechnicalForm.getBaPassword())) passwords.add(signupTechnicalForm.getBaPassword());
		while(passwords.size()<16) passwords.add(PasswordGenerator.generatePassword());

		// Store to the request
		request.setAttribute("countryOptions", countryOptions);
		request.setAttribute("passwords", passwords);
	}

	public static String getBaCountry(AOServConnector rootConn, SignupTechnicalForm signupTechnicalForm) throws IOException, SQLException {
		String baCountry = signupTechnicalForm.getBaCountry();
		return baCountry==null || baCountry.length()==0 ? "" : rootConn.getCountryCodes().get(baCountry).getName();
	}

	public static void setConfirmationRequestAttributes(
		ServletContext servletContext,
		HttpServletRequest request,
		SignupTechnicalForm signupTechnicalForm
	) throws IOException, SQLException {
		// Lookup things needed by the view
		AOServConnector rootConn = SiteSettings.getInstance(servletContext).getRootAOServConnector();

		// Store as request attribute for the view
		request.setAttribute("baCountry", getBaCountry(rootConn, signupTechnicalForm));
	}

	public static void printConfirmation(ChainWriter emailOut, AOServConnector rootConn, SignupTechnicalForm signupTechnicalForm) throws IOException, SQLException {
		emailOut.print("    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baName.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaName()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baTitle.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaTitle()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baWorkPhone.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaWorkPhone()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baCellPhone.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaCellPhone()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baHomePhone.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaHomePhone()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baFax.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaFax()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baEmail.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaEmail()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baAddress1.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaAddress1()).print("\n"
					 + "    \n");
		if(!GenericValidator.isBlankOrNull(signupTechnicalForm.getBaAddress2())) {
			emailOut.print("    \n"
						 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
						 + "        ").print(accessor.getMessage("signupTechnicalForm.baAddress2.prompt")).print("\n"
						 + "        ").encodeXhtml(signupTechnicalForm.getBaAddress2()).print("\n"
						 + "    \n");
		}
		emailOut.print("    \n"
					 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baCity.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaCity()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baState.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaState()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baCountry.prompt")).print("\n"
					 + "        ").encodeXhtml(getBaCountry(rootConn, signupTechnicalForm)).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baZip.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaZip()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.required")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baUsername.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaUsername()).print("\n"
					 + "    \n"
					 + "    \n"
					 + "        ").print(accessor.getMessage("signup.notRequired")).print("\n"
					 + "        ").print(accessor.getMessage("signupTechnicalForm.baPassword.prompt")).print("\n"
					 + "        ").encodeXhtml(signupTechnicalForm.getBaPassword()).print("\n"
					 + "    \n");
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy