001: package org.enhydra.dm.presentation;
002:
003: import org.enhydra.dm.EnhydraDM;
004: import org.enhydra.dm.api.UserManager;
005: import org.enhydra.dm.api.exceptions.BaseException;
006: import org.enhydra.dm.business.exceptions.ActionNotAllowedException;
007: import org.enhydra.dm.util.EnhydraDMConstants;
008:
009: import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
010: import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
011:
012: /**
013: * Register.java handles the user registration functionality of the DiscRack app.
014: */
015: public class Register extends Base {
016:
017: RegisterHTML page;
018:
019: UserManager userManager = null;
020:
021: public void run(HttpPresentationComms comms) throws Exception {
022:
023: comms.request.getHttpServletRequest().setCharacterEncoding(
024: EnhydraDMConstants.ENCODING);
025:
026: page = (RegisterHTML) comms.xmlcFactory
027: .create(RegisterHTML.class);
028: boolean doCommit = true;
029: try {
030: initTransaction();
031:
032: String action = comms.request
033: .getParameter(EnhydraDMConstants.ACTION);
034:
035: if (null != action) {
036: documentManager = ((EnhydraDM) comms.application)
037: .getDocumentManager();
038: userManager = ((EnhydraDM) comms.application)
039: .getUserManager();
040: registerUser(comms);
041: }
042:
043: comms.response.writeDOM(page);
044: } catch (Exception ex) {
045: doCommit = false;
046: throw new Exception(ex);
047: } finally {
048: if (doCommit) {
049: commitTransaction();
050: } else {
051: rollbackTransaction();
052: }
053: }
054: }
055:
056: private void registerUser(HttpPresentationComms comms)
057: throws BaseException {
058: try {
059: String username = comms.request
060: .getParameter(EnhydraDMConstants.PARAM_LOGIN);
061: String password = comms.request
062: .getParameter(EnhydraDMConstants.PARAM_PASSWORD);
063: String firstname = comms.request
064: .getParameter(EnhydraDMConstants.PARAM_FIRSTNAME);
065: String lastname = comms.request
066: .getParameter(EnhydraDMConstants.PARAM_LASTNAME);
067: String repassword = comms.request
068: .getParameter(EnhydraDMConstants.PARAM_REPASSWORD);
069:
070: // if login or password field is empty, generate error and redirect to this PO
071: if (username.length() == 0 || password.length() == 0
072: || firstname.length() == 0
073: || lastname.length() == 0) {
074: page
075: .setTextErrorText("Missing information. Please make sure all fields are filled out exactly");
076:
077: return;
078: }
079:
080: // Check that password was duplicated correctly
081: if (!repassword.equals(password)) {
082: page
083: .setTextErrorText("Please make sure your password and password confirmation match exactly");
084: return;
085: }
086: if (userManager != null
087: && userManager.createUser(firstname, lastname,
088: username, password)) {
089: throw new ClientPageRedirectException(
090: EnhydraDMConstants.NAVIG_LOGIN);
091: } else {
092: page
093: .setTextErrorText("User with this username already exists! Please try again!");
094:
095: }
096: } catch (Exception e) {
097: throw new ActionNotAllowedException(e);
098: }
099: }
100: }
|