Skip to content

Commit

Permalink
started to add gender
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed Jan 24, 2012
1 parent 959db25 commit a52d609
Showing 1 changed file with 17 additions and 8 deletions.
Expand Up @@ -241,8 +241,9 @@ private void sendConfirmationLinkEmail(Document doc, String uuid, String firstam

/**
* Register user
* @param gender Gender of user
*/
private void registerUser(Document doc, String firstname, String lastname, String email, String password) {
private void registerUser(Document doc, String gender, String firstname, String lastname, String email, String password) {
Element rootElement = doc.getDocumentElement();

try {
Expand All @@ -252,6 +253,7 @@ private void registerUser(Document doc, String firstname, String lastname, Strin

// INFO: Yanel registration
org.wyona.security.core.api.User user = getRealm().getIdentityManager().getUserManager().createUser("" + customerID, firstname + " " + lastname, email, password);
// TODO: user.setProperty("gender", gender);
user.setLanguage(getContentLanguage());
org.wyona.security.core.api.User alias = getRealm().getIdentityManager().getUserManager().createAlias(email, "" + customerID);
// TODO: Move adding to groups into separated method
Expand Down Expand Up @@ -309,8 +311,8 @@ private void registerUser(Document doc, String firstname, String lastname, Strin
* Save registration request persistently
* @param email E-Mail address of user
*/
private void saveRegistrationRequest(String uuid, String firstname, String lastname, String email, String city, String phone, String password) {
Document doc = getRegistrationRequestAsXML(uuid, firstname, lastname, email, city, phone, password);
private 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);
Node node = null;
try {
String path = getActivationNodePath(uuid);
Expand All @@ -330,7 +332,7 @@ private void saveRegistrationRequest(String uuid, String firstname, String lastn
* Generate registration request as XML
* @param email E-Mail address of user
*/
private Document getRegistrationRequestAsXML(String uuid, String firstname, String lastname, String email, String city, String phone, String password) {
private Document getRegistrationRequestAsXML(String uuid, String gender, String firstname, String lastname, String email, String city, String phone, String password) {
Document doc = XMLHelper.createDocument(NAMESPACE, "registration-request");
Element rootElem = doc.getDocumentElement();
rootElem.setAttribute("uuid", uuid);
Expand All @@ -343,6 +345,10 @@ private Document getRegistrationRequestAsXML(String uuid, String firstname, Stri
passwordElem.setTextContent(password);
rootElem.appendChild(passwordElem);

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

Element lastnameElem = doc.createElementNS(NAMESPACE, "lastname");
lastnameElem.setTextContent(lastname);
rootElem.appendChild(lastnameElem);
Expand Down Expand Up @@ -546,10 +552,10 @@ private void processRegistrationRequest(Document doc, String email) throws Excep
}
if (!emailConfigurationRequired) {
log.warn("User will be registered without email configuration!");
registerUser(doc, firstname, lastname, email, password);
registerUser(doc, gender, firstname, lastname, email, password);
} else {
String uuid = java.util.UUID.randomUUID().toString();
saveRegistrationRequest(uuid, firstname, lastname, email, city, phone, password);
saveRegistrationRequest(uuid, gender, firstname, lastname, email, city, phone, password);
sendConfirmationLinkEmail(doc, uuid, firstname, lastname, email);
}
} else {
Expand All @@ -568,7 +574,7 @@ private boolean activateRegistration(String uuid, Document doc) {

UserRegistrationBean urBean = readRegistrationRequest(getRealm().getRepository().getNode(path));

registerUser(doc, urBean.getFirstname(), urBean.getLastname(), urBean.getEmail(), urBean.getPassword());
registerUser(doc, urBean.getGender(), urBean.getFirstname(), urBean.getLastname(), urBean.getEmail(), urBean.getPassword());
getRealm().getRepository().getNode(path).delete();

MailUtil.send(FROM_ADDRESS, urBean.getEmail(), "User Registration Successful", getActivationURL().replace("registration", "index"));
Expand Down Expand Up @@ -610,11 +616,14 @@ private UserRegistrationBean readRegistrationRequest(Node node) throws Exception
xpath.setNamespaceContext(new UserRegistrationNamespaceContext());

// TODO: Get creation date to determine expire date!
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(firstname, lastname, email, password);

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

return urBean;
}
}
Expand Down

0 comments on commit a52d609

Please sign in to comment.