Skip to content

Commit

Permalink
use bean instead individual variables
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed Feb 22, 2012
1 parent 68b1ffd commit d2f6ece
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/resources/registration/src/build/build.properties
@@ -1,2 +1,2 @@
resource.name=user-registration
resource.version=0.0.2-dev-rXXX
resource.version=1.0.0
Expand Up @@ -4,25 +4,38 @@
package org.wyona.yanel.resources.registration;

/**
*
* User registration bean
*/
public class UserRegistrationBean {

private String uuid;
private String gender;
private String firstname;
private String lastname;
private String email;
private String password;
private String city;
private String phone;

/**
*
*/
public UserRegistrationBean(String gender, String firstname, String lastname, String email, String password) {
public UserRegistrationBean(String uuid, String gender, String firstname, String lastname, String email, String password, String city, String phone) {
this.uuid = uuid;
this.gender = gender;
this.firstname = firstname;
this.lastname = lastname;
this.email = email;
this.password = password;
this.city = city;
this.phone = phone;
}

/**
*
*/
public String getUUID() {
return uuid;
}

/**
Expand Down Expand Up @@ -59,4 +72,18 @@ public String getEmail() {
public String getPassword() {
return password;
}

/**
*
*/
public String getCity() {
return city;
}

/**
*
*/
public String getPhone() {
return phone;
}
}
Expand Up @@ -323,13 +323,13 @@ private void registerUser(Document doc, String gender, String firstname, String

/**
* Save registration request persistently
* @param email E-Mail address of user
* @param urb User registration bean containing E-Mail address of user, etc.
*/
protected void saveRegistrationRequest(String uuid, String gender, String firstname, String lastname, String email, String city, String phone, String password) {
Document doc = getRegistrationRequestAsXML(uuid, gender, firstname, lastname, email, city, phone, password);
protected void saveRegistrationRequest(UserRegistrationBean urb) {
Document doc = getRegistrationRequestAsXML(urb);
Node node = null;
try {
String path = getActivationNodePath(uuid);
String path = getActivationNodePath(urb.getUUID());
if (!getRealm().getRepository().existsNode(path)) {
node = YarepUtil.addNodes(getRealm().getRepository(), path, NodeType.RESOURCE);
} else {
Expand All @@ -344,35 +344,35 @@ protected void saveRegistrationRequest(String uuid, String gender, String firstn

/**
* Generate registration request as XML
* @param email E-Mail address of user
* @param urb User registration bean containing E-Mail address of user, etc.
*/
private Document getRegistrationRequestAsXML(String uuid, String gender, String firstname, String lastname, String email, String city, String phone, String password) {
private Document getRegistrationRequestAsXML(UserRegistrationBean urb) {
Document doc = XMLHelper.createDocument(NAMESPACE, "registration-request");
Element rootElem = doc.getDocumentElement();
rootElem.setAttribute("uuid", uuid);
rootElem.setAttribute("uuid", urb.getUUID());

DateFormat df = new SimpleDateFormat(DATE_FORMAT);
rootElem.setAttribute("request-time", df.format(new Date().getTime()));

// IMPORTANT TODO: Password needs to be encrypted!
Element passwordElem = doc.createElementNS(NAMESPACE, "password");
passwordElem.setTextContent(password);
passwordElem.setTextContent(urb.getPassword());
rootElem.appendChild(passwordElem);

Element genderElem = doc.createElementNS(NAMESPACE, "gender");
genderElem.setTextContent(gender);
genderElem.setTextContent(urb.getGender());
rootElem.appendChild(genderElem);

Element lastnameElem = doc.createElementNS(NAMESPACE, "lastname");
lastnameElem.setTextContent(lastname);
lastnameElem.setTextContent(urb.getLastname());
rootElem.appendChild(lastnameElem);

Element firstnameElem = doc.createElementNS(NAMESPACE, "firstname");
firstnameElem.setTextContent(firstname);
firstnameElem.setTextContent(urb.getFirstname());
rootElem.appendChild(firstnameElem);

Element emailElem = doc.createElementNS(NAMESPACE, "email");
emailElem.setTextContent(email);
emailElem.setTextContent(urb.getEmail());
rootElem.appendChild(emailElem);

return doc;
Expand Down Expand Up @@ -544,7 +544,8 @@ private void processRegistrationRequest(Document doc, String email) throws Excep
registerUser(doc, gender, firstname, lastname, email, password);
} else {
String uuid = java.util.UUID.randomUUID().toString();
saveRegistrationRequest(uuid, gender, firstname, lastname, email, city, phone, password);
UserRegistrationBean userRegBean = new UserRegistrationBean(uuid, gender, firstname, lastname, email, password, city, phone);
saveRegistrationRequest(userRegBean);
sendConfirmationLinkEmail(doc, uuid, firstname, lastname, email);
}
} else {
Expand Down Expand Up @@ -610,13 +611,14 @@ private UserRegistrationBean readRegistrationRequest(Node node) throws Exception
xpath.setNamespaceContext(new UserRegistrationNamespaceContext());

// TODO: Get creation date to determine expire date!
String uuid = (String) xpath.evaluate("/ur:registration-request/@uuid", doc, XPathConstants.STRING);
String gender = (String) xpath.evaluate("/ur:registration-request/ur:gender", doc, XPathConstants.STRING);
String firstname = (String) xpath.evaluate("/ur:registration-request/ur:firstname", doc, XPathConstants.STRING);
String lastname = (String) xpath.evaluate("/ur:registration-request/ur:lastname", doc, XPathConstants.STRING);
String email = (String) xpath.evaluate("/ur:registration-request/ur:email", doc, XPathConstants.STRING);
String password = (String) xpath.evaluate("/ur:registration-request/ur:password", doc, XPathConstants.STRING);

UserRegistrationBean urBean = new UserRegistrationBean(gender, firstname, lastname, email, password);
UserRegistrationBean urBean = new UserRegistrationBean(uuid, gender, firstname, lastname, email, password, "TODO", "TODO");

return urBean;
}
Expand Down

0 comments on commit d2f6ece

Please sign in to comment.