if (isEmailRequired && (email == null || email.length() == 0)) {
return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "User email is mandatory.", null));
}
UserInfo userInfo = null;
try {
userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, login, false, false);
} catch (CoreException e) {
LogHelper.log(e);
return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e));
}
if (userInfo != null) {
return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "User " + login + " already exists.", null));
}
if (email != null && email.length() > 0) {
if (!email.contains("@")) { //$NON-NLS-1$
return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Invalid user email.", null));
}
userInfo = null;
try {
userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.EMAIL, email.toLowerCase(), false, false);
} catch (CoreException e) {
LogHelper.log(e);
return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e));
}
if (userInfo != null) {
return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, NLS.bind("Email address already in use: {0}.", email), null));
}
}
userInfo = new UserInfo();
userInfo.setUserName(login);
userInfo.setFullName(name);
userInfo.setProperty(UserConstants2.PASSWORD, password);
if (identifier != null) {
userInfo.setProperty(UserConstants2.OAUTH, identifier);
}
if (email != null && email.length() > 0) {
userInfo.setProperty(UserConstants2.EMAIL, email);
}
if (isEmailRequired) {
userInfo.setProperty(UserConstants2.BLOCKED, "true");
userInfo.setProperty(UserConstants2.EMAIL_CONFIRMATION_ID, getUniqueEmailConfirmationId());
}
try {
OrionConfiguration.getMetaStore().createUser(userInfo);
} catch (CoreException e) {
LogHelper.log(e);
return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, NLS.bind("Error creating user: {0}", login), null));
}
Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.account"); //$NON-NLS-1$
if (logger.isInfoEnabled())
logger.info("Account created: " + login); //$NON-NLS-1$
try {
//give the user access to their own user profile
String location = '/' + UserConstants.KEY_USERS + '/' + userInfo.getUniqueId();
AuthorizationService.addUserRight(userInfo.getUniqueId(), location);
} catch (CoreException e) {
return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "User rights could not be added.", e));
}
URI userLocation = URIUtil.append(ServletResourceHandler.getURI(req), userInfo.getUniqueId());
if (isEmailRequired) {
try {
UserEmailUtil.getUtil().sendEmailConfirmation(req, userInfo);
return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_CREATED, NLS.bind("Your account {0} has been successfully created. You have been sent an email address verification. Follow the instructions in this email to login to your Orion account.", login), null));
} catch (URISyntaxException e) {
LogHelper.log(e);
return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Could not send confirmation email to " + userInfo.getProperty(UserConstants2.EMAIL), null));
}
}
OrionServlet.writeJSONResponse(req, resp, formJson(userInfo, userLocation, req.getContextPath()));
if (email != null && email.length() > 0 && UserEmailUtil.getUtil().isEmailConfigured()) {
try {