head	1.43;
access;
symbols
	TIGRIS_1_1_0RC2:1.27
	TIGRIS_1_1_0RC1:1.27
	TIGRIS_1_1:1.27.0.4
	TIGRIS_1_0_8:1.27
	TIGRIS_1_0_8RC3:1.27
	TIGRIS_1_0_8RC2:1.27
	TIGRIS_1_0_8RC1:1.27
	TIGRIS_1_0_7:1.27
	TIGRIS_1_0_7RC3:1.27
	TIGRIS_1_0_7RC2:1.27
	TIGRIS_1_0_7RC1:1.27
	TIGRIS_1_0_6:1.27
	TIGRIS_1_0_6RC5:1.27
	TIGRIS_1_0_6RC4:1.27
	TIGRIS_1_0_6RC3:1.27
	TIGRIS_1_0_6RC2:1.27
	TIGRIS_1_0_6RC1:1.27
	TIGRIS_1_0_5:1.27
	TIGRIS_1_0_5RC6:1.27
	TIGRIS_1_0_5RC5:1.27
	TIGRIS_1_0_5RC4:1.27
	TIGRIS_1_0_5RC3:1.27
	TIGRIS_1_0_5RC2:1.27
	TIGRIS_1_0_5RC1:1.27
	TIGRIS_1_0_4:1.27
	TIGRIS_1_0_3:1.27
	TIGRIS_1_0_2:1.27
	TIGRIS_1_0_1:1.27
	TIGRIS_1_0:1.27.0.6
	TIGRIS_1_0_0:1.27
	TIGRIS_1_0_0_RC1:1.27.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.14.2.1
	TIGRIS_0_9_2_3:1.14.2.1
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.16
	TIGRIS_0_9_2_1:1.16
	TIGRIS_0_9_2:1.14.0.2
	TIGRIS_0_9_0:1.10.0.2
	TIGRIS_0_8_4:1.3.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.43
date	2001.08.11.09.08.01;	author dlr;	state Exp;
branches;
next	1.42;

1.42
date	2001.07.25.19.39.26;	author leonardr;	state Exp;
branches;
next	1.41;

1.41
date	2001.07.24.00.02.27;	author leonardr;	state Exp;
branches;
next	1.40;

1.40
date	2001.07.19.18.42.22;	author dlr;	state Exp;
branches;
next	1.39;

1.39
date	2001.07.19.00.44.23;	author dlr;	state Exp;
branches;
next	1.38;

1.38
date	2001.07.18.10.05.12;	author dlr;	state Exp;
branches;
next	1.37;

1.37
date	2001.07.17.17.55.45;	author leonardr;	state Exp;
branches;
next	1.36;

1.36
date	2001.07.11.23.13.29;	author leonardr;	state Exp;
branches;
next	1.35;

1.35
date	2001.07.06.20.11.50;	author leonardr;	state Exp;
branches;
next	1.34;

1.34
date	2001.07.06.19.59.04;	author leonardr;	state Exp;
branches;
next	1.33;

1.33
date	2001.07.05.23.19.55;	author leonardr;	state Exp;
branches;
next	1.32;

1.32
date	2001.06.21.01.00.43;	author dlr;	state Exp;
branches;
next	1.31;

1.31
date	2001.06.09.01.02.15;	author leonardr;	state Exp;
branches;
next	1.30;

1.30
date	2001.05.25.16.57.15;	author leonardr;	state Exp;
branches;
next	1.29;

1.29
date	2001.05.23.01.50.10;	author dlr;	state Exp;
branches;
next	1.28;

1.28
date	2001.04.11.17.42.11;	author leonardr;	state Exp;
branches;
next	1.27;

1.27
date	2001.03.20.16.42.58;	author leonardr;	state Exp;
branches;
next	1.26;

1.26
date	2001.03.07.01.53.20;	author lucas;	state Exp;
branches;
next	1.25;

1.25
date	2001.03.02.23.38.02;	author dlr;	state Exp;
branches;
next	1.24;

1.24
date	2001.03.02.01.59.17;	author dlr;	state Exp;
branches;
next	1.23;

1.23
date	2001.03.01.08.53.50;	author dlr;	state Exp;
branches;
next	1.22;

1.22
date	2001.02.28.02.55.08;	author dlr;	state Exp;
branches;
next	1.21;

1.21
date	2001.02.28.00.20.29;	author dlr;	state Exp;
branches;
next	1.20;

1.20
date	2001.02.27.09.28.50;	author dlr;	state Exp;
branches;
next	1.19;

1.19
date	2001.02.26.22.01.09;	author dlr;	state Exp;
branches;
next	1.18;

1.18
date	2001.02.21.01.08.21;	author dlr;	state Exp;
branches;
next	1.17;

1.17
date	2001.01.30.03.29.13;	author jrobbins;	state Exp;
branches;
next	1.16;

1.16
date	2001.01.26.18.29.02;	author edk;	state Exp;
branches
	1.16.2.1;
next	1.15;

1.15
date	2001.01.26.05.24.06;	author edk;	state dead;
branches;
next	1.14;

1.14
date	2001.01.15.21.00.50;	author dlr;	state Exp;
branches
	1.14.2.1;
next	1.13;

1.13
date	2000.12.29.02.40.16;	author dlr;	state Exp;
branches;
next	1.12;

1.12
date	2000.12.28.00.58.42;	author dlr;	state Exp;
branches;
next	1.11;

1.11
date	2000.12.27.16.58.17;	author leonardr;	state Exp;
branches;
next	1.10;

1.10
date	2000.12.20.23.12.17;	author dlr;	state Exp;
branches;
next	1.9;

1.9
date	2000.12.20.22.58.12;	author dlr;	state Exp;
branches;
next	1.8;

1.8
date	2000.12.15.10.36.47;	author jrobbins;	state Exp;
branches;
next	1.7;

1.7
date	2000.12.14.19.44.12;	author dlr;	state Exp;
branches;
next	1.6;

1.6
date	2000.12.14.17.16.00;	author leonardr;	state Exp;
branches;
next	1.5;

1.5
date	2000.12.12.21.46.40;	author leonardr;	state Exp;
branches;
next	1.4;

1.4
date	2000.12.05.04.26.29;	author edk;	state Exp;
branches;
next	1.3;

1.3
date	2000.11.29.03.49.22;	author dlr;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2000.11.17.08.12.17;	author edk;	state Exp;
branches;
next	1.1;

1.1
date	2000.11.12.21.15.41;	author dlr;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2000.11.12.21.15.41;	author dlr;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2001.02.21.00.32.21;	author dlr;	state Exp;
branches;
next	;

1.3.2.1
date	2000.12.05.06.34.17;	author jrobbins;	state Exp;
branches;
next	;

1.14.2.1
date	2001.01.30.04.24.23;	author jrobbins;	state Exp;
branches;
next	;

1.16.2.1
date	2001.01.28.01.02.17;	author dlr;	state dead;
branches;
next	1.16.2.2;

1.16.2.2
date	2001.02.07.02.23.55;	author leonardr;	state Exp;
branches;
next	1.16.2.3;

1.16.2.3
date	2001.02.15.20.50.35;	author leonardr;	state Exp;
branches;
next	1.16.2.4;

1.16.2.4
date	2001.02.16.02.42.15;	author leonardr;	state Exp;
branches;
next	1.16.2.5;

1.16.2.5
date	2001.02.16.22.21.58;	author leonardr;	state Exp;
branches;
next	1.16.2.6;

1.16.2.6
date	2001.02.19.23.58.39;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.43
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@/* ================================================================
 * Copyright (c) 2000-2001 CollabNet.  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 CollabNet (http://www.CollabNet/)."
 * 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 CollabNet.
 * 
 * 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 COLLABNET 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 CollabNet.
 */


package org.tigris.helm.domain;

import java.io.IOException;
import java.util.*;
import java.sql.*;

import gnu.regexp.*;

import org.apache.velocity.context.Context;

import org.apache.turbine.util.Log;
import org.apache.commons.util.exception.NestableException;

import org.tigris.helm.tool.HelmProperties;

import org.tigris.helm.AlreadyExists;
import org.tigris.helm.tool.task.TaskException;
import org.tigris.helm.security.*;
import org.tigris.helm.om.*;
import org.tigris.helm.om.UserPeer;
import org.tigris.helm.tool.*;

/**
 * Present a UI for addition of new users.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: UserAdd.java,v 1.42 2001/07/25 19:39:26 leonardr Exp $
 */
public class UserAdd extends UserInfo
{
    /**
     * Whether to log debugging info.
     */
    private static final boolean DEBUG = true;
   
    /**
     * The action used for creating a single user.
     */
    private static final String CREATE_USER_ACTION = "Create User";

    /**
     * The action used for creating multiple users.
     */
    private static final String CREATE_USERS_ACTION = "Create Users";

    /**
     * The field name containing the user's login name
     */
    private static final String LOGIN_NAME_FIELD = "userName";

    /**
     * The field name containing the user's email address
     */
    private static final String EMAIL_FIELD = "email";

    /**
     * The field name containing the user's real name
     */
    private static final String REAL_NAME_FIELD = "realName";

    /**
     * The field name containing the user's organization
     */
    private static final String ORGANIZATION_FIELD = "organization";

    /**
     * The field name containing the user's password
     */
    private static final String PASSWORD_FIELD = "passwd";

    /**
     * The field name containing the confirmation of the user's password
     */
    private static final String PASSWORD_CONFIRM_FIELD = "passwdConfirm";

    /**
     * The big text box containing information for adding multiple users.
     */
    private static final String MULTIPLE_USERS_TEXT_FIELD = "multipleUsers";

    /**
     * The text area filled with a list of user groups to put mass added users
     * into.
     */
    private static final String USER_GROUP_NAMES = "userGroupNames";

    /**
     * The field containing whether or not the form has been seen.
     * Used for setting checkbox defaults.
     */
    private static final String FORM_SEEN_FIELD = "seen";

    /**
     * The checkbox which determines whether or not to email password
     * tickets to newly added users.  
     */
    private static final String SEND_PASSWORD_TICKET_CHECKBOX = 
        "sendPasswordTicket";

    /**
     * The checkbox which determines whether or not to email welcome
     * messages to newly added users.  
     */
    private static final String SEND_WELCOME_EMAIL_CHECKBOX =
        "sendWelcomeEmail";

    /**
     * Display the UI or add the user(s).
     */
    protected String processRequest(Context context)
        throws NestableException, RedirectException
    {
        String templateName = super.processRequest(context);

        try
        {
            // Get all that user input shlock.
            String loginName = ContextAPI.processField
                (context, LOGIN_NAME_FIELD);
            String email = processEmail
                (ContextAPI.processField(context, EMAIL_FIELD));

            String realName = ContextAPI.processField
                (context, REAL_NAME_FIELD);
            String organization = ContextAPI.processField
                (context, ORGANIZATION_FIELD);
            String passwd = ContextAPI.processFieldRaw
                (context, PASSWORD_FIELD);
            String passwdConfirm = ContextAPI.processFieldRaw
                (context, PASSWORD_CONFIRM_FIELD);
            String multipleUsers = ContextAPI.processField
                (context, MULTIPLE_USERS_TEXT_FIELD);
            String userGroupNames = ContextAPI.processField
                (context, USER_GROUP_NAMES);
            
            boolean formSeen = DBFlag.booleanValueOf
                (ContextAPI.processField
                 (context, FORM_SEEN_FIELD, DBFlag.OFF));
            
            boolean sendPasswordTicket = ContextAPI.processCheckbox
                (context, SEND_PASSWORD_TICKET_CHECKBOX);
            boolean sendWelcomeEmail = ContextAPI.processCheckbox
                (context, SEND_WELCOME_EMAIL_CHECKBOX);

            if (!formSeen)
            {
                sendPasswordTicket = true;
                sendWelcomeEmail = true;
            }

            // Process the desired action.
            String action = getAction(context);
            if (action != null)
            {
                StringBuffer buf = new StringBuffer();
                AccessControlList acl = getLoginUser(context).getACL();
                Domain domain = getCurrentDomain(context);

                if (action.equals(CREATE_USER_ACTION))
                {
                    validate(context, loginName, 
                             email, realName, passwd, passwdConfirm);

                    if (ContextAPI.isValidUserInput(context))
                    {
                        // When no password is specified, set the password
                        // to null (prohibiting login) and
                        // send the user a ticket to change the password.
                        if (addUser(acl, domain, context, realName, 
                                    loginName, passwd, email, organization, 
                                    sendPasswordTicket, sendWelcomeEmail,
                                    null, buf))
                        {
                            redirectToNextServletInFlow(action);
                        }
                        // addUser() adds the appropriate message on failure.
                    }
                }
                else if (action.equals(CREATE_USERS_ACTION))
                {
                    // Check for required field.
                    ContextAPI.requireValue(context, multipleUsers, 
                                            "Add multiple users");

                    // Iterate users (one per line).
                    StringTokenizer users = new StringTokenizer(multipleUsers, 
                                                                "\n\r\f");
                    // Iterate fields (tab or space separated)
                    RE regex = null;
                    RE quotedRegex = null;
                    try
                    {
                        regex = new RE("([^\t ]+)[\t ]*");
                        quotedRegex = new RE("([^\"']+)[\"'][\t ]*");
                    }
                    catch (REException e)
                    {
                        Log.error("Could not initialize regular expression.",
                                  e);
                    }

                    UserGroup[] userGroups = parseUserGroups
                        (context, domain, userGroupNames);

                    REMatch match;
                    int pos;
                    int preBatchErrorCount = ContextAPI
                        .getValidationErrors(context).size();
                    while (users.hasMoreTokens())
                    {
                        String data = users.nextToken().trim();

                        if (haveValue(data))
                        {
                            match = regex.getMatch(data);
                            if (DEBUG) Log.debug("match 1=" + match);
                            pos = match.getEndIndex();
                            if (DEBUG) Log.debug("pos 1=" + pos);
                            loginName = match.toString(1);

                            match = regex.getMatch(data, pos);
                            if (DEBUG) Log.debug("match 2=" + match);
                            pos = match.getEndIndex();
                            if (DEBUG) Log.debug("pos 2=" + pos);
                            email = match.toString(1);

                            // The realName field is quoted.
                            match = quotedRegex.getMatch(data, pos);
                            if (DEBUG) Log.debug("match 3=" + match);
                            if (match != null)
                            {
                                realName = match.toString(1);
                                pos = match.getEndIndex();
                                if (DEBUG) Log.debug("pos 3=" + pos);

                                // The organization field is quoted.
                                match = quotedRegex.getMatch(data, pos);
                                if (DEBUG) Log.debug("match 4=" + match);
                                organization =
                                    (match == null ? "" : match.toString(1));
                            }
                            else
                            {
                                // Fall back to email or login user name.
                                int at = email.indexOf('@@');
                                if (at != -1)
                                {
                                    realName = email.substring(0, at);
                                }
                                else
                                {
                                    realName = loginName;
                                }
                            }

                            if ( User.isValidLoginName(loginName) && 
                                 DataValidator.isValidEmail(email) && 
                                 User.isValidRealName(realName) )
                            {
                                // On failure, addUser() puts an appropriate 
                                // message into the context.
                                addUser(acl, domain, context,
                                        realName, loginName,
                                        passwd, email, organization, 
                                        sendPasswordTicket,
                                        sendWelcomeEmail,
                                        userGroups, buf);
                            }
                            else
                            {
                                // Add the user or error condition.
                                buf.setLength(0);
                                buf.append("User record is malformed: ")
                                    .append(data);
                                ContextAPI.addValidationError
                                    (context, buf.toString());
                            }
                        }
                    }

                    // Add additional detail to any error messages
                    // generated by malformed user records.
                    List validationErrors = ContextAPI
                        .getValidationErrors(context);
                    if (validationErrors.size() > preBatchErrorCount)
                    {
                        int index = (preBatchErrorCount == 0 ?
                                     0 : preBatchErrorCount - 1);
                        validationErrors.add
                            (index, "Information entered for either the " +
                             "login name, email address, or real name " +
                             "field during batch user addition is invalid.  " +
                             "Check for improperly placed spaces and mis-" +
                             "matched quotes, and try adding malformed user " +
                             "records again.");
                    }

                    if (ContextAPI.isValidUserInput(context))
                    {
                        // Send the admin on their merry way.
                        redirectToNextServletInFlow(action);
                    }
                }
            }
        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            String errMsg = "Unable to add user: " + e.getMessage();
            Log.error(errMsg, e);
            throw new NestableException(e);
        }
        return templateName;
    }

    /**
     * Redirects to the next servlet in the wizard-like flow.
     *
     * @@param action HELP: Why is this passed?
     */
    protected void redirectToNextServletInFlow(String action)
        throws RedirectException
    {
        redirectTo("UserList");
    }

    /**
     * Parses the provided list of line feed separated user group names and
     * returns an array of <code>UserGroup</code> objects.
     *
     * @@param domain The domain to get the user groups for.
     * @@param list   The text list of user group names.
     * @@param errors The list to note unknown user groups in.
     * @@return       An array, or <code>null</code> if nothing to parse.
     */
    private UserGroup[] parseUserGroups(Context context, Domain domain, 
                                        String list)
        throws Exception
    {
        if (haveValue(list))
        {
            List groups = new ArrayList(1);
            StringTokenizer tok = new StringTokenizer(list);
            while (tok.hasMoreTokens())
            {
                String userGroupName = tok.nextToken().trim();
                if (DEBUG) Log.debug("Parsed user group " + userGroupName +
                                     " to mass add users to");
                try
                {
                    groups.add((UserGroup)UserPeer.getInstanceByLoginName
                               (domain, userGroupName));
                }
                catch (Exception e)
                {
                    ContextAPI.addValidationError
                        (context, 
                         "User group " + userGroupName + " does not exist");
                }
            }
            return (UserGroup [])groups.toArray(new UserGroup[groups.size()]);
        }
        else
        {
            return null;
        }
    }

    /**
     * Adds the specified user, then adds the new user's database key to the 
     * default user group.  Emails the user their password.  On failure, adds
     * an appropriate message to the context.
     *
     * @@param acl       The admin's ACL.
     * @@param realName  The user's real name.
     * @@param loginName The user's login name.
     * @@param passwd    The user's password.
     * @@param email     The user's email.
     * @@param org       The user's organization.
     * @@param sendPasswdTicket First of several indicators checked
     *                         with regard to whether the user should
     *                         be emailed a password ticket when no *
     *                         <code>password</code> value is
     *                         specified.
     * @@param usrGrps   The user groups to add the new user to, or
     *                  <code>null</code> for none.
     * @@return Whether or not addition was successful */
    private boolean addUser(AccessControlList acl, Domain domain, 
                            Context context,
                            String realName, String loginName, String passwd, 
                            String email, String org, 
                            boolean sendPasswordTicket, 
                            boolean sendWelcomeEmail,
                            UserGroup[] usrGrps, StringBuffer buf)
        throws RedirectException, TaskException
    {
        //If they don't have a password, set it to null so they can't
        //log in and (possibly) send them a ticket.
        if (!haveValue(passwd))
        {
            passwd = null;
        }
                         
        try
        {
            User user = User.add(acl, domain, realName, 
                                 loginName, passwd, email, org, 
                                 sendWelcomeEmail);
            if (usrGrps != null && usrGrps.length > 0)
            {
                for (int i = 0; i < usrGrps.length; i++)
                {
                    if (DEBUG)
                    {
                        Log.debug("Adding user " + loginName + " to user group " +
                                  usrGrps[i].getName() + " during user creation");
                    }
                    usrGrps[i].addUser(acl, user);
                }
            }
            boolean emailSuppliedPasswords = "true".equals
                (myProperties.getProperty("emailSuppliedPasswords"));

            if (emailSuppliedPasswords || 
                (passwd == null && sendPasswordTicket))
            {
                // Mail a password ticket to the user.
                String subject = getSubject(domain);
                user.sendNewPasswordTicket(context, subject, 
                                           NEW_USER_PASSWORD_TICKET_TEMPLATE);
            }
        }
        catch (AlreadyExists e)
        {
            ContextAPI.addError(context, e.getMessage());
            return false;
        }
        catch (Exception e)
        {
            String msg = e.getMessage();
            if (DEBUG) Log.error(msg,e);
            redirectToError(context, msg);
        }
        return true;
    }
}
@


1.42
log
@User deletes are now soft deletes which change the user type to 'deleted' (a minimal type of user which has user information but is not allowed associations with roles or user groups). Includes some other miscellaneous bug fixes.
@
text
@d59 1
a59 1
import org.apache.turbine.util.TurbineException;
d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.41 2001/07/24 00:02:27 leonardr Exp $
d158 1
a158 1
        throws TurbineException, RedirectException
d361 1
a361 1
            throw new TurbineException(e);
@


1.41
log
@The final pieces of the error handling revolution.
@
text
@d63 1
d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.40 2001/07/19 18:42:22 dlr Exp $
d483 1
a483 1
        catch (org.tigris.helm.AlreadyExists e)
d485 1
a485 3
            // Report user exists error.
            if (DEBUG) Log.warn(e.getMessage());
            ContextAPI.addError(context, "User already exists: " + loginName);
@


1.40
log
@Updated in light of the port of Joist JoistProperties class to Helm (as class HelmProperties).
@
text
@d73 1
a73 1
 * @@version $Id: UserAdd.java,v 1.39 2001/07/19 00:44:23 dlr Exp $
d486 1
a486 1
            appendToError(context, "User already exists: " + loginName);
@


1.39
log
@Removed [some] Joist dependancies.
@
text
@d61 1
a61 1
import org.joist.util.JoistProperties;
d73 1
a73 1
 * @@version $Id: UserAdd.java,v 1.38 2001/07/18 10:05:12 dlr Exp $
@


1.38
log
@Ported Joist Redirect*Exception to Helm.
@
text
@a59 1
import org.apache.turbine.util.TurbineException;
a60 2
import org.tigris.helm.security.RedirectException;
import org.joist.util.PasswordGenerator;
d73 1
a73 1
 * @@version $Id: UserAdd.java,v 1.37 2001/07/17 17:55:45 leonardr Exp $
@


1.37
log
@Porting of domain package to new error handling API.
@
text
@d62 1
a62 1
import org.joist.security.RedirectException;
d76 1
a76 1
 * @@version $Id: UserAdd.java,v 1.36 2001/07/11 23:13:29 leonardr Exp $
@


1.36
log
@Trim leading and trailing spaces in form fields, except when obtaining passwords.
@
text
@d76 1
a76 1
 * @@version $Id: UserAdd.java,v 1.35 2001/07/06 20:11:50 leonardr Exp $
d167 17
a183 11
            String loginName = processField(context, LOGIN_NAME_FIELD);
            String email = processEmail(processField(context, EMAIL_FIELD));

            String realName = processField(context, REAL_NAME_FIELD);
            String organization = processField(context, ORGANIZATION_FIELD);
            String passwd = processFieldRaw(context, PASSWORD_FIELD);
            String passwdConfirm = processFieldRaw(context,
                                                   PASSWORD_CONFIRM_FIELD);
            String multipleUsers = processField(context,
                                                MULTIPLE_USERS_TEXT_FIELD);
            String userGroupNames = processField(context, USER_GROUP_NAMES);
d186 2
a187 1
                (processField(context, FORM_SEEN_FIELD, DBFlag.OFF));
d189 1
a189 1
            boolean sendPasswordTicket = processCheckbox
d191 1
a191 1
            boolean sendWelcomeEmail = processCheckbox
a203 2
                List missingFields = new ArrayList();
                List validationErrors = new ArrayList();
d210 1
a210 1
                    validate(missingFields, validationErrors, loginName, 
d213 1
a213 1
                    if (isValidUserInput(missingFields, validationErrors))
a226 5
                    else
                    {
                        reportInvalidUserInput(context, missingFields, 
                                               validationErrors);
                    }
d231 2
a232 2
                    requireValue(multipleUsers, "Add multiple users", 
                                 missingFields);
d251 2
a252 3
                    UserGroup[] userGroups = parseUserGroups(domain,
                                                             userGroupNames,
                                                             validationErrors);
d256 2
a257 1
                    int preBatchErrorCount = validationErrors.size();
d324 2
a325 1
                                validationErrors.add(buf.toString());
d332 2
d347 1
a347 1
                    if (isValidUserInput(missingFields, validationErrors))
a351 5
                    else
                    {
                        reportInvalidUserInput(context, missingFields, 
                                               validationErrors);
                    }
d388 2
a389 2
    private UserGroup[] parseUserGroups(Domain domain, String list,
                                        List errors)
d408 3
a410 2
                    errors.add("User group " + userGroupName +
                               " does not exist");
@


1.35
log
@Got rid of extraneous debug.
@
text
@d76 1
a76 1
 * @@version $Id: UserAdd.java,v 1.34 2001/07/06 19:59:04 leonardr Exp $
d172 3
a174 3
            String passwd = processField(context, PASSWORD_FIELD);
            String passwdConfirm = processField(context,
                                                PASSWORD_CONFIRM_FIELD);
@


1.34
log
@Welcome message and password ticket message are both consistently controlled by checkboxes.
@
text
@d76 1
a76 1
 * @@version $Id: UserAdd.java,v 1.33 2001/07/05 23:19:55 leonardr Exp $
a186 1
            Log.debug("Ticket send: " + sendPasswordTicket);
a188 1
                Log.debug("Form unseen.");
a192 1
            Log.debug("2Ticket send: " + sendPasswordTicket);
d466 5
a470 2
                    Log.debug("Adding user " + loginName + " to user group " +
                              usrGrps[i].getName() + " during user creation");
a476 3
            Log.debug("Password: " + passwd);
            Log.debug("emailSuppliedPasswords: " + emailSuppliedPasswords);
            Log.debug("sendPasswordTicket: " + sendPasswordTicket);
@


1.33
log
@Use the template to send email instead of making up the body in Java code.
@
text
@d76 1
a76 1
 * @@version $Id: UserAdd.java,v 1.32 2001/06/21 01:00:43 dlr Exp $
d137 2
a138 2
     * The checkbox which determines whether or not to email newly
     * added users.  
d140 15
a154 1
    private static final String EMAIL_USERS_CHECKBOX = "emailUsers";
d178 8
a185 1
            String emailUsers = processField(context, EMAIL_USERS_CHECKBOX);
d187 9
d214 1
a214 1
                        // to the empty string (prohibiting login) and
d216 4
a219 9
                        //
                        // TODO: Make the sending of tickets an option
                        // that you have to click on a checkbox to
                        // activate.
                        boolean sendPasswdTicket =
                            !(haveValue(passwd) && haveValue(passwdConfirm));
                        if (addUser(acl, domain, context, realName, loginName, 
                                    passwd, email, organization, 
                                    sendPasswdTicket, null, buf))
d317 2
a318 1
                                        DBFlag.booleanValueOf(emailUsers),
a358 1
            context.put(EMAIL_USERS_CHECKBOX, DBFlag.flagValueOf(emailUsers));
d448 3
a450 2
                            boolean sendPasswdTicket, UserGroup[] usrGrps,
                            StringBuffer buf)
d463 2
a464 1
                                 loginName, passwd, email, org);
a473 1

d477 5
a481 1
            if (emailSuppliedPasswords || (passwd == null && sendPasswdTicket))
@


1.32
log
@Clarified error message for bad records in a batch user addition as
per IZ #3493.
@
text
@d76 1
a76 1
 * @@version $Id: UserAdd.java,v 1.31 2001/06/09 01:02:15 leonardr Exp $
a142 7
     * The template to use when sending out password tickets to new
     * users.  
     */
    private static final String NEW_USER_PASSWORD_TICKET_TEMPLATE =
        TemplateTool.getPathToMessageTemplate("NewUserPasswordTicket.vm");

    /**
d454 1
a454 2
                String subject = "How to set your " + domain.getName() 
                    + " password";                
@


1.31
log
@Got rid of the ugly and unneccessary asGroup() and getGroupInstance() methods.
@
text
@d76 1
a76 1
 * @@version $Id: UserAdd.java,v 1.30 2001/05/25 16:57:15 leonardr Exp $
d242 1
d278 1
a278 1
                                // Use email user name.
d284 4
d311 15
@


1.30
log
@.wm is now .vm
@
text
@d76 1
a76 1
 * @@version $Id: UserAdd.java,v 1.29 2001/05/23 01:50:10 dlr Exp $
d370 1
a370 1
                    groups.add(UserPeer.getGroupInstanceByName
@


1.29
log
@Ported Helm from WebMacro to Velocity.
@
text
@d76 1
a76 1
 * @@version $Id: UserAdd.java,v 1.28 2001/04/11 17:42:11 leonardr Exp $
d147 1
a147 1
        TemplateTool.getPathToMessageTemplate("NewUserPasswordTicket.wm");
@


1.28
log
@Reworked PasswordEdit and got rid of the practice of generating passwords for new users. New users now get a ticket into PasswordEdit to set their passwords initially.
@
text
@d56 1
a56 1
import org.webmacro.servlet.*;
d59 2
d76 1
a76 1
 * @@version $Id: UserAdd.java,v 1.27 2001/03/20 16:42:58 leonardr Exp $
d152 2
a153 2
    protected String processRequest(Connection conn, WebContext context)
        throws HandlerException, RedirectException
d155 1
a155 1
        String templateName = super.processRequest(conn, context);
d330 1
a330 1
            throw new HandlerException(errMsg);
d407 1
a407 1
                            WebContext context,
@


1.27
log
@Refactored some code (and shamelessly copied some other code) so that Join can work as well as UserAdd.
@
text
@d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.26 2001/03/07 01:53:20 lucas Exp $
d141 2
a142 1
     * The field name containing the user's 
d144 2
a145 1
    private static final String _FIELD = "";
d188 8
a195 4
                        // Only send the password when none is specified.
                        // TODO: Leonard recommends controlling this via a 
                        // checkbox instead (defaulting to off).
                        boolean sendPasswd =
d198 2
a199 2
                                    passwd, email, organization, sendPasswd,
                                    null, buf))
d396 5
a400 3
     * @@param sendPasswdEmail First of several indicators checked with regard
     *                  to whether the user should be emailed their password
     *                  when no <code>password</code> value is specified.
d403 1
a403 2
     * @@return          Whether or not addition was successful
     */
d408 1
a408 1
                            boolean sendPasswdEmail, UserGroup[] usrGrps,
d412 3
a414 3
        boolean hadPassword = haveValue(passwd);
        // Generate a password if need be.
        if (!hadPassword)
d416 1
a416 1
            passwd = PasswordGenerator.password();
d418 1
a418 1

d436 1
a436 1
            if ((!hadPassword && sendPasswdEmail) || emailSuppliedPasswords)
d438 5
a442 4
                // Mail the password to the user.
                String subject = getSubject(buf, domain, loginName);
                new HelmEmailer().mailUserFromSystem
                    (user, subject, getMessage(buf, subject, passwd));
@


1.26
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.25 2001/03/02 23:38:02 dlr Exp $
a144 6

    /**
     * The <code>mailto:</code> part of a mail href.
     */
    private static final String MAIL_TO = "mailto:";

d157 1
a157 10
            String email = processField(context, EMAIL_FIELD);

            // Treat "mailto:x" the same as "x".
            if (email.length() > MAIL_TO.length())
            {
                if (email.startsWith(MAIL_TO))
                {
                    email = email.substring(MAIL_TO.length());
                }                
            }
a450 32
    }

    /**
     * Formats the subject of an email message.
     *
     * @@param buf     The buffer to use for formatting.
     * @@param project The project that the message is regarding.
     * @@return        The formatted text.
     */
    private static final String getSubject (StringBuffer buf, Domain domain, 
                                            String loginName)
    {
        buf.setLength(0);
        buf.append("The ").append(domain.getName())
            .append(" password for the user '")
            .append(loginName).append('\'');
        return buf.toString();
    }

    /**
     * Formats the body of an email message.
     *
     * @@param buf     The buffer to use for formatting.
     * @@param project The project that the message is regarding.
     * @@return        The formatted text.
     */
    private static final String getMessage (StringBuffer buf, String msgStart, 
                                            String passwd)
    {
        buf.setLength(0);
        buf.append(msgStart).append(" is:\n\n").append(passwd).append('\n');
        return buf.toString();
@


1.25
log
@It's an email containing the password only.
@
text
@d67 1
a67 1
import org.tigris.helm.om.peer.UserPeer;
d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.24 2001/03/02 01:59:17 dlr Exp $
@


1.24
log
@* Now works due to fix to UserPeer.getGroupInstanceByName()!
* Added validation errors parameter to parseUserGroups() method to
  record unknown user groups in.
* Added improved debugging information.
@
text
@d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.23 2001/03/01 08:53:50 dlr Exp $
d405 3
a407 3
     * @@param sendEmail First of several indicators checked with regard to
     *                  whether the user should be emailed their password when 
     *                  no <code>password</code> value is specified.
d416 1
a416 1
                            boolean sendEmail, UserGroup[] usrGrps,
d444 1
a444 1
            if ((!hadPassword && sendEmail) || emailSuppliedPasswords)
@


1.23
log
@Attempted to add support for mass add of users to user groups.  This
feature does not actually work yet, but does not break anything,
either (so I'm going to go ahead and commit it).
@
text
@d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.22 2001/02/28 02:55:08 dlr Exp $
d243 3
a245 2
                    UserGroup[] userGroups =
                        parseUserGroups(domain, userGroupNames);
d359 1
d362 2
a363 1
    private UserGroup[] parseUserGroups(Domain domain, String list)
d372 3
d378 1
a378 1
                               (domain, tok.nextToken().trim()));
d382 2
a383 1
                    // TODO: Handle unknown groups gracefully.
d435 2
@


1.22
log
@Only send the password in single user add when none is specified.
@
text
@d67 1
a67 1

d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.21 2001/02/28 00:20:29 dlr Exp $
d129 6
d181 1
d208 1
a208 1
                                    buf))
d242 4
d301 1
a301 1
                                        buf);
d353 35
d401 2
d405 6
a410 5
    private boolean addUser (AccessControlList acl, Domain domain, 
                             WebContext context,
                             String realName, String loginName, String passwd, 
                             String email, String org, 
                             boolean sendEmail, StringBuffer buf)
d424 8
@


1.21
log
@Don't email users when the checkbox isn't checked!  (A side affect of
this commit results in the box defaulting to not checked.)
@
text
@d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.20 2001/02/27 09:28:50 dlr Exp $
d194 5
d200 2
a201 1
                                    passwd, email, organization, true, buf))
@


1.20
log
@Organization is now supported as a fourth parameter in the mass user
add section.
@
text
@d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.19 2001/02/26 22:01:09 dlr Exp $
d159 1
a159 1
            //Treat "mailto:x" the same as "x".
d175 1
a175 2
            String emailUsers = processField(context, EMAIL_USERS_CHECKBOX,
                                             DBFlag.ON);
d283 2
a284 1
                                        haveValue(emailUsers), buf);
d309 1
@


1.19
log
@Broke long lines.
@
text
@d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.18 2001/02/21 01:08:21 dlr Exp $
d81 1
a81 1
    private static final boolean debug = true;
d223 1
a223 1
                        quotedRegex = new RE("([^\"']+)");
d239 1
a239 1
                            if (debug) Log.debug("match 1=" + match);
d241 1
a241 1
                            if (debug) Log.debug("pos 1=" + pos);
d245 1
a245 1
                            if (debug) Log.debug("match 2=" + match);
d247 1
a247 1
                            if (debug) Log.debug("pos 2=" + pos);
d252 1
a252 1
                            if (debug) Log.debug("match 3=" + match);
d256 8
d317 2
a318 2
            if (debug) Log.error(errMsg,e);
            appendToMessage(context, errMsg);
d382 1
a382 1
            if (debug) Log.warn(e.getMessage());
d389 1
a389 1
            if (debug) Log.error(msg,e);
@


1.18
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.16.2.6 2001/02/19 23:58:39 dlr Exp $
d171 6
a176 3
            String passwdConfirm = processField(context, PASSWORD_CONFIRM_FIELD);
            String multipleUsers = processField(context, MULTIPLE_USERS_TEXT_FIELD);
            String emailUsers = processField(context, EMAIL_USERS_CHECKBOX, DBFlag.ON);
d227 2
a228 1
                        Log.error("Could not initialize regular expression.", e);
@


1.17
log
@implemented join and joinconfirm
@
text
@d2 1
a2 1
 * Copyright (c) 2000 CollabNet.  All rights reserved.
d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d51 1
a51 3
import java.util.StringTokenizer;
import java.util.List;
import java.util.ArrayList;
d54 2
a55 1
import org.webmacro.util.Log;
d58 1
a58 5
import gnu.regexp.RE;
import gnu.regexp.REMatch;
import gnu.regexp.REException;

import com.workingdogs.village.DataSetException;
a60 1
import org.joist.database.*;
d62 1
a62 1
import org.joist.mail.Emailer;
d64 1
a64 1
import org.tigris.helm.tool.UpdateException;
d66 3
a68 5
import org.tigris.helm.database.UserUserGroupManager;
import org.tigris.helm.project.Project;
import org.tigris.helm.tool.DataValidator;
import org.tigris.helm.tool.DBFlag;
import org.tigris.helm.tool.audit.AuditLog;
d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.16 2001/01/26 18:29:02 edk Exp $
a78 5
     * The log file.
     */
    private static Log log = new Log("usrAdd", "UserAdd");

    /**
d82 1
a82 1
    
d94 47
d156 2
a157 2
            String userName = processField(context, "userName");
            String email = processField(context, "email");
d168 6
a173 6
            String realName = processField(context, "realName");
            String organization = processField(context, "organization");
            String passwd = processField(context, "passwd");
            String passwdConfirm = processField(context, "passwdConfirm");
            String multipleUsers = processField(context, "multipleUsers");
            String emailUsers = processField(context, "emailUsers", DBFlag.ON);
d176 1
a176 2
            String action = (String) context.get("action");
            if (debug) log.debug("action=" + action);
d182 2
a183 1
                AccessControlList acl = getACL(context, conn);
d187 2
a188 2
                    validate(missingFields, validationErrors, userName, email, 
                             realName, passwd, passwdConfirm);
d192 1
a192 1
                        if (addUser(acl, conn, context, realName, userName, 
d224 1
a224 1
                        log.exception(e);
d235 1
a235 1
                            if (debug) log.info("match 1=" + match);
d237 2
a238 2
                            if (debug) log.info("pos 1=" + pos);
                            userName = match.toString(1);
d241 1
a241 1
                            if (debug) log.info("match 2=" + match);
d243 1
a243 1
                            if (debug) log.info("pos 2=" + pos);
d248 1
a248 1
                            if (debug) log.info("match 3=" + match);
d263 1
a263 1
                            if ( User.isValidUserName(userName) && 
d269 2
a270 1
                                addUser(acl, conn, context, realName, userName,
a303 1
            log.exception(e);
d305 1
a305 1
            if (debug) log.warning(errMsg);
d311 6
a316 1
    public void redirectToNextServletInFlow(String action)
a327 2
     * @@param conn      The JDBC connection.
     * @@param ctx       The context of user interaction.
d329 1
a329 1
     * @@param userName  The user's loginID.
d338 3
a340 3
    private boolean addUser (AccessControlList acl,
                             Connection conn, WebContext ctx, 
                             String realName, String userName, String passwd, 
d343 1
a343 1
        throws RedirectException, UpdateException
d354 5
a358 9
            Domain domain = getCurrentDomain(ctx);
            User user = new User(acl, conn, dMgr, ctx, domain.getID(),
                                 realName, userName, passwd, email, org);
            if (debug) log.info("Created user: " + user.getName() + " [" + 
                                 user.getID() + ']');
            AuditLog.logItem(conn, dMgr, acl.getUserID(), domain, 
                             "Added user " + user.getName());
            boolean emailSuppliedPasswords =
                "true".equals(myProperties.getProperty("emailSuppliedPasswords"));
d362 3
a364 4
                User admin = getLoginUser(ctx);
                String subject = getSubject(buf, domain, userName);
                new Emailer().sendEmailFrom(admin.getEmail(), email, subject, 
                                            getMessage(buf, subject, passwd));
d370 2
a371 10
            if (debug) log.warning(e.getMessage());
            appendToMessage(ctx,
                            "User email alias already exists: " + userName);
            return false;
        }
        catch (InsertFailedException e)
        {
            // Report user exists error.
            if (debug) log.warning(e.getMessage());
            appendToMessage(ctx, "User name already exists: " + userName);
a375 1
            log.exception(e);
d377 2
a378 2
            if (debug) log.error(msg);
            redirectToError(ctx, msg);
d391 1
a391 2
                                            String userName)
        throws DataSetException
d396 1
a396 1
            .append(userName).append('\'');
a408 2
                                            
        throws DataSetException
@


1.16
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d82 1
a82 1
 * @@version $Id: UserAdd.java,v 1.14 2001/01/15 21:00:50 dlr Exp $
d161 1
a161 1
                            redirectTo("UserList");
d253 1
a253 1
                        redirectTo("UserList");
d277 6
d325 1
a325 2
                myProperties.getProperty("emailSuppliedPasswords")
                .equals("true");
@


1.16.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d82 1
a82 1
 * @@version $Id: UserAdd.java,v 1.16 2001/01/26 18:29:02 edk Exp $
@


1.16.2.2
log
@Ported UserAdd servlet.
@
text
@d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d51 3
a53 1
import java.util.*;
d56 2
a57 1
import gnu.regexp.*;
d59 3
a61 1
import org.webmacro.servlet.*;
d63 1
a63 1
import org.apache.turbine.util.Log;
d66 1
a68 1
import org.joist.util.JoistProperties;
d70 1
a70 1
import org.tigris.helm.tool.task.TaskException;
d72 2
a73 2
import org.tigris.helm.om.*;

d76 1
a76 1
//import org.tigris.helm.tool.audit.AuditLog;
d82 1
a82 1
 * @@version $Id: UserAdd.java,v 1.17 2001/01/30 03:29:13 jrobbins Exp $
d87 5
d95 1
a95 1
   
a106 47
     * The field name containing the user's login name
     */
    private static final String LOGIN_NAME_FIELD = "userName";

    /**
     * The field name containing the user's email address
     */
    private static final String EMAIL_FIELD = "email";

    /**
     * The field name containing the user's real name
     */
    private static final String REAL_NAME_FIELD = "realName";

    /**
     * The field name containing the user's organization
     */
    private static final String ORGANIZATION_FIELD = "organization";

    /**
     * The field name containing the user's password
     */
    private static final String PASSWORD_FIELD = "passwd";

    /**
     * The field name containing the confirmation of the user's password
     */
    private static final String PASSWORD_CONFIRM_FIELD = "paswdConfirm";

    /**
     * The big text box containing information for adding multiple users.
     */
    private static final String MULTIPLE_USERS_TEXT_FIELD = "multipleUsers";

    /**
     * The checkbox which determines whether or not to email newly
     * added users.  
     */
    private static final String EMAIL_USERS_CHECKBOX = "emailUsers";

    /**
     * The field name containing the user's 
     */
    private static final String _FIELD = "";


    /**
d122 2
a123 2
            String loginName = processField(context, LOGIN_NAME_FIELD);
            String email = processField(context, EMAIL_FIELD);
d134 6
a139 6
            String realName = processField(context, REAL_NAME_FIELD);
            String organization = processField(context, ORGANIZATION_FIELD);
            String passwd = processField(context, PASSWORD_FIELD);
            String passwdConfirm = processField(context, PASSWORD_CONFIRM_FIELD);
            String multipleUsers = processField(context, MULTIPLE_USERS_TEXT_FIELD);
            String emailUsers = processField(context, EMAIL_USERS_CHECKBOX, DBFlag.ON);
d143 1
d149 1
a149 2
                AccessControlList acl = getLoginUser(context).getACL();
                Domain domain = getCurrentDomain(context);
d153 1
a153 1
                    validate(missingFields, validationErrors, loginName, email, 
d158 1
a158 1
                        if (addUser(acl, domain, context, realName, loginName, 
d161 1
a161 1
                            redirectToNextServletInFlow(action);
d190 1
a190 1
                        Log.error("Could not initialize regular expression.", e);
d201 1
a201 1
                            if (debug) Log.debug("match 1=" + match);
d203 2
a204 2
                            if (debug) Log.debug("pos 1=" + pos);
                            loginName = match.toString(1);
d207 1
a207 1
                            if (debug) Log.debug("match 2=" + match);
d209 1
a209 1
                            if (debug) Log.debug("pos 2=" + pos);
d214 1
a214 1
                            if (debug) Log.debug("match 3=" + match);
d229 1
a229 1
                            if ( User.isValidLoginName(loginName) && 
d235 1
a235 1
                                addUser(acl, domain, context, realName, loginName,
d253 1
a253 1
                        redirectToNextServletInFlow(action);
d269 1
d271 1
a271 1
            if (debug) Log.error(errMsg,e);
a276 6
    public void redirectToNextServletInFlow(String action)
        throws RedirectException
    {
        redirectTo("UserList");
    }

d283 2
d286 1
a286 1
     * @@param loginName The user's login name.
d295 3
a297 2
    private boolean addUser (AccessControlList acl, Domain domain, WebContext ctx,
                             String realName, String loginName, String passwd, 
d300 1
a300 1
        throws RedirectException, TaskException
d311 7
a317 4
            User user = User.add(acl, domain, realName, 
                                 loginName, passwd, email, org);
            //AuditLog.logItem(acl.getUserID(), domain, 
            //"Added user " + user.getName());
d319 2
a320 1
                "true".equals(myProperties.getProperty("emailSuppliedPasswords"));
d325 1
a325 1
                String subject = getSubject(buf, domain, loginName);
d333 10
a342 2
            if (debug) Log.warn(e.getMessage());
            appendToMessage(ctx, "User already exists: " + loginName);
d347 1
d349 1
a349 1
            if (debug) Log.error(msg,e);
d363 2
a364 1
                                            String loginName)
d369 1
a369 1
            .append(loginName).append('\'');
d382 2
@


1.16.2.3
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d77 1
a77 1
 * @@version $Id: UserAdd.java,v 1.16.2.2 2001/02/07 02:23:55 leonardr Exp $
@


1.16.2.4
log
@Changed field name which was causing big problems.
@
text
@d77 1
a77 1
 * @@version $Id: UserAdd.java,v 1.16.2.3 2001/02/15 20:50:35 leonardr Exp $
d124 1
a124 1
    private static final String PASSWORD_CONFIRM_FIELD = "passwdConfirm";
@


1.16.2.5
log
@Cleanup.
@
text
@d62 1
d69 3
a71 1
import org.tigris.helm.tool.*;
d77 1
a77 1
 * @@version $Id: UserAdd.java,v 1.16.2.4 2001/02/16 02:42:15 leonardr Exp $
d179 1
a179 1
            String action = getAction(context);
d190 2
a191 2
                    validate(missingFields, validationErrors, loginName, 
                             email, realName, passwd, passwdConfirm);
d272 1
a272 2
                                addUser(acl, domain, context,
                                        realName, loginName,
d335 1
a335 2
    private boolean addUser (AccessControlList acl, Domain domain, 
                             WebContext context,
d352 2
d359 1
d361 2
a362 2
                new HelmEmailer().mailUserFromSystem
                    (user, subject, getMessage(buf, subject, passwd));
d369 1
a369 1
            appendToError(context, "User already exists: " + loginName);
d376 1
a376 1
            redirectToError(context, msg);
@


1.16.2.6
log
@JavaDoc'd redirectToNextServletInFlow() method.
@
text
@d74 1
a74 1
 * @@version $Id: UserAdd.java,v 1.16.2.5 2001/02/16 22:21:58 leonardr Exp $
d311 1
a311 6
    /**
     * Redirects to the next servlet in the wizard-like flow.
     *
     * @@param action HELP: Why is this passed?
     */
    protected void redirectToNextServletInFlow(String action)
d351 2
a352 3
            boolean emailSuppliedPasswords = "true".equals
                (myProperties.getProperty("emailSuppliedPasswords"));

@


1.15
log
@revert this stuff to its state as of 2001/01/24 12:42:00 GMT -- with
the following exceptions, which have some different modifications so
they'll work with changes which have happened in joist:

ProjectNewsEdit.java
SkinManager.java
SkinStyleElementValueManager.java
StyleElementManager.java
StyleManager.java

it compiles.  i dunno if it works, though.
@
text
@@


1.14
log
@* Modified regex and logic to handle no user real name.  In this case,
  email user name is used instead.
* Removed debugging info.
@
text
@d82 1
a82 1
 * @@version $Id: UserAdd.java,v 1.13 2000/12/29 02:40:16 dlr Exp $
@


1.14.2.1
log
@moved changes from HEAD
@
text
@d82 1
a82 1
 * @@version $Id: UserAdd.java,v 1.17 2001/01/30 03:29:13 jrobbins Exp $
d161 1
a161 1
                            redirectToNextServletInFlow(action);
d253 1
a253 1
                        redirectToNextServletInFlow(action);
a276 6
    public void redirectToNextServletInFlow(String action)
        throws RedirectException
    {
        redirectTo("UserList");
    }

d319 2
a320 1
                "true".equals(myProperties.getProperty("emailSuppliedPasswords"));
@


1.13
log
@Made use of new DBFlag class.
@
text
@d82 1
a82 1
 * @@version $Id: UserAdd.java,v 1.12 2000/12/28 00:58:42 dlr Exp $
d185 1
a185 1
                        regex = new RE("([^\t ]+)[\t ]+");
d215 5
a219 3
                            realName = match.toString(1);

                            if (debug)
d221 6
a226 6
                                log.info("User.isValidUserName(\"" + userName + 
                                          "\")=" + User.isValidUserName(userName));
                                log.info("DataValidator.isValidEmail(\"" + email + "\")=" + 
                                          DataValidator.isValidEmail(email));
                                log.info("User.isValidRealName(\"" + realName + 
                                          "\")=" + User.isValidRealName(realName));
d235 1
a235 1
                                addUser(acl, conn, context, realName, userName, 
@


1.12
log
@* Introduced constant for "mailto:".
* Replaced check for null against a value returned by processField()--which
  never returns null--with a check that is actually useful.
@
text
@d75 1
d82 1
a82 1
 * @@version $Id: UserAdd.java,v 1.11 2000/12/27 16:58:17 leonardr Exp $
d139 1
a139 1
            String emailUsers = processField(context, "emailUsers", "Y");
@


1.11
log
@Treat 'mailto:x' the same as 'x' in email addresses.
@
text
@d81 1
a81 1
 * @@version $Id: UserAdd.java,v 1.10 2000/12/20 23:12:17 dlr Exp $
d106 5
d125 1
a125 1
            if (email != null)
d127 1
a127 1
                if (email.startsWith("mailto:"))
d129 1
a129 1
                    email = email.substring(7);
@


1.10
log
@Removed unnecessary negative logic for simplicity.
@
text
@d81 1
a81 1
 * @@version $Id: UserAdd.java,v 1.9 2000/12/20 22:58:12 dlr Exp $
d118 10
@


1.9
log
@Corrected bug where passwords would be emailed to users during a mass
add regardless as to whether the checkbox was checked (IZ #1648).
@
text
@d81 1
a81 1
 * @@version $Id: UserAdd.java,v 1.8 2000/12/15 10:36:47 jrobbins Exp $
d143 1
a143 1
                                    passwd, email, organization, false, buf))
d219 1
a219 1
                                        !haveValue(emailUsers), buf);
d272 1
a272 1
     * @@param doNotSend First of several indicators checked with regard to
d281 1
a281 1
                             boolean doNotSend, StringBuffer buf)
d303 1
a303 1
            if ((!hadPassword && !doNotSend) || emailSuppliedPasswords)
@


1.8
log
@made UserAdd not send a password if it was supplied, that way you can create an account without broadcasting the password
@
text
@d81 1
a81 1
 * @@version $Id: UserAdd.java,v 1.7 2000/12/14 19:44:12 dlr Exp $
d142 3
a144 3
                        if (addUser(acl, conn, context, realName,
                                    userName, passwd, email, organization, buf)) {
                            // success: send the admin on their merry way.
d147 1
a147 1
                         // failure : addUser should have added a message
d215 1
a215 1
                                // On failure, addUser puts an appropriate 
d217 3
a219 3
                                addUser(acl, conn, context, 
                                        realName, userName, passwd, 
                                        email, organization, buf);
d261 2
a262 1
     * default user group.  Emails the user their password.
d264 12
a275 1
     * @@return whether or not addition was successful
d278 4
a281 3
                          Connection conn, WebContext context, 
                          String realName, String userName, String passwd, 
                          String email, String organization, StringBuffer buf)
d293 3
a295 4
            Domain domain = getCurrentDomain(context);
            User user = new User(acl, conn, dMgr, context, domain.getID(),
                                 realName, userName, passwd, email, 
                                 organization);
d300 11
a310 10
            if (!hadPassword || "true".equals(myProperties.get("emailSuppliedPasswords")))
                {
                    // Mail the password to the user.
                    User admin = getLoginUser(context);
                    String subject = getSubject(buf, domain, userName);
                    new Emailer().sendEmailFrom(admin.getEmail(), email, subject, 
                                                getMessage(buf,
                                                           subject,
                                                           passwd));
                }
d316 2
a317 2
            appendToMessage(context,
                    "User email alias already exists: " + userName);
d324 1
a324 2
            appendToMessage(context, 
                            "User name already exists: " + userName);
d331 2
a332 2
            if (debug) log.warning(msg);
            redirectToError(context, msg);
@


1.7
log
@Corrected compiler errors.
@
text
@d81 1
a81 1
 * @@version $Id: UserAdd.java,v 1.6 2000/12/14 17:16:00 leonardr Exp $
d271 1
d273 1
a273 1
        if (!haveValue(passwd))
d288 10
a297 5
            // Mail the password to the user.
            User admin = getLoginUser(context);
            String subject = getSubject(buf, domain, userName);
            new Emailer().sendEmailFrom(admin.getEmail(), email, subject, 
                                        getMessage(buf, subject, passwd));
@


1.6
log
@Made user additions auditable.
@
text
@d74 1
d81 1
a81 1
 * @@version $Id: UserAdd.java,v 1.5 2000/12/12 21:46:40 leonardr Exp $
d203 6
a208 6
                                log.info("userNameRE.isMatch(\"" + userName + 
                                          "\")=" + userNameRE.isMatch(userName));
                                log.info("emailRE.isMatch(\"" + email + "\")=" + 
                                          emailRE.isMatch(email));
                                log.info("realNameRE.isMatch(\"" + realName + 
                                          "\")=" + realNameRE.isMatch(realName));
d211 3
a213 6
                            if ( (haveValue(userName) && 
                                  userNameRE.isMatch(userName)) &&
                                 (haveValue(email) && 
                                  emailRE.isMatch(email)) && 
                                 (haveValue(realName) && 
                                  realNameRE.isMatch(realName)) )
d215 2
a219 2
                                // on failure, addUser puts an appropriate
                                // message into the context
@


1.5
log
@Support for user organization
@
text
@d74 1
d80 1
a80 1
 * @@version $Id: UserAdd.java,v 1.4 2000/12/05 04:26:29 edk Exp $
d281 2
a282 2
            String domainID = getCurrentDomain(context).getID();
            User user = new User(acl, conn, dMgr, context, domainID,
d287 2
a289 1
            Domain domain = getCurrentDomain(context);
@


1.4
log
@handle AlreadyExists errors cleanly for user creation
@
text
@d79 1
a79 1
 * @@version $Id: UserAdd.java,v 1.3 2000/11/29 03:49:22 dlr Exp $
d117 1
d141 1
a141 1
                                    userName, passwd, email, buf)) {
d218 1
a218 1
                                        email, buf);
d269 1
a269 1
                          String email, StringBuffer buf)
d282 2
a283 1
                                 realName, userName, passwd, email);
@


1.3
log
@Modified some debug traces so that they would actually show up.
@
text
@d79 1
a79 1
 * @@version $Id: UserAdd.java,v 1.2 2000/11/17 08:12:17 edk Exp $
d139 6
a144 5
                        addUser(acl, conn, context, realName,
                                userName, passwd, email, buf);

                        // Send the admin on their merry way.
                        redirectTo("UserList");
d218 2
d262 2
d265 1
a265 1
    private void addUser (AccessControlList acl,
d291 8
d305 1
d314 1
@


1.3.2.1
log
@merged in changes from HEAD
@
text
@d79 1
a79 1
 * @@version $Id: UserAdd.java,v 1.4 2000/12/05 04:26:29 edk Exp $
d139 5
a143 6
                        if (addUser(acl, conn, context, realName,
                                    userName, passwd, email, buf)) {
                            // success: send the admin on their merry way.
                            redirectTo("UserList");
                        }
                         // failure : addUser should have added a message
a216 2
                                // on failure, addUser puts an appropriate
                                // message into the context
a258 2
     *
     * @@return whether or not addition was successful
d260 1
a260 1
    private boolean addUser (AccessControlList acl,
a285 8
        catch (org.tigris.helm.AlreadyExists e)
        {
            // Report user exists error.
            if (debug) log.warning(e.getMessage());
            appendToMessage(context,
                    "User email alias already exists: " + userName);
            return false;
        }
a291 1
            return false;
a299 1
        return true;
@


1.2
log
@notify anzu during user creation & when updates alter the e-mail address
@
text
@d79 1
a79 1
 * @@version $Id: UserAdd.java,v 1.1.1.1 2000/11/12 21:15:41 dlr Exp $
d181 1
a181 1
                            if (debug) log.debug("match 1=" + match);
d183 1
a183 1
                            if (debug) log.debug("pos 1=" + pos);
d187 1
a187 1
                            if (debug) log.debug("match 2=" + match);
d189 1
a189 1
                            if (debug) log.debug("pos 2=" + pos);
d194 1
a194 1
                            if (debug) log.debug("match 3=" + match);
d199 1
a199 1
                                log.debug("userNameRE.isMatch(\"" + userName + 
d201 1
a201 1
                                log.debug("emailRE.isMatch(\"" + email + "\")=" + 
d203 1
a203 1
                                log.debug("realNameRE.isMatch(\"" + realName + 
d250 1
a250 1
            if (debug) log.debug(errMsg);
d277 1
a277 1
            if (debug) log.debug("Created user: " + user.getName() + " [" + 
d289 1
a289 1
            if (debug) log.debug(e.getMessage());
d297 1
a297 1
            if (debug) log.debug(msg);
@


1.1
log
@Initial revision
@
text
@d79 1
a79 1
 * @@version $Id: UserAdd.java,v 1.38 2000/11/11 03:33:32 dlr Exp $
d275 2
a276 2
            User user = new User(acl, conn, dMgr, context, 
                                 domainID, realName, userName, passwd);
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@@


1.1.1.2
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d51 3
a53 1
import java.util.*;
d56 2
a57 1
import gnu.regexp.*;
d59 3
a61 1
import org.webmacro.servlet.*;
d63 1
a63 1
import org.apache.turbine.util.Log;
d66 1
d68 1
a68 1
import org.joist.util.JoistProperties;
d70 1
a70 1
import org.tigris.helm.tool.task.TaskException;
d72 2
a73 3
import org.tigris.helm.om.*;

import org.tigris.helm.tool.*;
d79 1
a79 1
 * @@version $Id: UserAdd.java,v 1.16.2.6 2001/02/19 23:58:39 dlr Exp $
d84 5
d92 1
a92 1
   
a103 52
     * The field name containing the user's login name
     */
    private static final String LOGIN_NAME_FIELD = "userName";

    /**
     * The field name containing the user's email address
     */
    private static final String EMAIL_FIELD = "email";

    /**
     * The field name containing the user's real name
     */
    private static final String REAL_NAME_FIELD = "realName";

    /**
     * The field name containing the user's organization
     */
    private static final String ORGANIZATION_FIELD = "organization";

    /**
     * The field name containing the user's password
     */
    private static final String PASSWORD_FIELD = "passwd";

    /**
     * The field name containing the confirmation of the user's password
     */
    private static final String PASSWORD_CONFIRM_FIELD = "passwdConfirm";

    /**
     * The big text box containing information for adding multiple users.
     */
    private static final String MULTIPLE_USERS_TEXT_FIELD = "multipleUsers";

    /**
     * The checkbox which determines whether or not to email newly
     * added users.  
     */
    private static final String EMAIL_USERS_CHECKBOX = "emailUsers";

    /**
     * The field name containing the user's 
     */
    private static final String _FIELD = "";


    /**
     * The <code>mailto:</code> part of a mail href.
     */
    private static final String MAIL_TO = "mailto:";

    /**
d114 7
a120 18
            String loginName = processField(context, LOGIN_NAME_FIELD);
            String email = processField(context, EMAIL_FIELD);

            //Treat "mailto:x" the same as "x".
            if (email.length() > MAIL_TO.length())
            {
                if (email.startsWith(MAIL_TO))
                {
                    email = email.substring(MAIL_TO.length());
                }                
            }

            String realName = processField(context, REAL_NAME_FIELD);
            String organization = processField(context, ORGANIZATION_FIELD);
            String passwd = processField(context, PASSWORD_FIELD);
            String passwdConfirm = processField(context, PASSWORD_CONFIRM_FIELD);
            String multipleUsers = processField(context, MULTIPLE_USERS_TEXT_FIELD);
            String emailUsers = processField(context, EMAIL_USERS_CHECKBOX, DBFlag.ON);
d123 2
a124 1
            String action = getAction(context);
d130 1
a130 2
                AccessControlList acl = getLoginUser(context).getACL();
                Domain domain = getCurrentDomain(context);
d134 2
a135 2
                    validate(missingFields, validationErrors, loginName, 
                             email, realName, passwd, passwdConfirm);
d139 5
a143 6
                        if (addUser(acl, domain, context, realName, loginName, 
                                    passwd, email, organization, true, buf))
                        {
                            redirectToNextServletInFlow(action);
                        }
                        // addUser() adds the appropriate message on failure.
d165 1
a165 1
                        regex = new RE("([^\t ]+)[\t ]*");
d170 1
a170 1
                        Log.error("Could not initialize regular expression.", e);
d181 1
a181 1
                            if (debug) Log.debug("match 1=" + match);
d183 2
a184 2
                            if (debug) Log.debug("pos 1=" + pos);
                            loginName = match.toString(1);
d187 1
a187 1
                            if (debug) Log.debug("match 2=" + match);
d189 1
a189 1
                            if (debug) Log.debug("pos 2=" + pos);
d194 4
a197 6
                            if (debug) Log.debug("match 3=" + match);
                            if (match != null)
                            {
                                realName = match.toString(1);
                            }
                            else
d199 6
a204 6
                                // Use email user name.
                                int at = email.indexOf('@@');
                                if (at != -1)
                                {
                                    realName = email.substring(0, at);
                                }
d207 6
a212 3
                            if ( User.isValidLoginName(loginName) && 
                                 DataValidator.isValidEmail(email) && 
                                 User.isValidRealName(realName) )
d214 3
a216 6
                                // On failure, addUser() puts an appropriate 
                                // message into the context.
                                addUser(acl, domain, context,
                                        realName, loginName,
                                        passwd, email, organization, 
                                        haveValue(emailUsers), buf);
d232 1
a232 1
                        redirectToNextServletInFlow(action);
d248 1
d250 1
a250 1
            if (debug) Log.error(errMsg,e);
a256 11
     * Redirects to the next servlet in the wizard-like flow.
     *
     * @@param action HELP: Why is this passed?
     */
    protected void redirectToNextServletInFlow(String action)
        throws RedirectException
    {
        redirectTo("UserList");
    }

    /**
d258 1
a258 13
     * default user group.  Emails the user their password.  On failure, adds
     * an appropriate message to the context.
     *
     * @@param acl       The admin's ACL.
     * @@param realName  The user's real name.
     * @@param loginName The user's login name.
     * @@param passwd    The user's password.
     * @@param email     The user's email.
     * @@param org       The user's organization.
     * @@param sendEmail First of several indicators checked with regard to
     *                  whether the user should be emailed their password when 
     *                  no <code>password</code> value is specified.
     * @@return          Whether or not addition was successful
d260 5
a264 6
    private boolean addUser (AccessControlList acl, Domain domain, 
                             WebContext context,
                             String realName, String loginName, String passwd, 
                             String email, String org, 
                             boolean sendEmail, StringBuffer buf)
        throws RedirectException, TaskException
a265 1
        boolean hadPassword = haveValue(passwd);
d267 1
a267 1
        if (!hadPassword)
d274 11
a284 12
            User user = User.add(acl, domain, realName, 
                                 loginName, passwd, email, org);
            boolean emailSuppliedPasswords = "true".equals
                (myProperties.getProperty("emailSuppliedPasswords"));

            if ((!hadPassword && sendEmail) || emailSuppliedPasswords)
            {
                // Mail the password to the user.
                String subject = getSubject(buf, domain, loginName);
                new HelmEmailer().mailUserFromSystem
                    (user, subject, getMessage(buf, subject, passwd));
            }
d286 1
a286 1
        catch (org.tigris.helm.AlreadyExists e)
d289 3
a291 3
            if (debug) Log.warn(e.getMessage());
            appendToError(context, "User already exists: " + loginName);
            return false;
d295 1
d297 1
a297 1
            if (debug) Log.error(msg,e);
a299 1
        return true;
d310 2
a311 1
                                            String loginName)
d316 1
a316 1
            .append(loginName).append('\'');
d329 2
@

