portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions JLoginUser.java CreateNewUserAndConfirm.java
Date Thu, 19 Apr 2001 23:16:50 GMT
taylor      01/04/19 16:16:50

  Modified:    src/java/org/apache/jetspeed/modules/actions JLoginUser.java
                        CreateNewUserAndConfirm.java
  Log:
  made the 'confirmation email' feature optional
  it can be enabled in the JR.p with 'confirm.email.enable=true/false'
  
  Revision  Changes    Path
  1.9       +5 -6      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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JLoginUser.java	2001/03/08 17:16:35	1.8
  +++ JLoginUser.java	2001/04/19 23:16:49	1.9
  @@ -79,6 +79,7 @@
   import com.workingdogs.village.TableDataSet;
   import com.workingdogs.village.QueryDataSet;
   import com.workingdogs.village.Record;
  +import org.apache.jetspeed.services.resources.JetspeedResources;
   
   /**
       This class is responsible for logging a user into the system. It is also
  @@ -88,9 +89,7 @@
   */
   public class JLoginUser extends Action
   {
  -    /** this is the value that is stored in the database for confirmed users */
  -    private static final String CONFIRM_VALUE = "CONFIRMED";
  -    
  +
       public void doPerform( RunData data ) throws Exception
       {
           // This prevents a db hit on second Action call during page
  @@ -143,7 +142,7 @@
                       // check to make sure the user entered the right confirmation key
                       // if not, then send them to the ConfirmRegistration screen
                       String confirm_value = rec.getValue("CONFIRM_VALUE").asString();
  -                    if ( ! secretkey.equals ( confirm_value ) && ! confirm_value.equals
( CONFIRM_VALUE ) )
  +                    if ( ! secretkey.equals ( confirm_value ) && ! confirm_value.equals
( JetspeedResources.CONFIRM_VALUE ) )
                       {
                           data.setMessage(Localization.getString("JLOGINUSER_KEYNOTVALID"));
                           data.setScreen("ConfirmRegistration");
  @@ -151,9 +150,9 @@
                       }
                       
                       // if the user is not confirmed
  -                    if ( ! confirm_value.equals ( CONFIRM_VALUE ) )
  +                    if ( ! confirm_value.equals ( JetspeedResources.CONFIRM_VALUE ) )
                       {
  -                        rec.setValue ( "CONFIRM_VALUE", CONFIRM_VALUE );
  +                        rec.setValue ( "CONFIRM_VALUE", JetspeedResources.CONFIRM_VALUE
);
                           rec.save();
               
                           // Asign this user the role of authenticated_user.
  
  
  
  1.11      +86 -9     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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- CreateNewUserAndConfirm.java	2001/04/19 21:57:22	1.10
  +++ CreateNewUserAndConfirm.java	2001/04/19 23:16:49	1.11
  @@ -58,6 +58,7 @@
   // JDK Stuff
   import java.sql.Connection;
   import java.util.Vector;
  +import javax.servlet.RequestDispatcher;
   
   // External Stuff
   import org.apache.turbine.modules.Action;
  @@ -74,10 +75,16 @@
   import org.apache.turbine.om.peer.BasePeer;
   import org.apache.turbine.om.security.User;
   import org.apache.turbine.om.security.peer.TurbineUserPeer;
  +import org.apache.turbine.om.security.TurbineUser;
   import com.workingdogs.village.TableDataSet;
   import com.workingdogs.village.Record;
   import org.apache.jetspeed.services.profiler.*;
   import org.apache.jetspeed.services.resources.JetspeedResources;
  +import org.apache.turbine.util.security.TurbineSecurityException;
  +import org.apache.turbine.services.security.TurbineSecurity;
  +import org.apache.turbine.util.security.AccessControlList;
  +import org.apache.turbine.util.DynamicURI;
  +import org.apache.turbine.util.StringUtils;
   
   /**
       This action validates the form input from the NewAccount Screen. 
  @@ -165,24 +172,44 @@
                       user.setPerm(User.CONFIRM_VALUE, confirmValue);
                   // add the user's details to the database
                   Record rec = tds.addRecord();
  -                rec.setValue ( mapBuilder.getPassword(), data.getParameters().getString("password")
);
  +                String password = data.getParameters().getString("password");
  +                rec.setValue ( mapBuilder.getPassword(), password );
                   rec.setValue ( mapBuilder.getUsername(), username );
                   rec.setValue ( mapBuilder.getFirstName(), data.getParameters().getString("firstname")
);
                   rec.setValue ( mapBuilder.getLastName(), data.getParameters().getString("lastname")
);
                   rec.setValue ( mapBuilder.getEmail(), data.getParameters().getString("email")
);
                   rec.setValue ( mapBuilder.getCreated(), new java.util.Date() );
  +                // allow for disabling of email for configurations without a mail server
  +                boolean enableMail = JetspeedResources.getBoolean("confirm.email.enable",
false);
  +                if (false == enableMail)
  +                    confirmValue = JetspeedResources.CONFIRM_VALUE;
                   rec.setValue ( mapBuilder.getConfirmValue(), confirmValue );
                   rec.save();
                   data.setMessage(Localization.getString("CREATENEWUSERANDCONFIRM_CREATE"));
                   if (JetspeedResources.getBoolean("services.ProfileManager.enable", false))
  -                    // As the user is already in the db, we better
  -                    // send the email, no matter the error we get here
  -                    try {
  -                        ProfileManager.createUserProfile(data, username);
  -                    } catch (Throwable t) {
  -                        Log.error(t);
  -                    }
  -                ActionLoader.getInstance().exec(data, "SendConfirmationEmail");
  +                // As the user is already in the db, we better
  +                // send the email, no matter the error we get here
  +                try {
  +                    ProfileManager.createUserProfile(data, username);
  +                } catch (Throwable t) {
  +                    Log.error(t);
  +                }
  +                if (enableMail)
  +                {
  +                    ActionLoader.getInstance().exec(data, "SendConfirmationEmail");
  +                    data.setScreenTemplate("ConfirmRegistration");
  +                }
  +                else
  +                {
  +                    bypassConfirmMail(data, username, password);
  +                }
  +
  +            }
  +            catch (Exception e)
  +            {
  +              data.setMessage(e.toString());
  +              data.setStackTrace(StringUtils.stackTrace(e), e);
  +              data.setScreenTemplate("Error");
               }
               finally
               {
  @@ -199,4 +226,54 @@
               data.getParameters().add("username", CHNAME);
           }
       }
  +
  +    /**
  +     * bypassConfirmMail allows configurations to bypass sending the confirmation email
  +     * The new user is logged on and then redirected to the home page
  +     *
  +     * @param data Turbine information.
  +     * @param username The user's username.
  +     * @param password The user's password.
  +     */
  +    private void bypassConfirmMail(RunData data, String username, String password)
  +    {
  +        User usr = null;
  +        try
  +        {
  +          // Authenticate the user and get the object.
  +          usr = TurbineSecurity.getAuthenticatedUser( username, password );
  +
  +          // Store the user object.
  +          data.setUser(usr);
  +
  +          // Mark the user as being logged in.
  +          usr.setHasLoggedIn(new Boolean(true));
  +
  +          // Set the last_login date in the database.
  +          usr.updateLastLogin();
  +
  +          AccessControlList acl = data.getACL();
  +          if ( acl == null )
  +          {
  +              acl = TurbineSecurity.getACL( data.getUser() );
  +              data.getSession().setAttribute( AccessControlList.SESSION_KEY,
  +                                          (Object)acl );
  +          }
  +          data.setACL(acl);
  +          data.save();
  +
  +          // bring logged on user to homepage with internal redirect
  +          String homepage = TurbineResources.getString("screen.homepage");
  +          data.setScreen(homepage);
  +          data.setMessage(TurbineResources.getString("login.welcome"));
  +        }
  +        catch ( Exception e )
  +        {
  +            data.setMessage(e.toString());
  +            data.setStackTrace(StringUtils.stackTrace(e), e);
  +            data.setScreenTemplate("Error");
  +        }
  +      }
  +
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message