public String getActivationMessage() {
/*check if the email can be retrieved from openID attributes
* if it it belongs to a registered user, send the activation email in a separate thread
*/
OpenIDAuthenticationToken token = (OpenIDAuthenticationToken)SecurityContextHolder.getContext().getAuthentication();
// get the email attribute
String email = null;
if (token == null) {
log.error("OpenIDAuthenticationToken is null");
return "Email address was not found in response " + MartinlawConstants.OPENID_ERROR_MSG_INDICATOR;
} else {
List<OpenIDAttribute> attributes = token.getAttributes();
for (OpenIDAttribute attr: attributes) {
if (StringUtils.contains(attr.getName(), "email")) {
email = attr.getValues().get(0);
break;
}
}
}
if (email == null) {
log.error("Email attribute was not found in attributes");
return "Email address was not found in response " + MartinlawConstants.OPENID_ERROR_MSG_INDICATOR;
} else {
EntityContract entity = getEntityInfoService().getEntityByEmail(email);
if (entity == null) {
return "Email address '" + email + "' is not associated with an existing user"
+ MartinlawConstants.OPENID_ERROR_MSG_INDICATOR;
} else if (!hasEmploymentAffiliation(entity)) {
return "You are not affiliated as a staff :(";
} else if (!entity.isActive()) {
return "Your account is not active :(";
} else {
if (emailSetupOk()) {
String fromAddr = getParameterService().getParameterValueAsString(
KewApiConstants.KEW_NAMESPACE, "Mailer", KewApiConstants.EMAIL_REMINDER_FROM_ADDRESS);
createAndEmailActivation(email, token.getIdentityUrl(), entity, fromAddr);
return entity.getDefaultName().getFirstName() +
", an activation email has been sent to '" + email + "' from address '" + fromAddr
+ "'. If none comes to your inbox or spam folder after a few minutes, please contact support";
} else {
return "An activation email could not be sent to '" + email +