head	1.9;
access;
symbols
	TIGRIS_NOV_12_2000:1.8
	OLDHELM:1.8.0.4
	TIGRIS_NOV_11_2000:1.8
	TIGRIS_SEP_13_2000:1.8.0.2
	TIGRIS_BASELINE:1.8;
locks; strict;
comment	@# @;


1.9
date	2000.11.12.23.10.06;	author dlr;	state dead;
branches;
next	1.8;

1.8
date	2000.09.20.03.13.14;	author brian;	state Exp;
branches;
next	1.7;

1.7
date	2000.08.29.22.12.06;	author jrobbins;	state Exp;
branches;
next	1.6;

1.6
date	2000.06.22.23.39.30;	author dlr;	state Exp;
branches;
next	1.5;

1.5
date	2000.05.02.20.50.46;	author jrobbins;	state Exp;
branches;
next	1.4;

1.4
date	2000.05.02.20.47.50;	author jrobbins;	state Exp;
branches;
next	1.3;

1.3
date	2000.04.18.00.10.33;	author jrobbins;	state Exp;
branches;
next	1.2;

1.2
date	2000.02.03.04.21.31;	author jrobbins;	state Exp;
branches;
next	1.1;

1.1
date	2000.01.30.01.59.36;	author jrobbins;	state Exp;
branches;
next	;


desc
@@


1.9
log
@Does not exist--possibly only WRT this location--in newhelm.
@
text
@/* ================================================================
 * Copyright (c) 2000 Collab.Net.  All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * 3. The end-user documentation included with the redistribution, if
 * any, must include the following acknowlegement: "This product includes
 * software developed by Collab.Net (http://www.Collab.Net/)."
 * Alternately, this acknowlegement may appear in the software itself, if
 * and wherever such third-party acknowlegements normally appear.
 * 
 * 4. The hosted project names must not be used to endorse or promote
 * products derived from this software without prior written
 * permission. For written permission, please contact info@@collab.net.
 * 
 * 5. Products derived from this software may not use the "Tigris" name
 * nor may "Tigris" appear in their names without prior written
 * permission of Collab.Net.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ====================================================================
 * 
 * This software consists of voluntary contributions made by many
 * individuals on behalf of Collab.Net.
 */


package org.tigris.helm.admin;

import org.webmacro.util.*;
import org.webmacro.servlet.*;
import org.webmacro.engine.*;
import org.webmacro.broker.*;

import javax.servlet.*;
import javax.servlet.http.*;

import java.sql.*;
import java.io.IOException;
import com.sun.java.util.collections.ArrayList;
import com.sun.java.util.collections.Iterator;
import com.workingdogs.village.DataSetException;
import gnu.regexp.RE;

import org.joist.security.PermissionSet;
import org.joist.security.RedirectException;
import org.joist.security.SecureServlet;
import org.joist.database.DataManager;
import org.joist.database.UserRoleManager;
import org.joist.database.JoistDatabaseException;

import org.tigris.helm.database.TUserManager;
import org.tigris.helm.tool.UpdateException;

/**
 * Present a form for the addition of a new user
 */
public class UserAdd extends SecureServlet {

    static private Log log = new Log("usrAdd", "UserAdd");
    static private boolean debug = true;
    
    static private RE emailRE = null;
    static private RE loginRE = null;
    static private RE realnameRE = null;
    //static private RE passwordRE = null;

    public void start() throws ServletException {
	super.start();
	try {
	    emailRE = new RE("^[\\w\\-\\._=\\!#\\*\\+]+@@([\\w\\-]+\\.)+[a-zA-Z]{2,3}$");
	    loginRE = new RE("^[\\w]{1,16}$");
	    realnameRE = new RE("^[\\w \\-\\.\\,]+$");
	    //passwordRE = new RE("^[\w]{4,8}$"); //not used
	}
	catch (gnu.regexp.REException e) {
	    log.exception(e);
	}
    }
    
    protected String processRequest(Connection connection, WebContext context)
	throws HandlerException, RedirectException
    {
	String templateName = super.processRequest(connection, context);
	
	// Get the userID and permissions of the person who logged in.
	String loginUserID = (String)context.get("loginUserID");
	PermissionSet userPerms = (PermissionSet)context.get("UserPermissions");

	ArrayList missingFields = new ArrayList();
	ArrayList validationErrors = new ArrayList();
	boolean userExists = false;
	boolean passwordMismatch = false;

	context.put("username", "");
	context.put("name", "");
	context.put("email", "");
	context.put("password1", "");
	context.put("password2", "");

	// Determine which button was pushed
	String action = (String) context.get("action");

	if (action.equals("Create User")) {
	    if (debug) log.debug("action=" + action);
	    String username = context.getForm("username");
	    if (username == null || username.equals(""))
		missingFields.add("LoginID");
	    else {
		//TODO: filter illegal characters
		context.put("username", username);
	    }
	
	    String real_name = context.getForm("name");
	    if (real_name == null || real_name.equals(""))
		missingFields.add("Real Name");
	    else
		context.put("name", real_name);
	
	    String email = context.getForm("email");
	    if (email == null || email.equals(""))
		missingFields.add("Email Address");
	    else
		context.put("email", email);
	
	    String passwd1 = context.getForm("password1");
	    String passwd2 = context.getForm("password2");
	    if (passwd1 == null || passwd2 == null || passwd1.equals(""))
		missingFields.add("Password");
	    else {
		context.put("password1", passwd1);
		context.put("password2", passwd2);
		if (!passwd1.equals(passwd2))
		    passwordMismatch = true;
	    }

	    if (missingFields.isEmpty()) {
		if (!loginRE.isMatch(username))
		    validationErrors.add("LoginID");
		if (!emailRE.isMatch(email))
		    validationErrors.add("Email Address");
		if (!realnameRE.isMatch(real_name))
		    validationErrors.add("Real Name");
	    }
	    
	    if (!userExists && !passwordMismatch &&
		validationErrors.isEmpty() && missingFields.isEmpty()) {
		try {
		    if (debug) log.debug("Creating user " + username);
		    DataManager dMgr = getDataManager(context);
                    TUserManager uMgr = (TUserManager)
                        dMgr.getManager("org.tigris.helm.database.TUserManager");
		    UserRoleManager urMgr = (UserRoleManager)
                        dMgr.getManager("org.joist.database.UserRoleManager");
		    Integer userID = uMgr.addUser(connection, context,
						  username, passwd1, email, 
                                                  real_name);
		    if (debug) log.debug("Created user " + username + "=" + 
                                         userID);

		    String roleName = "Active Developer";
		    urMgr.addRoleForUser(connection, userID.toString(), 
                                         roleName);
		    if (debug) log.debug("Added role for user " + username + 
                                         "=" + userID + " role=" + roleName);
		    
		    if (debug) log.debug("redirecting to user list");
		    redirectTo("UserList");
		    //TODO: multiple step user add wizard?
		}
		catch (SQLException e) {
		    log.exception(e);
		    if (debug) log.debug(e.getMessage());
		    context.put("message", "UserAdd got an SQLException");
		}
		catch (DataSetException e) {
		    log.exception(e);
		    if (debug) log.debug(e.getMessage());
		    context.put("message", "UserAdd got an DataSetException");
		}
		catch (JoistDatabaseException e) {
		    log.exception(e);
		    if (debug) log.debug(e.getMessage());
		    context.put("message", "UserAdd got an SourcexDatabaseException");
		}
		catch (UpdateException e) {
		    log.exception(e);
		    if (debug) log.debug(e.getMessage());
		    context.put("message", "UserAdd got an UpdateException");
		}
	    }
	}
    
	context.put("missingFields", missingFields);
	context.put("validationErrors", validationErrors);
	context.put("userExists", new Boolean(userExists));
	context.put("passwordMismatch", new Boolean(passwordMismatch));
    
	return templateName;
    }

} /* end class UserAdd */
@


1.8
log
@
Obtained from:
Submitted by:
Reviewed by:

Moved from org.helm to org.tigris.helm
Moved from org/helm to org/tigris/helm

perl -pi.bak -e, how I love thee

note: this update was done POST-CVS-REPOSITORY surgury.  In order to
get this right, you may need to remove the directories

$CVSROOT/helm/java/org/helm
$CVSROOT/helm/data/htdoc/look/www/org/helm
$CVSROOT/helm/templates/org/helm

before doing the "CVS update" call, since those directories don't
exist anymore and CVS will try to create lockfiles for you in them,
giving you an error.
@
text
@@


1.7
log
@added more form validation
@
text
@d48 1
a48 1
package org.helm.admin;
d72 2
a73 2
import org.helm.database.TUserManager;
import org.helm.tool.UpdateException;
d172 1
a172 1
                        dMgr.getManager("org.helm.database.TUserManager");
@


1.6
log
@Switched from DataManager.getXxxManger() API to DataManager.getManager("xxx.xxx.xxx").  Please note that this has the possiblity of introducing minor bugs if I did not type all the fully qualified class names properly.
@
text
@d85 1
d93 1
d162 2
@


1.5
log
@added missing line from robin
@
text
@d167 4
a170 2
		    TUserManager uMgr = (TUserManager) dMgr.getUserManager();
		    UserRoleManager urMgr = dMgr.getUserRoleManager();		    
d172 4
a175 2
						  username, passwd1, email, real_name);
		    if (debug) log.debug("Created user " + username + "=" + userID);
d178 4
a181 2
		    urMgr.addRoleForUser(connection, userID.toString(), roleName);
		    if (debug) log.debug("Added role for user " + username + "=" + userID + " role=" + roleName);
@


1.4
log
@fixed a bug where new users do not have roles
@
text
@d168 1
@


1.3
log
@switched from collections2.jar to collections.jar
@
text
@d69 1
d171 5
@


1.2
log
@Added tigris.org license
PR:
Obtained from:
Submitted by:
Reviewed by:
@
text
@d60 2
a61 2
import java.util.ArrayList;
import java.util.Iterator;
@


1.1
log
@initial checking
@
text
@d1 46
a46 1
// Copyright (c) 2000 Collab.Net, Inc. All Rights Reserved.
@

