Skip to content

Commit

Permalink
check whether administrator needs to confirm registration request
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwechner committed May 9, 2015
1 parent af6b159 commit 17b0e95
Showing 1 changed file with 31 additions and 5 deletions.
Expand Up @@ -229,9 +229,17 @@ private void sendConfirmationLinkEmail(Document doc, UserRegistrationBean userRe
try {
Element element = (Element) rootElement.appendChild(doc.createElementNS(NAMESPACE, "confirmation-link-email"));
if (sendNotificationsEnabled()) {
if (administratorConfirmationRequired()) {
StringBuilder body = new StringBuilder();
body.append("A user with email address '" + userRegBean.getEmail() + "' has sent a registration request.");
body.append("\n\nPlease confirm the request by clicking on the following link:");
body.append("\n\n" + getActivationURL(userRegBean) + "TODO");
body.append("\n\nNote that this confirmation link is valid only for the next " + DEFAULT_TOTAL_VALID_HRS + " hours.");
MailUtil.send(getResourceConfigProperty(FROM_ADDRESS_PROP_NAME), getResourceConfigProperty("administrator-email"), "Confirm User Registration Request", body.toString());
}
StringBuilder body = new StringBuilder();
body.append("Thank you for your registration.");
body.append("\n\nTo activate your account, you need to click on the following link:");
body.append("\n\nTo activate your account, you need to click on the following link:");
body.append("\n\n" + getActivationURL(userRegBean));
body.append("\n\nNote that this confirmation link is valid only for the next " + DEFAULT_TOTAL_VALID_HRS + " hours.");
MailUtil.send(getResourceConfigProperty(FROM_ADDRESS_PROP_NAME), userRegBean.getEmail(), "Activate User Registration (sent by Yanel)", body.toString());
Expand Down Expand Up @@ -283,6 +291,7 @@ private void registerUser(Document doc, UserRegistrationBean userRegBean) throws
/**
* Activate user
* @param userRegBean User registration bean containing gender, firstname, etc.
* @return activated user
*/
protected User activateUser(UserRegistrationBean userRegBean) throws Exception {
long customerID = new java.util.Date().getTime();
Expand Down Expand Up @@ -483,9 +492,20 @@ private void processRegistrationRequest(Document doc, String email) throws Excep
}
}

/**
* Check whether administrator needs to confirm registration request
*/
private boolean administratorConfirmationRequired() throws Exception {
if (getResourceConfigProperty("administrator-confirmation-required") != null && getResourceConfigProperty("administrator-confirmation-required").equals("true")) {
return true;
}
return false;
}

/**
* Try to activate user registration
* @param uuid UUID of user registration activation request
* @param doc Document containing response to user trying to activate account
* @return true if user registration activation was successful, otherwise return false if actication failed
*/
protected boolean activateRegistration(String uuid, Document doc) {
Expand All @@ -495,8 +515,15 @@ protected boolean activateRegistration(String uuid, Document doc) {

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

registerUser(doc, urBean);
getRealm().getRepository().getNode(path).delete();
Element rootElement = doc.getDocumentElement();

if (administratorConfirmationRequired() && !urBean.hasAdministratorConfirmedRegistration()) {
log.warn("Administrator has not confirmed registration request yet!");
rootElement.appendChild(doc.createElement("administrator-not-confirmed-yet"));
return false;
} else {
registerUser(doc, urBean);
getRealm().getRepository().getNode(path).delete();

if (doNotifyAdministrator()) {
StringBuilder body = new StringBuilder();
Expand All @@ -514,8 +541,6 @@ protected boolean activateRegistration(String uuid, Document doc) {
MailUtil.send(getResourceConfigProperty(FROM_ADDRESS_PROP_NAME), urBean.getEmail(), "User Registration Successful", body.toString());
}

Element rootElement = doc.getDocumentElement();

// TODO: Add gender/salutation

Element emailE = (Element) rootElement.appendChild(doc.createElementNS(NAMESPACE, EMAIL));
Expand All @@ -528,6 +553,7 @@ protected boolean activateRegistration(String uuid, Document doc) {
lastnameE.appendChild(doc.createTextNode(urBean.getLastname()));

return true;
}
} else {
log.error("No such activation request node: " + path);
return false;
Expand Down

0 comments on commit 17b0e95

Please sign in to comment.