head	1.49;
access;
symbols
	TIGRIS_1_1_0RC2:1.34
	TIGRIS_1_1_0RC1:1.34
	TIGRIS_1_1:1.34.0.4
	TIGRIS_1_0_8:1.34
	TIGRIS_1_0_8RC3:1.34
	TIGRIS_1_0_8RC2:1.34
	TIGRIS_1_0_8RC1:1.34
	TIGRIS_1_0_7:1.34
	TIGRIS_1_0_7RC3:1.34
	TIGRIS_1_0_7RC2:1.34
	TIGRIS_1_0_7RC1:1.34
	TIGRIS_1_0_6:1.34
	TIGRIS_1_0_6RC5:1.34
	TIGRIS_1_0_6RC4:1.34
	TIGRIS_1_0_6RC3:1.34
	TIGRIS_1_0_6RC2:1.34
	TIGRIS_1_0_6RC1:1.34
	TIGRIS_1_0_5:1.34
	TIGRIS_1_0_5RC6:1.34
	TIGRIS_1_0_5RC5:1.34
	TIGRIS_1_0_5RC4:1.34
	TIGRIS_1_0_5RC3:1.34
	TIGRIS_1_0_5RC2:1.34
	TIGRIS_1_0_5RC1:1.34
	TIGRIS_1_0_4:1.34
	TIGRIS_1_0_3:1.34
	TIGRIS_1_0_2:1.34
	TIGRIS_1_0_1:1.34
	TIGRIS_1_0:1.34.0.6
	TIGRIS_1_0_0:1.34
	TIGRIS_1_0_0_RC1:1.34.0.2
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.19
	TIGRIS_0_9_2_3:1.19
	HELM_PEER_PORT_BRANCH:1.1.1.2
	TURBINE_PEER:1.21
	TIGRIS_0_9_2_1:1.21
	TIGRIS_0_9_2:1.19.0.2
	TIGRIS_0_9_0:1.13.0.2
	TIGRIS_0_8_4:1.7.0.2
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1;
locks; strict;
comment	@# @;


1.49
date	2001.08.28.17.45.17;	author leonardr;	state Exp;
branches;
next	1.48;

1.48
date	2001.08.11.09.08.01;	author dlr;	state Exp;
branches;
next	1.47;

1.47
date	2001.08.06.21.29.10;	author dlr;	state Exp;
branches;
next	1.46;

1.46
date	2001.07.24.00.02.27;	author leonardr;	state Exp;
branches;
next	1.45;

1.45
date	2001.07.19.18.42.22;	author dlr;	state Exp;
branches;
next	1.44;

1.44
date	2001.07.18.10.05.12;	author dlr;	state Exp;
branches;
next	1.43;

1.43
date	2001.06.18.22.12.20;	author leonardr;	state Exp;
branches;
next	1.42;

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

1.41
date	2001.05.25.00.05.14;	author dlr;	state Exp;
branches;
next	1.40;

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

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

1.38
date	2001.05.23.01.36.27;	author leonardr;	state Exp;
branches;
next	1.37;

1.37
date	2001.05.22.00.15.52;	author elicia;	state Exp;
branches;
next	1.36;

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

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

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

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

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

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

1.30
date	2001.03.07.01.53.20;	author lucas;	state Exp;
branches;
next	1.29;

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

1.28
date	2001.02.24.03.51.35;	author dlr;	state Exp;
branches;
next	1.27;

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

1.26
date	2001.02.23.22.01.55;	author leonardr;	state Exp;
branches;
next	1.25;

1.25
date	2001.02.23.19.09.50;	author leonardr;	state Exp;
branches;
next	1.24;

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

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

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

1.21
date	2001.01.26.18.29.02;	author edk;	state Exp;
branches
	1.21.2.1;
next	1.20;

1.20
date	2001.01.26.05.24.06;	author edk;	state dead;
branches;
next	1.19;

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

1.18
date	2001.01.12.07.47.44;	author jrobbins;	state Exp;
branches;
next	1.17;

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

1.16
date	2001.01.08.23.25.02;	author dlr;	state Exp;
branches;
next	1.15;

1.15
date	2001.01.05.01.10.56;	author dlr;	state Exp;
branches;
next	1.14;

1.14
date	2001.01.04.01.10.25;	author dlr;	state Exp;
branches;
next	1.13;

1.13
date	2000.12.20.08.05.21;	author dlr;	state Exp;
branches
	1.13.2.1;
next	1.12;

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

1.11
date	2000.12.06.20.11.32;	author dlr;	state Exp;
branches;
next	1.10;

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

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

1.8
date	2000.12.06.19.29.17;	author dlr;	state Exp;
branches;
next	1.7;

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

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

1.5
date	2000.12.01.10.30.35;	author dlr;	state Exp;
branches;
next	1.4;

1.4
date	2000.11.29.00.34.53;	author dlr;	state Exp;
branches;
next	1.3;

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

1.2
date	2000.11.29.00.28.46;	author dlr;	state Exp;
branches;
next	1.1;

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

1.1.1.1
date	2000.11.12.21.15.37;	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.13.2.1
date	2001.01.12.03.27.15;	author jrobbins;	state Exp;
branches;
next	1.13.2.2;

1.13.2.2
date	2001.01.12.07.52.31;	author jrobbins;	state Exp;
branches;
next	1.13.2.3;

1.13.2.3
date	2001.01.12.08.00.07;	author jrobbins;	state Exp;
branches;
next	;

1.21.2.1
date	2001.01.28.01.02.17;	author dlr;	state dead;
branches;
next	1.21.2.2;

1.21.2.2
date	2001.02.01.01.42.33;	author dlr;	state Exp;
branches;
next	1.21.2.3;

1.21.2.3
date	2001.02.01.01.44.45;	author dlr;	state Exp;
branches;
next	1.21.2.4;

1.21.2.4
date	2001.02.01.14.42.44;	author leonardr;	state Exp;
branches;
next	1.21.2.5;

1.21.2.5
date	2001.02.01.16.32.23;	author leonardr;	state Exp;
branches;
next	1.21.2.6;

1.21.2.6
date	2001.02.01.18.14.58;	author dlr;	state Exp;
branches;
next	1.21.2.7;

1.21.2.7
date	2001.02.02.17.59.01;	author dlr;	state Exp;
branches;
next	1.21.2.8;

1.21.2.8
date	2001.02.08.00.29.13;	author dlr;	state Exp;
branches;
next	1.21.2.9;

1.21.2.9
date	2001.02.08.00.43.22;	author dlr;	state Exp;
branches;
next	1.21.2.10;

1.21.2.10
date	2001.02.08.00.54.47;	author dlr;	state Exp;
branches;
next	1.21.2.11;

1.21.2.11
date	2001.02.09.03.05.40;	author dlr;	state Exp;
branches;
next	1.21.2.12;

1.21.2.12
date	2001.02.14.23.20.28;	author leonardr;	state Exp;
branches;
next	1.21.2.13;

1.21.2.13
date	2001.02.15.20.50.35;	author leonardr;	state Exp;
branches;
next	1.21.2.14;

1.21.2.14
date	2001.02.16.03.01.26;	author dlr;	state Exp;
branches;
next	;


desc
@@


1.49
log
@More methods migrated to ContextAPI.
@
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.io.*;
import java.util.*;
import java.sql.*;

import javax.servlet.http.HttpSession;

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

import org.apache.fulcrum.velocity.TurbineVelocity;

import org.apache.velocity.context.Context;

import org.tigris.helm.tool.SessionManager;
import org.tigris.helm.security.RedirectException;

import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.*;
import org.tigris.helm.tool.HelmProperties;
import org.tigris.helm.tool.TemplateTool;
import org.tigris.helm.tool.ContextAPI;
import org.tigris.helm.security.BaseHelmServlet;

/**
 * Display and process the Tigris login screen.
 *
 * @@author <a href="mailto:jrobbins@@collab.net">Jason Robbins</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: TLogin.java,v 1.48 2001/08/11 09:08:01 dlr Exp $
 */
public class TLogin extends BaseHelmServlet
{
    private static final String LOGIN = "Login";

    private static final String NEW_PASSWD = "New Password";

    private static final String PASSWORD_TICKET_EMAIL_SUBJECT =
        "How to change your password";

    private static final String PASSWORD_TICKET_TEMPLATE =
        TemplateTool.getPathToMessageTemplate("PasswordTicket.vm");

    /**
     *  Display and process the Tigris login screen.
     */
    protected String processRequest(Context ctx)
        throws NestableException, RedirectException
    {
        String templateName = super.processRequest(ctx);

        SessionManager sMgr = getSessionManager(ctx);

        // Get loginID and password from the screen
        String loginID = ContextAPI.getParameter(ctx, "loginID");
        String password = ContextAPI.getParameter(ctx, "password");
        String action = getAction(ctx);

        try
        {
            if (sMgr.isLoggedIn().booleanValue() &&
                !sMgr.getUserID().equals(UserPeer.getAnonymousUser().getID()))
            {
                // Indicate which user the client is already logged in.
                ctx.put("loginID", sMgr.getLoginID());
            }

            // HACK: We need currentDomain, but do not sub class
            // HelmServlet.  Thus, we sin.
            String domainName = HelmProperties.getProperty("domain");
            Domain currentDomain = ProjectPeer.getDomain(domainName);
            ctx.put("currentDomain", currentDomain);

            if (action.equals(NEW_PASSWD))
            {
                if (haveValue(loginID))
                {
                    // Send a ticket redeemable for password editting.
                    try 
                    {
                        User user = UserPeer.getInstanceByIdentifier
                            (currentDomain, loginID);
                        user.sendNewPasswordTicket
                            (ctx, PASSWORD_TICKET_EMAIL_SUBJECT, 
                             PASSWORD_TICKET_TEMPLATE);
                        ContextAPI.addMessage
                            (ctx, "The URL to set a new password has " +
                             "been e-mailed to you");
                    }
                    catch (Exception e)
                    {
                        // Login failed.  Bail out now and redisplay the login
                        // page.
                        ContextAPI.addError
                            (ctx, "Email of password ticket URL " +
                             "failed: " + e.getMessage());
                    }
                }
                else
                {
                    ContextAPI.addError
                        (ctx, "Your login name or email address " +
                         "is required for a new password");
                }
            }

            if (action != null && action.equals(LOGIN))
            {
                sMgr.getSession().putValue("acl", "force new acl");

                if (!haveValue(loginID) || !haveValue(password))
                {
                    ContextAPI.addError
                        (ctx, "Please enter a Login Name or " +
                         "Email Address, and a Password");
                    return templateName;
                }

                // Check if the login name - password is valid, and cache
                // login info in the session.
                try
                {
                    User u = UserPeer.assertValidLogin(currentDomain, loginID,
                                                       password);
                    sMgr.init(u);
                }
                catch (NestableException invalidLogin)
                {
                    // Login failed.  Bail out now and redisplay the login
                    // page.
                    ContextAPI.addError(ctx, "Login Failed");
                    return templateName;
                }

                // Redirect to the target page or the Start Page for this User
                redirectToDetour(ctx);
            }
        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            String msg = "Login error: " + e.getMessage();
            Log.error(msg, e);
            throw new NestableException(e);
        }

        return templateName;
    }

    /**
     * Redirect to the detoured page.  But dont do to startservlet,
     * always go to HomePage.
     *
     * @@param	context    the Context partially populated by WMServlet
     * @@exception	HandlerException
     * @@exception	RedirectException
     */
    protected void redirectToDetour(Context context)
        throws NestableException, RedirectException
    {
        SessionManager sMgr = getSessionManager(context);
        String detourPage = sMgr.redirectToDetour(context);

        if (detourPage != null)
        {
            redirectTo(detourPage);
        }
        else
        {
            context.put(ACTION_KEY, "none");

            // if (((Boolean) context.get("isLoggedIn")).booleanValue())
            // redirectTo(myProperties.getProperty("startServletName"));
            // else
            redirectToHomePage(context);
        }
    }
}
@


1.48
log
@Upgrading to Turbine 3.0-dev, Fulcrum 1.0, and Torque 1.0.
@
text
@d79 1
a79 1
 * @@version $Id: TLogin.java,v 1.47 2001/08/06 21:29:10 dlr Exp $
d104 2
a105 2
        String loginID = getParameter(ctx, "loginID");
        String password = getParameter(ctx, "password");
@


1.47
log
@Added an init() method to the SessionManager class; made use of it in two places.
@
text
@d57 2
a58 2
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.services.TurbineServices;
d60 1
a60 1
import org.apache.turbine.services.velocity.TurbineVelocity;
d79 1
a79 1
 * @@version $Id: TLogin.java,v 1.46 2001/07/24 00:02:27 leonardr Exp $
d97 1
a97 1
        throws TurbineException, RedirectException
d176 1
a176 1
                catch (TurbineException invalidLogin)
d196 1
a196 1
            throw new TurbineException(e);
d211 1
a211 1
        throws TurbineException, RedirectException
@


1.46
log
@The final pieces of the error handling revolution.
@
text
@d79 1
a79 1
 * @@version $Id: TLogin.java,v 1.45 2001/07/19 18:42:22 dlr Exp $
d174 1
a174 5
                    sMgr.isLoggedIn(true);
                    sMgr.setUserID(u.getID());
                    sMgr.setLoginID(u.getLoginName());
                    sMgr.setEmail(u.getEmail());
                    sMgr.setUserName(u.getRealName());
@


1.45
log
@Updated in light of the port of Joist JoistProperties class to Helm (as class HelmProperties).
@
text
@d58 2
d71 1
d79 1
a79 1
 * @@version $Id: TLogin.java,v 1.44 2001/07/18 10:05:12 dlr Exp $
d135 3
a137 3
                        appendToMessage(ctx, 
                                        "The URL to set a new password has " +
                                        "been e-mailed to you");
d143 3
a145 2
                        appendToMessage(ctx, "Email of password ticket URL " +
                                        "failed: " + e.getMessage());
d150 3
a152 2
                    appendToError(ctx, "Your login name or email address " +
                                  "is required for a new password");
d162 3
a164 2
                    appendToMessage(ctx, "Please enter a Login Name or " +
                                    "Email Address, and a Password");
d184 1
a184 1
                    appendToMessage(ctx, "Login Failed");
@


1.44
log
@Ported Joist Redirect*Exception to Helm.
@
text
@a57 3
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.util.TurbineException;
import org.apache.turbine.services.TurbineServices;
a60 1
import org.apache.velocity.context.Context;
a61 1
import org.joist.util.*;
d67 1
d76 1
a76 1
 * @@version $Id: TLogin.java,v 1.43 2001/06/18 22:12:20 leonardr Exp $
d116 1
a116 1
            String domainName = JoistProperties.getProperty("domain");
@


1.43
log
@Huge patch of the day: Got rid of redundant HELM_DOMAIN table. The project representation of the domain and the host is now the canonical one. Host and Domain now subclass ProjectGroup. The canonical representation of a project's membership in a domain group is now the corresponding mapping in HELM_PROJECT_PROJECTGROUP. Schema changes: No more HELM_DOMAIN table (obviously); no more DOMAIN_ID in HELM_PROJECT; HELM_USER and HELM_VC_VIEW now have foreign keys in HELM_PROJECT instead of HELM_DOMAIN.
@
text
@d68 1
a68 1
import org.joist.security.RedirectException;
d80 1
a80 1
 * @@version $Id: TLogin.java,v 1.42 2001/05/25 16:57:15 leonardr Exp $
@


1.42
log
@.wm is now .vm
@
text
@d80 1
a80 1
 * @@version $Id: TLogin.java,v 1.41 2001/05/25 00:05:14 dlr Exp $
d121 1
a121 1
            Domain currentDomain = DomainPeer.getInstanceByName(domainName);
@


1.41
log
@Formatted method.
@
text
@d80 1
a80 1
 * @@version $Id: TLogin.java,v 1.40 2001/05/24 23:06:06 dlr Exp $
d92 1
a92 1
        TemplateTool.getPathToMessageTemplate("PasswordTicket.wm");
@


1.40
log
@Improved error message.
@
text
@d80 1
a80 1
 * @@version $Id: TLogin.java,v 1.39 2001/05/23 01:50:10 dlr Exp $
d213 1
a213 1
	throws TurbineException, RedirectException
d215 2
a216 2
	SessionManager sMgr = getSessionManager(context);
	String detourPage = sMgr.redirectToDetour(context);
d218 7
a224 7
	if (detourPage != null)
	{
	    redirectTo(detourPage);
	}
	else
	{
	    context.put(ACTION_KEY, "none");
d226 1
a226 1
	    // if (((Boolean) context.get("isLoggedIn")).booleanValue())
d228 1
a228 1
	    // else
d230 1
a230 1
	}
@


1.39
log
@Ported Helm from WebMacro to Velocity.
@
text
@d80 1
a80 1
 * @@version $Id: TLogin.java,v 1.38 2001/05/23 01:36:27 leonardr Exp $
d144 2
a145 1
                        appendToMessage(ctx, "Send Failed: " + e.getMessage());
d150 2
a151 2
                    appendToMessage(ctx, "Your login name or email address " +
                                    "is required for a new password");
@


1.38
log
@Put currentDomain into the context.
@
text
@d58 2
d61 1
a61 1
import org.apache.turbine.services.webmacro.TurbineWebMacro;
d63 2
a64 2
import org.webmacro.servlet.*;
import org.webmacro.servlet.WebContext;
d67 1
a67 1
import org.joist.session.*;
d80 1
a80 1
 * @@version $Id: TLogin.java,v 1.37 2001/05/22 00:15:52 elicia Exp $
d97 2
a98 2
    protected String processRequest (Connection conn, WebContext ctx)
        throws HandlerException, RedirectException
d100 1
a100 1
        String templateName = super.processRequest(conn, ctx);
d105 2
a106 2
        String loginID = ctx.getForm("loginID");
        String password = ctx.getForm("password");
d197 1
a197 1
            throw new HandlerException(msg);
d207 1
a207 1
     * @@param	context    the WebContext partially populated by WMServlet
d211 2
a212 2
    protected void redirectToDetour(WebContext context)
	throws HandlerException, RedirectException
@


1.37
log
@removed import of old SessionManager
@
text
@d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.36 2001/04/17 00:19:39 leonardr Exp $
d120 1
@


1.36
log
@Moved from Message, the last of the Joist tables, to HELM_MESSAGE. A few minor problems with Joist servlets remain.
@
text
@d70 1
a71 1
import org.tigris.helm.tool.*;
d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.35 2001/04/11 17:42:11 leonardr Exp $
@


1.35
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
@a65 1
import org.joist.security.UnsecureServlet;
d69 2
a70 1
import org.tigris.helm.om.*;import org.tigris.helm.om.*;
d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.34 2001/03/23 18:52:47 leonardr Exp $
d80 1
a80 1
public class TLogin extends UnsecureServlet 
@


1.34
log
@Some fixes for the whole ProjectMembershipRequest/Join/Login/Invitation Rube Goldberg.
@
text
@d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.33 2001/03/23 04:04:28 leonardr Exp $
d128 5
a132 1
                        sendPasswordTicket(ctx, currentDomain, loginID);
a226 27
    }

    /**
     * Sends a email with a URL containing a ticket used to validate a change
     * of password for the user.  Using this ticket and having the user come to
     * the site to change their password prevents a DOS attack against the user
     * that would be possible if we just changed the password and emailed it
     * directly instead.
     */
    private void sendPasswordTicket (WebContext context, Domain domain,
                                     String loginOrEmail)
        throws DoesNotExist, Exception
    {
        User user = UserPeer.getInstanceByIdentifier(domain, loginOrEmail);
        String ticket = user.newPasswordTicket();

        String url = URL.schemeAndServer(context) + "/servlets/PasswordEdit";
        url = URL.appendCGIParam(url, "userID", user.getID());
        url = URL.appendCGIParam(url, "ticket", ticket);
        
        WebContext ctx = TurbineWebMacro.getContext();
        ctx.put("user", user);
        ctx.put("url", url);
        String body = TurbineWebMacro.handleRequest(ctx,
                                                    PASSWORD_TICKET_TEMPLATE);
        new HelmEmailer().mailUserFromSystem
            (user, PASSWORD_TICKET_EMAIL_SUBJECT, body);
@


1.33
log
@Moved method into here.
@
text
@d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.32 2001/03/08 01:02:30 dlr Exp $
a177 3
                redirectOnTicket(ctx.getRequest().getSession(true), 
                                 "ticket", "ProjectMembershipRequest");

a193 29
    }

    /**
     * See if the session contains a ticket.  If so, redirect the user
     * to the specified servlet. This should be called in servlets
     * like Join and TLogin after they do their processing.  
     */
    public void redirectOnTicket(HttpSession session, 
                                 String ticketFieldName,
                                 String servlet)
        throws RedirectException, Exception
    {
        if (haveValue(ticketFieldName))
        {
            String ticket = (String)session.getValue(ticketFieldName);
            Invitation invite = null;
            try 
            {
                invite = InvitationPeer.getInstance(ticket);
            } 
            catch (DoesNotExist ignore) 
            {                
            }
            if (invite != null)
            {
                Project project = invite.getProject();            
                throw new RedirectException(project.getProjectPageURL(servlet));
            }
        }
@


1.32
log
@More consistant with coding conventions used in the rest of the
source.
@
text
@d54 2
d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.31 2001/03/08 00:53:27 leonardr Exp $
d178 3
d197 29
@


1.31
log
@Show an error sending the new password URL on the same screen, not a different screen.
@
text
@d76 1
a76 1
 * @@version $Id: TLogin.java,v 1.30 2001/03/07 01:53:20 lucas Exp $
d84 2
a85 2
    private static final String PASSWORD_TICKET_EMAIL_SUBJECT 
        = "How to change your password";
@


1.30
log
@Corrected regex madness for Torque upgrade.  -dlr
@
text
@d76 1
a76 1
 * @@version $Id: TLogin.java,v 1.29 2001/02/24 11:43:00 dlr Exp $
a103 1
        Log.debug("action=" + action);
d124 13
a136 3
                    sendPasswordTicket(ctx, currentDomain, loginID);
                    appendToMessage(ctx, "The URL to set a new password has " +
                                    "been e-mailed to you");
a139 1
                    Log.debug("Missing loginID");
a146 1
                Log.debug("clearing out acl");
a209 1
	    Log.debug("redirectToDetour: " + detourPage);
a213 2
	    Log.debug("redirectToDetour: setting action=none; " +
                      "isLoggedIn: " + context.get("isLoggedIn"));
@


1.29
log
@Make use of the TurbineWebMacro facade of WebMacroService for a more convienient interface.
@
text
@d68 1
a68 3
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
import org.tigris.helm.om.*;
d76 1
a76 1
 * @@version $Id: TLogin.java,v 1.28 2001/02/24 03:51:35 dlr Exp $
@


1.28
log
@More informative exception handling.
@
text
@d57 1
a57 1
import org.apache.turbine.services.webmacro.WebMacroService;
d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.27 2001/02/24 01:17:24 leonardr Exp $
d239 1
a239 3
        WebMacroService wmSrvc = (WebMacroService)
            TurbineServices.getInstance().getService(WebMacroService.SERVICE_NAME);
        WebContext ctx = wmSrvc.getContext();
d242 2
a243 1
        String body = wmSrvc.handleRequest(ctx, PASSWORD_TICKET_TEMPLATE);
@


1.27
log
@Failure message on invalid username should be the same as failure message on invalid password.
@
text
@d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.26 2001/02/23 22:01:55 leonardr Exp $
d181 3
a183 2
            Log.error(e);
            throw new HandlerException(e.getMessage());
@


1.26
log
@Assignments are fun.
@
text
@d32 1
a32 1
 * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.25 2001/02/23 19:09:50 leonardr Exp $
@


1.25
log
@Get users using all avaliable methods.
@
text
@d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.24 2001/02/22 01:17:52 dlr Exp $
d232 1
a232 2
        String ticket = ""; 
        user.newPasswordTicket();
@


1.24
log
@Find the template in the right place.
@
text
@d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.23 2001/02/22 00:38:46 dlr Exp $
d147 1
a147 1
                                    "Email Address and a Password");
d155 2
a156 4
                    UserPeer.assertValidLogin(currentDomain, loginID,
                                              password);
                    User u = UserPeer.getInstanceByLoginName(currentDomain,
                                                             loginID);
d231 1
a231 3
        User user = (loginOrEmail.indexOf('@@') == -1 ?
                     UserPeer.getInstanceByLoginName(domain, loginOrEmail) :
                     UserPeer.getInstanceByEmail(domain, loginOrEmail));
@


1.23
log
@Now using TurbineWebMacroService instead of TemplateInterpolator.
@
text
@d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.22 2001/02/21 01:08:21 dlr Exp $
d88 3
a90 1
    private static final String PASSWORD_TICKET_TEMPLATE = "PasswordTicket.wm";
@


1.22
log
@This is the highest revision from the HELM_PEER_PORT_BRANCH.  The previous import caused too many conflicts to resolve manually
@
text
@d56 2
d60 1
a60 1
import org.webmacro.engine.BuildContext;
d78 1
a78 1
 * @@version $Id: TLogin.java,v 1.21.2.14 2001/02/16 03:01:26 dlr Exp $
d196 1
a196 2
        protected void
    redirectToDetour (WebContext context)
d241 3
a243 1
        BuildContext ctx = TemplateInterpolator.createContext();
d246 1
a246 2
        String body = TemplateInterpolator.interpolate
            (PASSWORD_TICKET_TEMPLATE, ctx, getClass());        
@


1.21
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.
d54 3
a56 1
import org.webmacro.util.Log;
d58 1
a59 3
import com.workingdogs.village.DataSetException;

import org.joist.*;
a60 3
import org.joist.mail.Emailer;
import org.joist.database.DataManager;
import org.joist.database.JoistDatabaseException;
d66 4
d72 1
a72 8
 * Display and process the login screen.
 *  - Get loginID and password from the screen
 *  - Use both the Name and Password to select from the User table
 *  - If no match, redisplay the Login screen with a "Login Failed" message
 *  - If a record is found:
 *    - Look up the Roles and Permissions for this User
 *    - Cache Permissions for this User
 *    - Redirect to the Start Page for this User
d74 3
d84 3
a86 8
    private static final String PASSWD_EMAIL_SUBJ = "Your new password";

    private static final String PASSWD_TICKET_MSG = 
        "Visit the URL below to set a new password:\n";

    private static Log log = new Log("tlogin", "TLogin");

    private static final boolean debug = true;
d89 1
a89 1
     *  Display and process the tlogin screen.
d102 1
a102 1
        if (debug) log.info("action=" + action);
d107 1
a107 1
                !sMgr.getUserID().equals(User.getGuest().getID()))
d113 5
d120 1
a120 1
                if (!haveValue(loginID))
d122 4
a125 4
                    if (debug) log.warning("Missing loginID");
                    appendToMessage(ctx, "Your login name or email address " +
                                    "is required for a new password");
                        
d129 3
a131 12
                    // Send a ticket redeemable for password editting.
                    // HACK: We need currentDomain, but do not sub class
                    // HelmServlet.  Thus, we sin.
                    DataManager dMgr = getDataManager(ctx);
                    String domainName =
                        JoistProperties.getInstance().getProperty("domain");
                    Domain currentDomain = new Domain(conn, domainName, dMgr);
                    //String domainID = getCurrentDomain(ctx).getID();
                    String domainID = currentDomain.getID();
                    sendPasswordTicket(conn, ctx, dMgr, domainID, loginID);
                    appendToMessage(ctx, "The URL to set a new password has " + 
                                    "been e-mailed to you");
d137 1
a137 1
                if (debug) log.info("clearing out acl");
d149 13
a161 1
                if (!sMgr.loginIsValid(conn, ctx, loginID, password))
a168 4
                // Look up the Roles and Permissions for this User and
                // cache them in the session.
                sMgr.getPermissions(conn, ctx);

d179 2
a180 3
            String errMsg = e.getMessage();
            if (debug) log.warning(errMsg);
            throw new HandlerException(errMsg);
d203 1
a203 1
	    if (debug) log.info("redirectToDetour: " + detourPage);
d208 2
a209 2
	    if (debug) log.info("redirectToDetour: setting action=none; " +
                    "isLoggedIn: " + context.get("isLoggedIn"));
a218 2


d226 1
a226 2
    private void sendPasswordTicket (Connection conn, WebContext ctx,
                                     DataManager dMgr, String domainID,
d228 1
a228 2
        throws DataSetException, SQLException, DoesNotExist,
               JoistException, JoistDatabaseException
d231 6
a236 4
                     new User(conn, dMgr, domainID, loginOrEmail) :
                     new User(conn, loginOrEmail, dMgr, domainID));
        String ticket = user.newPasswordTicket();
        String url = URL.schemeAndServer(ctx) + "/servlets/PasswordEdit";
d239 8
a246 2
        new Emailer().sendEmail(user.getEmail(), PASSWD_EMAIL_SUBJ,
                                PASSWD_TICKET_MSG + url);
@


1.21.2.1
log
@Porting to the Turbine Peer system.  -dlr and leonardr
@
text
@@


1.21.2.2
log
@Display and process the Tigris login screen.
@
text
@d54 2
a55 1
import org.apache.turbine.util.Log;
d57 1
a57 1
import org.webmacro.servlet.*;
a67 2
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.*;
d71 8
a78 1
 * Display and process the Tigris login screen.
a79 3
 * @@author <a href="mailto:jrobbins@@collab.net">Jason Robbins</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: $
d92 4
d110 1
a110 1
        Log.debug("action=" + action);
d115 1
a115 1
                !sMgr.getUserID().equals(UserPeer.getGuestUser().getID()))
d125 1
a125 1
                    Log.warn("Missing loginID");
d138 5
a142 4
                    Domain currentDomain =
                        DomainPeer.getInstanceByName(domainName);
                    sendPasswordTicket(ctx, currentDomain, loginID);
                    appendToMessage(ctx, "The URL to set a new password has " +
d149 1
a149 1
                Log.debug("clearing out acl");
d183 3
a185 2
            Log.error(e);
            throw new HandlerException(e.getMessage());
d208 1
a208 1
	    Log.debug("redirectToDetour: " + detourPage);
d213 2
a214 2
	    Log.debug("redirectToDetour: setting action=none; " +
                      "isLoggedIn: " + context.get("isLoggedIn"));
d233 2
a234 1
    private void sendPasswordTicket (WebContext ctx, Domain domain,
d236 2
a237 1
        throws DoesNotExist, Exception
d240 2
a241 2
                     UserPeer.getInstanceByLoginName(domain, loginOrEmail) :
                     UserPeer.getInstanceByEmail(domain, loginOrEmail));
@


1.21.2.3
log
@Switched order to non-negative logic (heh) and changed logging to
debug.
@
text
@d76 1
a76 1
 * @@version $Id: TLogin.java,v 1.21.2.2 2001/02/01 01:42:33 dlr Exp $
d116 8
a123 1
                if (haveValue(loginID))
a135 6
                }
                else
                {
                    Log.debug("Missing loginID");
                    appendToMessage(ctx, "Your login name or email address " +
                                    "is required for a new password");
@


1.21.2.4
log
@Fixed build errors.
@
text
@d76 1
a76 1
 * @@version $Id: TLogin.java,v 1.21.2.3 2001/02/01 01:44:45 dlr Exp $
d230 1
a230 3
        String ticket = ""; 
        //FIXME: No such method.
        //user.newPasswordTicket();
@


1.21.2.5
log
@Got rid of unneccessary Joist stuff.
@
text
@d76 1
a76 1
 * @@version $Id: TLogin.java,v 1.21.2.4 2001/02/01 14:42:44 leonardr Exp $
d159 4
@


1.21.2.6
log
@Had forgotten to check the ported version of this method in.  It's in
CVS now, so this code can be live again.
@
text
@d76 1
a76 1
 * @@version $Id: TLogin.java,v 1.21.2.5 2001/02/01 16:32:23 leonardr Exp $
d227 2
a228 1
        user.newPasswordTicket();
@


1.21.2.7
log
@Cleanup.
@
text
@d76 1
a76 1
 * @@version $Id: TLogin.java,v 1.21.2.6 2001/02/01 18:14:58 dlr Exp $
d90 1
a90 1
     *  Display and process the Tigris login screen.
d122 2
a123 1
                    String domainName = JoistProperties.getProperty("domain");
d209 2
@


1.21.2.8
log
@Hacked in a way to not call SessionManager.loginIsValid(), which
references Joist tables that we no longer wish to include in the Helm
schema in their Joist incarnation.
@
text
@d76 1
a76 1
 * @@version $Id: TLogin.java,v 1.21.2.7 2001/02/02 17:59:01 dlr Exp $
a113 5
            // HACK: We need currentDomain, but do not sub class
            // HelmServlet.  Thus, we sin.
            String domainName = JoistProperties.getProperty("domain");
            Domain currentDomain = DomainPeer.getInstanceByName(domainName);

d119 6
d151 1
a151 13
                try
                {
                    UserPeer.assertValidLogin(currentDomain, loginID,
                                              password);
                    User u = UserPeer.getInstanceByLoginName(currentDomain,
                                                             loginID);
                    sMgr.isLoggedIn(true);
                    sMgr.setUserID(u.getID());
                    sMgr.setLoginID(u.getLoginName());
                    sMgr.setEmail(u.getEmail());
                    sMgr.setUserName(u.getRealName());
                }
                catch (Exception invalidLogin)
@


1.21.2.9
log
@Catch the exception thrown by TurbineException.
@
text
@d76 1
a76 1
 * @@version $Id: TLogin.java,v 1.21.2.8 2001/02/08 00:29:13 dlr Exp $
d162 1
a162 1
                catch (TurbineException invalidLogin)
@


1.21.2.10
log
@Actually import TurbineException.
@
text
@a54 1
import org.apache.turbine.util.TurbineException;
d76 1
a76 1
 * @@version $Id: TLogin.java,v 1.21.2.9 2001/02/08 00:43:22 dlr Exp $
@


1.21.2.11
log
@Concept of the "guest" user renamed to "anonymous".
@
text
@d77 1
a77 1
 * @@version $Id: TLogin.java,v 1.21.2.10 2001/02/08 00:54:47 dlr Exp $
d109 1
a109 1
                !sMgr.getUserID().equals(UserPeer.getAnonymousUser().getID()))
@


1.21.2.12
log
@Big wide-ranging patch being committed all at once due to network downness. Features of this patch include: lots of added and updated JavaDoc, conversion of emails to use TemplateInterpolator and HelmEmailer, rearrangement of methods, changing code that gets mappings and loops over them to code that just gets the appropriate objects from the peer using AddJoin.
@
text
@a57 1
import org.webmacro.engine.BuildContext;
d59 1
d61 3
a67 1
import org.tigris.helm.DoesNotExist;
d70 1
a70 1
import org.tigris.helm.tool.*;
d77 1
a77 1
 * @@version $Id: TLogin.java,v 1.21.2.11 2001/02/09 03:05:40 dlr Exp $
d85 4
a88 3
    private static final String PASSWORD_TICKET_EMAIL_SUBJECT 
        = "How to change your password";
    private static final String PASSWORD_TICKET_TEMPLATE = "PasswordTicket.wm";
d228 1
a228 1
    private void sendPasswordTicket (WebContext context, Domain domain,
d237 1
a237 2

        String url = URL.schemeAndServer(context) + "/servlets/PasswordEdit";
d240 2
a241 8
        
        BuildContext ctx = TemplateInterpolator.createContext();
        ctx.put("user", user);
        ctx.put("url", url);
        String body = TemplateInterpolator.interpolate
            (PASSWORD_TICKET_TEMPLATE, ctx, getClass());        
        new HelmEmailer().mailUserFromSystem
            (user, PASSWORD_TICKET_EMAIL_SUBJECT, body);
@


1.21.2.13
log
@Normalized copyright dates.
@
text
@d2 1
a2 1
 * Copyright (c) 2000-2001 CollabNet.  All rights reserved.
d75 1
a75 1
 * @@version $Id: TLogin.java,v 1.21.2.12 2001/02/14 23:20:28 leonardr Exp $
@


1.21.2.14
log
@Added new imports necessitated by Torque.
@
text
@a66 1
import org.tigris.helm.om.base.*;
d75 1
a75 1
 * @@version $Id: TLogin.java,v 1.21.2.13 2001/02/15 20:50:35 leonardr Exp $
@


1.20
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.19
log
@Removed deprecated check of validAction flag.  This has been replaced
by useful checks that don't allocate memory pointlessly.
@
text
@@


1.18
log
@added specialized version of redirectToDetour so we have better control over page after login
@
text
@a120 2
            boolean validAction = action.equals("none");

a122 2
                validAction = true;

a148 2
                validAction = true;

a175 1
            if (debug && !validAction) log.warning("Invalid action: " + action);
@


1.17
log
@made TLogin go directly to HomePage (/) on success
@
text
@d180 1
a180 1
                redirectToHomePage(ctx);
d197 35
@


1.16
log
@Corrected a bunch of regressions to previous User instantion method.  Deprecated User's getUserID() method in favor of getID() for better conformance with BusinessObject interface and orthoginality with other business objects.  Added a guest user and interface.  Added some JavaDoc to User.
@
text
@d180 1
a180 1
                redirectToDetour(ctx);
@


1.15
log
@Migrated to latest Turbine CVS to avoid connection release bug (fixed long ago in Turbine CVS--we just had a bunk version).
@
text
@d112 1
a112 1
        if (sMgr.isLoggedIn().booleanValue())
d114 6
a119 3
            // Indicate which user the client is already logged in.
            ctx.put("loginID", sMgr.getLoginID());
        }
a120 2
        try
        {
@


1.14
log
@Add the loginID of a logged in user to the context.
@
text
@d114 1
a114 1
            // Need to indicate that the user is already logged in.
@


1.13
log
@Rather than redirecting to the Unauthorized Access screen on a
unrecognized action, perform default action and log a warning if in
debug mode.
@
text
@d110 7
a116 1
        if (debug) log.info("action=" + action );
@


1.13.2.1
log
@made TLogin go directly to HomePage (/) on success
@
text
@d173 1
a173 1
                redirectToHomePage(ctx);
@


1.13.2.2
log
@moved change from HEAD
@
text
@d110 1
a110 1
        if (debug) log.info("action=" + action);
a113 7
            if (sMgr.isLoggedIn().booleanValue() &&
                !sMgr.getUserID().equals(User.getGuest().getID()))
            {
                // Indicate which user the client is already logged in.
                ctx.put("loginID", sMgr.getLoginID());
            }

a189 72

    /**
     * Redirect to the detoured page.  But dont do to startservlet,
     * always go to HomePage.
     *
     * @@param	context    the WebContext partially populated by WMServlet
     * @@exception	HandlerException
     * @@exception	RedirectException
     */
        protected void
    redirectToDetour (WebContext context)
	throws HandlerException, RedirectException
    {
	SessionManager sMgr = getSessionManager(context);
	String detourPage = sMgr.redirectToDetour(context);

	if (detourPage != null)
	{
	    if (debug) log.info("redirectToDetour: " + detourPage);
	    redirectTo(detourPage);
	}
	else
	{
	    if (debug) log.info("redirectToDetour: setting action=none; " +
                    "isLoggedIn: " + context.get("isLoggedIn"));
	    context.put(ACTION_KEY, "none");

	    // if (((Boolean) context.get("isLoggedIn")).booleanValue())
            // redirectTo(myProperties.getProperty("startServletName"));
	    // else
            redirectToDetour(context);
	}
    }



 
     /**
      * Redirect to the detoured page.  But dont do to startservlet,
      * always go to HomePage.
      *
      * @@param context    the WebContext partially populated by WMServlet
      * @@exception     HandlerException
      * @@exception     RedirectException
      */
    protected void
        redirectToDetour (WebContext context)
        throws HandlerException, RedirectException
    {
        SessionManager sMgr = getSessionManager(context);
        String detourPage = sMgr.redirectToDetour(context);
        
        if (detourPage != null)
            {
                if (debug) log.info("redirectToDetour:" + detourPage);
                redirectTo(detourPage);
            }
        else
            {
               if (debug) log.info("redirectToDetour: setting action=none; " +
                                   "isLoggedIn: " + context.get("isLoggedIn"));
               context.put(ACTION_KEY, "none");
               
               // if (((Boolean) context.get("isLoggedIn")).booleanValue())
               //
               //
               // redirectTo(myProperties.getProperty("startServletName"));
               // else
               redirectToHomePage(context);
            }
    }
 
@


1.13.2.3
log
@corrected bad merge
@
text
@d110 1
a110 1
        if (debug) log.info("action=" + action );
d114 7
d180 1
a180 1
                redirectToDetour(ctx);
a197 3



d227 1
a227 1
            redirectToHomePage(context);
d233 36
@


1.12
log
@Include the host protocol and name in the URL.  Duh!  ;)
@
text
@d175 1
a175 2

            if (!validAction) redirectToUnauthorized();
@


1.11
log
@Slightly more understandable comment.
@
text
@d138 1
a138 1
                    sendPasswordTicket(conn, dMgr, domainID, loginID);
d199 3
a201 2
    private void sendPasswordTicket (Connection conn, DataManager dMgr,
                                     String domainID, String loginOrEmail)
d209 2
a210 2
        String url = URL.appendCGIParam("/servlets/PasswordEdit",
                                        "userID", user.getID());
@


1.10
log
@Corrected syntax error.
@
text
@d129 1
a129 1
                    // A redeemable ticket is used for password editting.
@


1.9
log
@Handle email address.
@
text
@d205 2
a206 2
                     user = new User(conn, dMgr, domainID, loginOrEmail) :
                     user = new User(conn, loginOrEmail, dMgr, domainID));
@


1.8
log
@Send change password ticket.
@
text
@d204 3
a206 10
        User user = null;
        if (loginOrEmail.indexOf('@@') == -1)
        {
            user = new User(conn, dMgr, domainID, loginOrEmail);
        }
        else
        {
            // TODO: Handle User object retreival via email addrs.
        }

@


1.7
log
@Added necessary URL format.
@
text
@a52 2
import javax.servlet.*;
import javax.servlet.http.*;
d54 1
a54 1
import org.webmacro.util.*;
d56 2
a57 3
import org.webmacro.engine.*;
import org.webmacro.broker.*;
import org.webmacro.resource.*;
d61 3
a64 2
import org.joist.security.PasswordRegenerator;

d68 2
d87 5
d99 1
a99 2
    protected String
        processRequest (Connection conn, WebContext ctx)
d120 1
a120 1
                if (loginID.equals(""))
d122 4
a125 3
                    if (debug) log.info("missing loginID");
                    appendToMessage
                        (ctx, "Your login name is required for new password");
d129 12
a140 14
                    // TODO: Use a ticket redeemable for password editting.
                    // Mail that to the user, instead of a new plaintext
                    // password which allows a DOS attack because absolutely
                    // no auth is used.
                    //String ticket = user.newPasswordTicket();
                    //String url = URL.appendCGIParam("/servlets/PasswordEdit",
                    //                                "userID", ...);
                    //url = URL.appendCGIParam(url, "ticket", ticket);
                    if (debug) log.info("calling newPassword");
                    appendToMessage(ctx, "Your new password has been " + 
                                    "e-mailed to you");
                    PasswordRegenerator pwd =
                        new PasswordRegenerator(myProperties);
                    pwd.newPassword(conn, ctx, loginID);
a150 1

d154 1
a154 1
                                    "Email Address and Password");
d178 1
a178 1
        catch (SQLException e)
d180 1
a180 3
            String errMsg = e.getMessage();
            if (debug) log.warning(errMsg);
            throw new HandlerException(errMsg);
d182 1
a182 1
        catch (JoistException e)
d190 30
@


1.6
log
@Better TODO note, in line with latest interface to support
implementation.
@
text
@d129 3
@


1.5
log
@minor cleanup
@
text
@d124 5
a128 1
                    // TODO: Use a nonce: Nonce.buildNonce();
@


1.4
log
@removed evil tab characters
@
text
@d2 1
a2 1
 * Copyright (c) 2000 Collab.Net.  All rights reserved.
d17 1
a17 1
 * software developed by Collab.Net (http://www.Collab.Net/)."
d27 1
a27 1
 * permission of Collab.Net.
d44 1
a44 1
 * individuals on behalf of Collab.Net.
d85 2
d112 1
a112 1
            if (action.equals("New Password"))
d118 3
a120 3
                    if (debug) log.info("Tlogin: missing loginID");
                    ctx.put("Message",
                            "Your login name is required for new password");
d125 1
a125 1
                    if (debug) log.info("Tlogin: calling newPassword");
@


1.3
log
@scrubbed a tad more
@
text
@d71 10
a80 11
  * Display and process the login screen.
  *  - Get loginID and password from the screen
  *  - Use both the Name and Password to select from the User table
  *  - If no match, redisplay the Login screen with a "Login Failed" message
  *  - If a record is found:
  *    - Look up the Roles and Permissions for this User
  *    - Cache Permissions for this User
  *    - Redirect to the Start Page for this User
  *
  */

d92 3
a94 3
	protected String
    processRequest (Connection conn, WebContext ctx)
	throws HandlerException, RedirectException
d96 1
a96 1
	String templateName = super.processRequest(conn, ctx);
d98 1
a98 1
	SessionManager sMgr = getSessionManager(ctx);
d100 5
a104 5
	// Get loginID and password from the screen
	String loginID = ctx.getForm("loginID");
	String password = ctx.getForm("password");
	String action = getAction(ctx);
	if (debug) log.info("action=" + action );
d107 2
a108 2
	{
	    boolean validAction = action.equals("none");
d110 12
a121 12
	    if (action.equals("New Password"))
	    {
		validAction = true;

		if (loginID.equals(""))
		{
		    if (debug) log.info("Tlogin: missing loginID");
		    ctx.put("Message",
			"Your login name is required for new password");
		}
		else
		{
d123 1
a123 1
		    if (debug) log.info("Tlogin: calling newPassword");
d126 9
a134 9
		    PasswordRegenerator pwd =
			new PasswordRegenerator(myProperties);
		    pwd.newPassword(conn, ctx, loginID);
		}
	    }

	    if (action != null && action.equals(LOGIN))
	    {
		validAction = true;
d140 3
a142 3
		if (!haveValue(loginID) || !haveValue(password))
		{
		    appendToMessage(ctx, "Please enter a Login Name or " +
d144 2
a145 2
		    return templateName;
		}
d147 5
a151 5
		// Check if the login name - password is valid, and cache
		// login info in the session.
		if (!sMgr.loginIsValid(conn, ctx, loginID, password))
		{
		    // Login failed.  Bail out now and redisplay the login
d153 26
a178 26
		    appendToMessage(ctx, "Login Failed");
		    return templateName;
		}

		// Look up the Roles and Permissions for this User and
		// cache them in the session.
		sMgr.getPermissions(conn, ctx);

		// Redirect to the target page or the Start Page for this User
		redirectToDetour(ctx);
	    }

	    if (!validAction) redirectToUnauthorized();
	}
	catch (SQLException e)
	{
	    String errMsg = e.getMessage();
	    if (debug) log.warning(errMsg);
	    throw new HandlerException(errMsg);
	}
	catch (JoistException e)
	{
	    String errMsg = e.getMessage();
	    if (debug) log.warning(errMsg);
	    throw new HandlerException(errMsg);
	}
d180 1
a180 1
	return templateName;
@


1.2
log
@Refactored to make use of some new functionality.
@
text
@d152 3
a154 2
		    // Login failed.  Bail out now and redisplay the login page.
		    ctx.put("Message", "Login Failed");
d157 3
a159 3
	    
		//  Look up the Roles and Permissions for this User and
		//  cache them in the session.
d162 1
a162 1
		//  Redirect to the target page or the Start Page for this User
@


1.1
log
@Initial revision
@
text
@d84 5
a88 2
    static private Log log = new Log("tlogin", "TLogin");
    static private boolean debug = true;
d94 1
a94 1
    processRequest (Connection connection, WebContext context)
d97 1
a97 1
	String templateName = super.processRequest(connection, context);
d99 1
a99 1
	SessionManager sMgr = getSessionManager(context);
d102 4
a105 3
	String loginID = context.getForm("loginID");
	String password = context.getForm("password");
	String action = (String)context.get("action");
d107 1
a107 3
	if (debug) log.debug("action=" + action );

	try
d117 2
a118 2
		    if (debug) log.debug("Tlogin: missing loginID");
		    context.put("Message",
d123 4
a126 3
		    if (debug) log.debug("Tlogin: calling newPassword");
		    context.put("Message",
			"Your new password has been e-mailed to you");
d129 1
a129 1
		    pwd.newPassword(connection, context, loginID);
d133 1
a133 1
	    if (action.equals("Login"))
d137 1
a137 1
                log.info("clearing out acl");
d141 1
a141 2
		if ((loginID == null) || (loginID.trim().length() == 0) ||
		   (password == null) || (password.trim().length() == 0))
d143 2
a144 2
		    context.put("Message",
			"Please enter a Login Name or Email Address and Password");
d150 1
a150 1
		if (!sMgr.loginIsValid(connection, context, loginID, password))
d153 1
a153 1
		    context.put("Message", "Login Failed");
d159 1
a159 1
		sMgr.getPermissions(connection, context);
d162 1
a162 1
		redirectToDetour(context);
d169 3
a171 3
	    String message = "SQL problem in Tlogin: " + e.getMessage();
	    if (debug) log.debug(message);
	    throw new HandlerException(message);
d175 3
a177 3
	    String message = "Problem in Tlogin: " + e.getMessage();
	    if (debug) log.debug(message);
	    throw new HandlerException(message);
a182 1

@


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/)."
d27 1
a27 1
 * permission of CollabNet.
d44 1
a44 1
 * individuals on behalf of CollabNet.
d53 2
d56 1
a56 3
import org.apache.turbine.util.Log;
import org.apache.turbine.util.TurbineException;

d58 3
a60 1
import org.webmacro.engine.BuildContext;
d62 1
d65 2
d70 11
a80 5
import org.tigris.helm.DoesNotExist;
import org.tigris.helm.om.peer.*;
import org.tigris.helm.om.base.*;
import org.tigris.helm.om.*;
import org.tigris.helm.tool.*;
a81 7
/**
 * Display and process the Tigris login screen.
 *
 * @@author <a href="mailto:jrobbins@@collab.net">Jason Robbins</a>
 * @@author <a href="mailto:dlr@@collab.net">Daniel Rall</a>
 * @@version $Id: TLogin.java,v 1.21.2.14 2001/02/16 03:01:26 dlr Exp $
 */
d84 2
a85 7
    private static final String LOGIN = "Login";

    private static final String NEW_PASSWD = "New Password";

    private static final String PASSWORD_TICKET_EMAIL_SUBJECT 
        = "How to change your password";
    private static final String PASSWORD_TICKET_TEMPLATE = "PasswordTicket.wm";
d88 1
a88 1
     *  Display and process the Tigris login screen.
d90 3
a92 2
    protected String processRequest (Connection conn, WebContext ctx)
        throws HandlerException, RedirectException
d94 14
a107 1
        String templateName = super.processRequest(conn, ctx);
d109 24
a132 1
        SessionManager sMgr = getSessionManager(ctx);
d134 1
a134 40
        // Get loginID and password from the screen
        String loginID = ctx.getForm("loginID");
        String password = ctx.getForm("password");
        String action = getAction(ctx);
        Log.debug("action=" + action);

        try
        {
            if (sMgr.isLoggedIn().booleanValue() &&
                !sMgr.getUserID().equals(UserPeer.getAnonymousUser().getID()))
            {
                // Indicate which user the client is already logged in.
                ctx.put("loginID", sMgr.getLoginID());
            }

            // HACK: We need currentDomain, but do not sub class
            // HelmServlet.  Thus, we sin.
            String domainName = JoistProperties.getProperty("domain");
            Domain currentDomain = DomainPeer.getInstanceByName(domainName);

            if (action.equals(NEW_PASSWD))
            {
                if (haveValue(loginID))
                {
                    // Send a ticket redeemable for password editting.
                    sendPasswordTicket(ctx, currentDomain, loginID);
                    appendToMessage(ctx, "The URL to set a new password has " +
                                    "been e-mailed to you");
                }
                else
                {
                    Log.debug("Missing loginID");
                    appendToMessage(ctx, "Your login name or email address " +
                                    "is required for a new password");
                }
            }

            if (action != null && action.equals(LOGIN))
            {
                Log.debug("clearing out acl");
a136 42
                if (!haveValue(loginID) || !haveValue(password))
                {
                    appendToMessage(ctx, "Please enter a Login Name or " +
                                    "Email Address and a Password");
                    return templateName;
                }

                // Check if the login name - password is valid, and cache
                // login info in the session.
                try
                {
                    UserPeer.assertValidLogin(currentDomain, loginID,
                                              password);
                    User u = UserPeer.getInstanceByLoginName(currentDomain,
                                                             loginID);
                    sMgr.isLoggedIn(true);
                    sMgr.setUserID(u.getID());
                    sMgr.setLoginID(u.getLoginName());
                    sMgr.setEmail(u.getEmail());
                    sMgr.setUserName(u.getRealName());
                }
                catch (TurbineException invalidLogin)
                {
                    // Login failed.  Bail out now and redisplay the login
                    // page.
                    appendToMessage(ctx, "Login Failed");
                    return templateName;
                }

                // Redirect to the target page or the Start Page for this User
                redirectToDetour(ctx);
            }
        }
        catch (RedirectException e)
        {
            throw e;
        }
        catch (Exception e)
        {
            Log.error(e);
            throw new HandlerException(e.getMessage());
        }
d138 24
a161 2
        return templateName;
    }
d163 3
a165 16
    /**
     * Redirect to the detoured page.  But dont do to startservlet,
     * always go to HomePage.
     *
     * @@param	context    the WebContext partially populated by WMServlet
     * @@exception	HandlerException
     * @@exception	RedirectException
     */
        protected void
    redirectToDetour (WebContext context)
	throws HandlerException, RedirectException
    {
	SessionManager sMgr = getSessionManager(context);
	String detourPage = sMgr.redirectToDetour(context);

	if (detourPage != null)
d167 3
a169 2
	    Log.debug("redirectToDetour: " + detourPage);
	    redirectTo(detourPage);
d171 1
a171 1
	else
d173 3
a175 8
	    Log.debug("redirectToDetour: setting action=none; " +
                      "isLoggedIn: " + context.get("isLoggedIn"));
	    context.put(ACTION_KEY, "none");

	    // if (((Boolean) context.get("isLoggedIn")).booleanValue())
            // redirectTo(myProperties.getProperty("startServletName"));
	    // else
            redirectToHomePage(context);
a176 1
    }
d178 1
a178 28
    /**
     * Sends a email with a URL containing a ticket used to validate a change
     * of password for the user.  Using this ticket and having the user come to
     * the site to change their password prevents a DOS attack against the user
     * that would be possible if we just changed the password and emailed it
     * directly instead.
     */
    private void sendPasswordTicket (WebContext context, Domain domain,
                                     String loginOrEmail)
        throws DoesNotExist, Exception
    {
        User user = (loginOrEmail.indexOf('@@') == -1 ?
                     UserPeer.getInstanceByLoginName(domain, loginOrEmail) :
                     UserPeer.getInstanceByEmail(domain, loginOrEmail));
        String ticket = ""; 
        user.newPasswordTicket();

        String url = URL.schemeAndServer(context) + "/servlets/PasswordEdit";
        url = URL.appendCGIParam(url, "userID", user.getID());
        url = URL.appendCGIParam(url, "ticket", ticket);
        
        BuildContext ctx = TemplateInterpolator.createContext();
        ctx.put("user", user);
        ctx.put("url", url);
        String body = TemplateInterpolator.interpolate
            (PASSWORD_TICKET_TEMPLATE, ctx, getClass());        
        new HelmEmailer().mailUserFromSystem
            (user, PASSWORD_TICKET_EMAIL_SUBJECT, body);
d181 1
@

