You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by pa...@apache.org on 2001/11/19 08:49:39 UTC

cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions SendNewUserNotificationEmail.java CreateNewUserAndConfirm.java JLoginUser.java SendConfirmationEmail.java

paulsp      01/11/18 23:49:39

  Modified:    src/java/org/apache/jetspeed/modules/actions
                        CreateNewUserAndConfirm.java JLoginUser.java
                        SendConfirmationEmail.java
  Added:       src/java/org/apache/jetspeed/modules/actions
                        SendNewUserNotificationEmail.java
  Log:
  Adding New User Confirmation and Notification
  PR:  4192
  Submitted by: Chris Kimpton
  
  Revision  Changes    Path
  1.22      +27 -7     jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/CreateNewUserAndConfirm.java
  
  Index: CreateNewUserAndConfirm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/CreateNewUserAndConfirm.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- CreateNewUserAndConfirm.java	2001/07/17 16:39:30	1.21
  +++ CreateNewUserAndConfirm.java	2001/11/19 07:49:39	1.22
  @@ -158,7 +158,6 @@
                   
                   user.setUserName( username );   
                   user.setPassword ( pass1 );
  -                //er.setModifiedDate(now);
                   user.setCreateDate(now);
                   user.setLastLogin(new Date(0));
                   user.setFirstName( data.getParameters().getString("firstname") );
  @@ -169,26 +168,47 @@
                   String confirmValue = GenerateUniqueId.getIdentifier();
       
                   // allow for disabling of email for configurations without a mail server
  -                boolean enableMail = JetspeedResources.getBoolean("confirm.email.enable", false);
  +                boolean newUserNotification = JetspeedResources.getBoolean("newuser.notification.enable", false);
  +                boolean newUserApproval = JetspeedResources.getBoolean("newuser.approval.enable", false);
  +                boolean enableMail = JetspeedResources.getBoolean("newuser.confirm.email.enable", false);
                   if (false == enableMail)
                       confirmValue = JetspeedResources.CONFIRM_VALUE;
       
  +                if (true == newUserApproval)
  +                    confirmValue = JetspeedResources.CONFIRM_VALUE_PENDING;
  +
                   user.setConfirmed( confirmValue );                
   
                   // Store the user object.
                   data.setUser(user);
            
                   JetspeedSecurity.addUser(user, pass1, data);
  -                user.setHasLoggedIn(new Boolean (true));        
  -
  +                if (!enableMail && !newUserApproval)
  +                {
  +                  user.setHasLoggedIn(new Boolean (true));        
  +                  user.setLastLogin(new Date(0));
  +                }
                   data.setMessage(Localization.getString("CREATENEWUSERANDCONFIRM_CREATE"));
  -                if (enableMail)
  +                if (enableMail || newUserNotification || newUserApproval)
                   {
                       data.setUser(TurbineSecurity.getAnonymousUser());
                       data.getParameters().add("username", username);
                       data.getParameters().add("password", pass1);
  -                    ActionLoader.getInstance().exec(data, "SendConfirmationEmail");
  -                    data.setScreenTemplate("ConfirmRegistration");
  +                    if ( ! newUserApproval )
  +                    {
  +                        ActionLoader.getInstance().exec(data, "SendConfirmationEmail");
  +                        data.setScreenTemplate("ConfirmRegistration");
  +                    }
  +                    else
  +                    {
  +                        data.setScreenTemplate("NewUserAwaitingAcceptance");
  +                    }
  +                    // FIXME: Should notification be set when request is made, or when
  +                    //        user is accepted?
  +                    if ( newUserNotification )
  +                    {
  +                        ActionLoader.getInstance().exec(data, "SendNewUserNotificationEmail");
  +                    }
                   }
                   else
                   {
  
  
  
  1.17      +43 -16    jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/JLoginUser.java
  
  Index: JLoginUser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/JLoginUser.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- JLoginUser.java	2001/07/08 03:41:35	1.16
  +++ JLoginUser.java	2001/11/19 07:49:39	1.17
  @@ -62,17 +62,17 @@
   // Turbine Modules
   import org.apache.turbine.modules.Action;
   import org.apache.turbine.modules.ActionLoader;
  -import org.apache.turbine.util.RunData;
  -import org.apache.turbine.services.localization.Localization;
  -import org.apache.turbine.services.resources.TurbineResources;
  -import org.apache.turbine.services.template.TurbineTemplate;
  -import org.apache.turbine.services.db.TurbineDB;
  -import org.apache.turbine.util.db.Criteria;
  +import org.apache.turbine.om.security.peer.RolePeer;
   import org.apache.turbine.om.security.peer.TurbineUserPeer;
   import org.apache.turbine.om.security.peer.UserGroupRolePeer;
  -import org.apache.turbine.om.security.peer.RolePeer;
   import org.apache.turbine.om.security.User;
  +import org.apache.turbine.services.db.TurbineDB;
  +import org.apache.turbine.services.localization.Localization;
  +import org.apache.turbine.services.resources.TurbineResources;
  +import org.apache.turbine.services.template.TurbineTemplate;
   import org.apache.turbine.util.Log;
  +import org.apache.turbine.util.RunData;
  +
   import org.apache.jetspeed.services.resources.JetspeedResources;
   import org.apache.jetspeed.services.Profiler;
   import org.apache.jetspeed.services.JetspeedSecurity;
  @@ -100,6 +100,7 @@
           // we are on the ConfirmRegistration page
           Log.note("Entering JLoginUser action");
   
  +        boolean newUserApproval = JetspeedResources.getBoolean("newuser.approval.enable", false);
           String secretkey = (String) data.getParameters().getString("secretkey", null);
           if ( secretkey != null )
           {
  @@ -116,7 +117,6 @@
               
               // check to make sure the user entered the right confirmation key
               // if not, then send them to the ConfirmRegistration screen            
  -//            User user = data.getUser();          
               String username = data.getParameters().getString("username", "");
               String password = data.getParameters().getString("password", "");
               User user = JetspeedSecurity.getUser(username);
  @@ -129,9 +129,27 @@
               String confirm_value = user.getConfirmed();
               if ( ! secretkey.equals ( confirm_value ) && ! confirm_value.equals ( JetspeedResources.CONFIRM_VALUE ) )
               {
  -                data.setMessage(Localization.getString("JLOGINUSER_KEYNOTVALID"));
  -                data.setScreenTemplate("ConfirmRegistration");
  -                return;
  +                if ( newUserApproval )
  +                {
  +                    data.setMessage(Localization.getString("JLOGINUSER_KEYNOTVALID"));
  +                    data.setScreenTemplate("NewUserAwaitingAcceptance");
  +                    return;
  +                }
  +                else
  +                {
  +                  if ( user.getConfirmed().equals(JetspeedResources.CONFIRM_VALUE_REJECTED))
  +                  {
  +                    data.setMessage(Localization.getString("JLOGINUSER_KEYNOTVALID"));
  +                    data.setScreenTemplate("NewUserRejected");
  +                    return;
  +                  }
  +                  else
  +                  {
  +                    data.setMessage(Localization.getString("JLOGINUSER_KEYNOTVALID"));
  +                    data.setScreenTemplate("ConfirmRegistration");
  +                    return;
  +                  }
  +                }
               }
                
               user.setConfirmed( JetspeedResources.CONFIRM_VALUE );
  @@ -149,12 +167,21 @@
               String confirmed = data.getUser().getConfirmed();
               if (confirmed == null || !confirmed.equals(JetspeedResources.CONFIRM_VALUE ))
               {
  -                data.setMessage(Localization.getString("JLOGINUSER_CONFIRMFIRST"));
  -                data.setScreenTemplate("ConfirmRegistration");
  -                data.getUser().setHasLoggedIn(new Boolean (false) );
  -                return;
  +                if ( confirmed.equals(JetspeedResources.CONFIRM_VALUE_REJECTED))
  +                {
  +                  data.setMessage(Localization.getString("JLOGINUSER_KEYNOTVALID"));
  +                  data.setScreenTemplate("NewUserRejected");
  +                  data.getUser().setHasLoggedIn(new Boolean (false) );
  +                  return;
  +                }
  +                else
  +                {
  +                  data.setMessage(Localization.getString("JLOGINUSER_CONFIRMFIRST"));
  +                  data.setScreenTemplate("ConfirmRegistration");
  +                  data.getUser().setHasLoggedIn(new Boolean (false) );
  +                  return;
  +                }
               }
           }
  -        
       }
   }
  
  
  
  1.14      +5 -8      jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/SendConfirmationEmail.java
  
  Index: SendConfirmationEmail.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/SendConfirmationEmail.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SendConfirmationEmail.java	2001/11/19 01:44:34	1.13
  +++ SendConfirmationEmail.java	2001/11/19 07:49:39	1.14
  @@ -58,25 +58,22 @@
   import java.io.StringWriter;
   import java.util.Properties;
     
  -// jetspeed services
  +// Jetspeed Stuff
   import org.apache.jetspeed.services.TemplateLocator;
   import org.apache.jetspeed.services.resources.JetspeedResources;
   import org.apache.jetspeed.services.JetspeedSecurity;
   
   // Turbine Stuff
   import org.apache.turbine.modules.Action;
  -import org.apache.turbine.services.localization.Localization;
   import org.apache.turbine.om.security.User;
  +import org.apache.turbine.services.localization.Localization;
  +import org.apache.turbine.services.velocity.TurbineVelocity;
   import org.apache.turbine.util.RunData;
   import org.apache.turbine.util.DynamicURI;
   import org.apache.turbine.util.mail.SimpleEmail;
  -//import org.apache.turbine.util.mail.Email;
   import org.apache.turbine.util.Log;
  -
  -// turbine velocity
  -import org.apache.turbine.services.velocity.TurbineVelocity;
   
  -// velocity context
  +// Velocity Stuff
   import org.apache.velocity.context.Context;
   
   /**
  @@ -110,7 +107,7 @@
               emailContext.put("config",new JetspeedResources());
               emailContext.put("urltojetspeed",url);
               emailContext.put("email",se);
  -            String templateFile = JetspeedResources.getString("confirm.email.template");
  +            String templateFile = JetspeedResources.getString("newuser.confirm.email.template");
               String templatePath = TemplateLocator.locateEmailTemplate(data, templateFile);
               TurbineVelocity.handleRequest(emailContext, templatePath, email_body);
   
  
  
  
  1.1                  jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/SendNewUserNotificationEmail.java
  
  Index: SendNewUserNotificationEmail.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 The Apache Software Foundation.  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 acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *     "Apache Jetspeed" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache" or
   *    "Apache Jetspeed", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * 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 THE APACHE SOFTWARE FOUNDATION 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 the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package org.apache.jetspeed.modules.actions;
  
  // Java stuff
  import java.io.StringWriter;
  import java.util.Properties;
  import java.util.Locale;
  
  // Jetspeed Stuff
  import org.apache.jetspeed.services.resources.JetspeedResources;
  import org.apache.jetspeed.services.TemplateLocator;
  import org.apache.jetspeed.services.JetspeedSecurity;
  
  // Turbine Stuff
  import org.apache.turbine.modules.Action;
  import org.apache.turbine.om.security.User;
  import org.apache.turbine.services.localization.Localization;
  import org.apache.turbine.services.velocity.TurbineVelocity;
  import org.apache.turbine.util.RunData;
  import org.apache.turbine.util.DynamicURI;
  import org.apache.turbine.util.mail.SimpleEmail;
  import org.apache.turbine.util.Log;
  
  // Velocity Stuff
  import org.apache.velocity.context.Context;
  
  /**
      This action will send a notification email to the notification user.
  
  TODO - does this apply to the notify emails?
      This class is used in two places, the first one is for new users.
      The second is where a user is updating their information after they
      have already created their account. If they are updating and they change
      their email address, then we want to re-confirm it to prevent people from
      screwing up their email address.
  */
  public class SendNewUserNotificationEmail extends Action
  {
      public void doPerform( RunData data ) throws Exception
      {
          User user = JetspeedSecurity.getUser(data.getParameters().getString("username", ""));        
          DynamicURI url = new DynamicURI(data)
                               .addPathInfo("pane0", "Security" )
                               .addPathInfo("select-panel2", "User")
                               .addPathInfo("entityid", user.getUserName() )
                               .addQueryData("mode","update");
          try
          {
              //build body via template
              StringWriter email_body = new StringWriter();
              SimpleEmail se = new SimpleEmail();
              Context emailContext = TurbineVelocity.getContext();
              emailContext.put( "data", data );
              emailContext.put( "user", user );
              emailContext.put( "config",new JetspeedResources());
              emailContext.put( "userurl",url);
              emailContext.put( "email",se);
  
              //determine the language to be used for the notification email
              String language = JetspeedResources.getString("newuser.notification.language","en");
              String country = JetspeedResources.getString("newuser.notification.country","US");
              Locale locale = new Locale(language,country);
  
              String templateFile = JetspeedResources.getString("newuser.notification.email.template");
              String templatePath = TemplateLocator.locateEmailTemplate(data, templateFile, locale);
              TurbineVelocity.handleRequest(emailContext, templatePath, email_body);
  
              se.setMsg(email_body.toString());
  
              Properties props = System.getProperties();
              String mailServerMachine = JetspeedResources.getString( "mail.server" );
              props.put ( "mail.host", mailServerMachine );
              props.put("mail.smtp.host", mailServerMachine);
  
              se.send();
  
              data.setMessage (Localization.getString("SENDCONFIRMATIONEMAIL_SENT"));
          } catch ( Exception e )
          {
              String errorTitle = Localization.getString("SENDCONFIRMATIONEMAIL_ERROR") ;
              String errorMessage = errorTitle + e.toString();
  
              Log.error( errorMessage );
              data.setMessage ( errorTitle + errorMessage );
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>