Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Creative commons Attribution-NonCommercial license. http://creativecommons.org/licenses/by-nc/2.5/au/deed.en_GB NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
  
  package base.jee.api.sql.util;
  
 
 import java.util.Date;
 import java.util.UUID;
 
 import static base.jee.api.sql.util.AddPerson.addPerson;
 import static base.jee.api.sql.util.Log.log;
 
 public class CreatePerson {
 
 	public static UUID createPerson(Connection cTemplateManager templateManagerSettings settingsUser userString firstNameString lastNameString emailString usernameString passwordDate expirythrows IOExceptionSQLExceptionNoSuchAlgorithmException {
 		PreparedStatement s = null;
 		PreparedStatement t = null;
 		ResultSet r = null;
 		UUID uuid = null;
 
 		if(username != null) {
 			username = username.trim();
 			if(username.length() == 0) {
 				username = null;
 			}
 		}
 
 		if(email == null || email.length() < 4) {
 			throw new IllegalArgumentException("Invalid email parameter");
 		}
 
 		try {
 			uuid = addPerson(cfirstNamelastNameemailusernamepasswordexpiry);
 
 			log(c"INFO"user"Created new account " + firstName + " " + lastName + ", " + emailnew ResourceUid("Person"uuid.toString()));
 
 			if(username == null || username.length() == 0 || settings.get("ldap.enabled""true").equals("false")) {
 				String supportTeam = null;
 				String supportEmail = null;
 				s = c.prepareStatement("select (select value from setting where name='support_team.name'), (select value from setting where name='support_team.email')");
 				r = s.executeQuery();
 				if(r.next()) {
 					supportTeam = r.getString(1);
 					supportEmail = r.getString(2);
 				}
 				r.close();
 				r = null;
 				s.close();
 				s = null;
 
 				String token = UUID.randomUUID().toString();
 				log(c"FINEST"user"Storing account activation token " + token + " for person " + email);
 				s = c.prepareStatement("insert into request_token (token, person_uuid, type, ip, expiry) values(?,?,'account_activation',?,?)");
 				s.setString(1, token);
 				s.setString(2, uuid.toString());
 				s.setString(3, user.getIp());
 				s.setLong(4, (new Date()).getTime()/1000);
 				s.close();
 				s = null;
 
 				ST html = templateManager.getCurrentTemplate().getInstanceOf("account_activation_email_html");
 				html.add("first_name"firstName);
 				html.add("last_name"lastName);
 				html.add("email"email);
 				html.add("user"user);
 				html.add("token"token);
 				html.add("formurl"settings.get("base.url"));
 
 				ST text = templateManager.getCurrentTemplate().getInstanceOf("account_activation_email_text");
 				text.add("first_name"firstName);
 				text.add("last_name"lastName);
 				text.add("email"email);
 				text.add("user"user);
 				text.add("token"token);
 				text.add("formurl"settings.get("base.url"));
 
 				Email e = new Email();
 				e.setTo(firstName + " " + lastName + " <" + email + ">");
 				e.setFrom(supportTeam + " <" + supportEmail + ">");
 				e.setText(text.render());
 				e.setHtml(html.render());
 				e.setSubject("Account activation");
				s = c.prepareStatement("insert into email (uuid, to_address,email,retries,attempt_at,in_progress) values(?,?,?,0,?,0)");
				s.setString(1, new base.uuid.UUID().toString());
				s.setString(2, e.getTo());
				s.setString(3, e.toJson());
				s.setLong(4, new Date().getTime());
				s.close();
				s = null;
			}
finally {
			if(r != null) {
				try { r.close(); } catch(Exception e) {}
			}
			if(s != null) {
				try { s.close(); } catch(Exception e) {}
			}
			if(t != null) {
				try { t.close(); } catch(Exception e) {}
			}
		}
		return uuid;
	}
New to GrepCode? Check out our FAQ X