head	1.13;
access;
symbols
	TIGRIS_1_1_0RC2:1.8
	TIGRIS_1_1_0RC1:1.8
	TIGRIS_1_1:1.8.0.4
	TIGRIS_1_0_8:1.8
	TIGRIS_1_0_8RC3:1.8
	TIGRIS_1_0_8RC2:1.8
	TIGRIS_1_0_8RC1:1.8
	TIGRIS_1_0_7:1.8
	TIGRIS_1_0_7RC3:1.8
	TIGRIS_1_0_7RC2:1.8
	TIGRIS_1_0_7RC1:1.8
	TIGRIS_1_0_6:1.8
	TIGRIS_1_0_6RC5:1.8
	TIGRIS_1_0_6RC4:1.8
	TIGRIS_1_0_6RC3:1.8
	TIGRIS_1_0_6RC2:1.8
	TIGRIS_1_0_6RC1:1.8
	TIGRIS_1_0_5:1.8
	TIGRIS_1_0_5RC6:1.8
	TIGRIS_1_0_5RC5:1.8
	TIGRIS_1_0_5RC4:1.8
	TIGRIS_1_0_5RC3:1.8
	TIGRIS_1_0_5RC2:1.8
	TIGRIS_1_0_5RC1:1.8
	TIGRIS_1_0_4:1.8
	TIGRIS_1_0_3:1.8
	TIGRIS_1_0_2:1.8
	TIGRIS_1_0_1:1.8
	TIGRIS_1_0:1.8.0.6
	TIGRIS_1_0_0:1.8
	TIGRIS_1_0_0_RC1:1.8.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.3
	TIGRIS_0_9_2_3:1.3
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.5
	TIGRIS_0_9_2_1:1.5
	TIGRIS_0_9_2:1.3.0.4
	TIGRIS_0_9_0:1.3.0.2
	TIGRIS_0_8_4:1.2.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


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

1.12
date	2001.07.17.17.55.45;	author leonardr;	state Exp;
branches;
next	1.11;

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

1.10
date	2001.07.05.23.19.55;	author leonardr;	state Exp;
branches;
next	1.9;

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

1.8
date	2001.03.20.16.42.58;	author leonardr;	state Exp;
branches;
next	1.7;

1.7
date	2001.03.07.01.53.20;	author lucas;	state Exp;
branches;
next	1.6;

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

1.5
date	2001.01.26.18.29.02;	author edk;	state Exp;
branches
	1.5.2.1;
next	1.4;

1.4
date	2001.01.26.05.24.06;	author edk;	state dead;
branches;
next	1.3;

1.3
date	2000.12.14.19.25.15;	author dlr;	state Exp;
branches;
next	1.2;

1.2
date	2000.11.22.17.50.41;	author leonardr;	state Exp;
branches;
next	1.1;

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

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

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

1.5.2.1
date	2001.01.28.01.02.17;	author dlr;	state dead;
branches;
next	1.5.2.2;

1.5.2.2
date	2001.02.07.02.23.55;	author leonardr;	state Exp;
branches;
next	1.5.2.3;

1.5.2.3
date	2001.02.15.20.50.35;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.13
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.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 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.util.List;

import org.apache.turbine.util.Log;
import org.apache.commons.util.exception.NestableException;
import org.apache.velocity.context.Context;

import org.tigris.helm.security.HelmServlet;
import org.tigris.helm.tool.DataValidator;
import org.tigris.helm.om.*;
import org.tigris.helm.tool.TemplateTool;
import org.tigris.helm.tool.ContextAPI;

/**
 * Base class for editting of user information.
 *
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: UserInfo.java,v 1.12 2001/07/17 17:55:45 leonardr Exp $
 */
abstract class UserInfo extends HelmServlet
{
    /**
     * The template to use when sending out password tickets to new
     * users.  
     */
    protected static final String NEW_USER_PASSWORD_TICKET_TEMPLATE =
        TemplateTool.getPathToMessageTemplate("NewUserPasswordTicket.vm");

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

    /**
     * Validates the user's information.
     */
    protected void validate (Context context, String loginName, String email, 
                             String realName, String passwd, 
                             String passwdConfirm)
    {
        // Also require loginName.
        ContextAPI.requireValue(context, loginName, "User name");
        if (ContextAPI.isValidUserInput(context))
        {
            if (!User.isValidLoginName(loginName))
            {
                ContextAPI.addValidationError(context, "Login name not valid");
            }
        }
        validate(context, email, realName, passwd, passwdConfirm);
    }

    /**
     * Validates the user's information.
     */
    protected void validate (Context context, String email, String realName, 
                             String passwd, String passwdConfirm)
    {
        // Check for required fields.
        ContextAPI.requireValue(context, email, "Email address");
        ContextAPI.requireValue(context, realName, "Real name");

        // If we have all the necessary values, validate them.
        if (ContextAPI.isValidUserInput(context))
        {
            if (!DataValidator.isValidEmail(email))
            {
                ContextAPI.addValidationError
                    (context, "Email address not valid");
            }

            if (!User.isValidRealName(realName))
            {
                ContextAPI.addValidationError(context, "Real name not valid");
            }

            if (haveValue(passwd))
            {
                if (haveValue(passwdConfirm))
                
                {
                    if (!passwd.equals(passwdConfirm))
                    {
                        ContextAPI.addValidationError
                            (context, "Password confirmation does not match.");
                    }
                }
                else
                {
                    ContextAPI.addMissingField
                        (context, "Password confirmation");
                }
            }
        }
    }
    /**
     * 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.
     */
    protected static final String getSubject(Domain domain)
    {
        return "How to set your " + domain.getName() + " password";
    }

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


1.12
log
@Porting of domain package to new error handling API.
@
text
@d53 1
a53 1
import org.apache.turbine.util.TurbineException;
d66 1
a66 1
 * @@version $Id: UserInfo.java,v 1.11 2001/07/06 16:15:46 leonardr Exp $
@


1.11
log
@Users without User - Edit must provide old password in order to change password.
@
text
@d54 1
a54 1
import org.apache.turbine.util.TurbineException;
d60 1
d66 1
a66 1
 * @@version $Id: UserInfo.java,v 1.10 2001/07/05 23:19:55 leonardr Exp $
d85 3
a87 3
    protected void validate (List missingFields, List validationErrors, 
                             String loginName, String email, String realName, 
                             String passwd, String passwdConfirm)
d90 2
a91 2
        requireValue(loginName, "User name", missingFields);
        if (isValidUserInput(missingFields, null))
d95 1
a95 1
                validationErrors.add("Login name not valid");
d98 1
a98 2
        validate(missingFields, validationErrors, email, realName, passwd, 
                 passwdConfirm);
d104 1
a104 2
    protected void validate (List missingFields, List validationErrors, 
                             String email, String realName, 
d108 2
a109 2
        requireValue(email, "Email address", missingFields);
        requireValue(realName, "Real name", missingFields);
d112 1
a112 1
        if (isValidUserInput(missingFields, null))
d116 2
a117 1
                validationErrors.add("Email not valid");
d122 1
a122 1
                validationErrors.add("Real name not valid");
d132 2
a133 2
                        validationErrors.add
                            ("Password confirmation does not match");
d138 2
a139 1
                    validationErrors.add("You must your password");
@


1.10
log
@Use the template to send email instead of making up the body in Java code.
@
text
@d65 1
a65 1
 * @@version $Id: UserInfo.java,v 1.9 2001/05/23 01:50:10 dlr Exp $
d138 1
a138 1
                    validationErrors.add("Please confirm your password");
@


1.9
log
@Ported Helm from WebMacro to Velocity.
@
text
@d59 1
d65 1
a65 1
 * @@version $Id: UserInfo.java,v 1.8 2001/03/20 16:42:58 leonardr Exp $
d69 6
a74 1

a142 1

d150 1
a150 19
    protected 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.
     */
    protected static final String getMessage (StringBuffer buf, String msgStart, 
                                            String passwd)
d152 1
a152 3
        buf.setLength(0);
        buf.append(msgStart).append(" is:\n\n").append(passwd).append('\n');
        return buf.toString();
@


1.8
log
@Refactored some code (and shamelessly copied some other code) so that Join can work as well as UserAdd.
@
text
@d53 2
d64 1
a64 1
 * @@version $Id: UserInfo.java,v 1.7 2001/03/07 01:53:20 lucas Exp $
@


1.7
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d56 2
a57 1
import org.tigris.helm.om.User;
d62 1
a62 1
 * @@version $Id: UserInfo.java,v 1.6 2001/02/21 01:08:21 dlr Exp $
d66 7
d134 45
@


1.6
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@a56 1

d61 1
a61 1
 * @@version $Id: UserInfo.java,v 1.5.2.3 2001/02/15 20:50:35 leonardr Exp $
@


1.5
log
@readding all the files as part of the process of returning to the way
things were as of tuesday
@
text
@d2 1
a2 1
 * Copyright (c) 2000 CollabNet.  All rights reserved.
d17 1
a17 1
 * software developed by CollabNet (http://www.CollabNet/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d52 1
a52 1
import org.webmacro.util.Log;
d56 1
d62 1
a62 1
 * @@version $Id: UserInfo.java,v 1.3 2000/12/14 19:25:15 dlr Exp $
a66 5
     * The log file.
     */
    private static Log log = new Log("usrInf", "UserInfo");

    /**
d70 1
a70 1
                             String userName, String email, String realName, 
d73 2
a74 2
        // Also require userName.
        requireValue(userName, "User name", missingFields);
d77 1
a77 1
            if (!User.isValidUserName(userName))
d79 1
a79 1
                validationErrors.add("User name not valid");
@


1.5.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@d61 1
a61 1
 * @@version $Id: UserInfo.java,v 1.5 2001/01/26 18:29:02 edk Exp $
@


1.5.2.2
log
@Ported UserAdd servlet.
@
text
@d17 1
a17 1
 * software developed by CollabNet (http://www.collab.net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d52 1
a52 1
import org.apache.turbine.util.Log;
a55 1
import org.tigris.helm.om.User;
d66 5
d74 1
a74 1
                             String loginName, String email, String realName, 
d77 2
a78 2
        // Also require loginName.
        requireValue(loginName, "User name", missingFields);
d81 1
a81 1
            if (!User.isValidLoginName(loginName))
d83 1
a83 1
                validationErrors.add("Login name not valid");
@


1.5.2.3
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d62 1
a62 1
 * @@version $Id: UserInfo.java,v 1.5.2.2 2001/02/07 02:23:55 leonardr Exp $
@


1.4
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.3
log
@Migrated data validation logic into User business object.
@
text
@d61 1
a61 1
 * @@version $Id: UserInfo.java,v 1.2 2000/11/22 17:50:41 leonardr Exp $
@


1.2
log
@Allow apostrophes in user real names
@
text
@a53 3
import gnu.regexp.RE;
import gnu.regexp.REException;

d55 1
d61 1
a61 1
 * @@version $Id: UserInfo.java,v 1.1.1.1 2000/11/12 21:15:44 dlr Exp $
a65 15
     * The regular expression used to validate user names.
     */
    protected static RE userNameRE = null;

    /**
     * The regular expression used to validate email addresses.
     */
    protected static RE emailRE = null;

    /**
     * The regular expression used to validate real names.
     */
    protected static RE realNameRE = null;

    /**
a69 16
    public void start() throws javax.servlet.ServletException
    {
        super.start();
        try
        {
            // HELP: Are these things thread safe?
            userNameRE = new RE("^[\\w]{1,16}$");
            emailRE = new RE("^[\\w\\-\\._=\\!#\\*\\+]+@@([\\w\\-]+\\.)+[a-zA-Z]{2,3}$");
            realNameRE = new RE("^[\\w' \\-\\.\\,]+$");
        }
        catch (REException e)
        {
            log.exception(e);
        }
    }

d81 1
a81 1
            if (!userNameRE.isMatch(userName))
d104 1
a104 1
            if (!emailRE.isMatch(email))
d109 1
a109 1
            if (!realNameRE.isMatch(realName))
@


1.1
log
@Initial revision
@
text
@d63 1
a63 1
 * @@version $Id: UserInfo.java,v 1.7 2000/11/11 06:18:31 dlr Exp $
d95 1
a95 1
            realNameRE = new RE("^[\\w \\-\\.\\,]+$");
@


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.
d17 1
a17 1
 * software developed by CollabNet (http://www.collab.net/)."
d32 1
a32 1
 * IN NO EVENT SHALL COLLABNET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d52 4
a55 1
import org.apache.turbine.util.Log;
a57 2
import org.tigris.helm.tool.DataValidator;
import org.tigris.helm.om.User;
d63 1
a63 1
 * @@version $Id: UserInfo.java,v 1.5.2.3 2001/02/15 20:50:35 leonardr Exp $
d68 36
d107 1
a107 1
                             String loginName, String email, String realName, 
d110 2
a111 2
        // Also require loginName.
        requireValue(loginName, "User name", missingFields);
d114 1
a114 1
            if (!User.isValidLoginName(loginName))
d116 1
a116 1
                validationErrors.add("Login name not valid");
d137 1
a137 1
            if (!DataValidator.isValidEmail(email))
d142 1
a142 1
            if (!User.isValidRealName(realName))
@

