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 CreateNewUserAndConfirm.java JLoginUser.java
Date Thu, 28 Jun 2001 08:49:47 GMT
taylor      01/06/28 01:49:46

  Modified:    src/java/org/apache/jetspeed/modules/actions
                        CreateNewUserAndConfirm.java JLoginUser.java
  Log:
  - modified JLoginUser.java to use Jetspeed(Turbine)Security
  
  Revision  Changes    Path
  1.18      +5 -15     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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- CreateNewUserAndConfirm.java	2001/06/22 06:35:52	1.17
  +++ CreateNewUserAndConfirm.java	2001/06/28 08:49:38	1.18
  @@ -171,12 +171,12 @@
                   if (false == enableMail)
                       confirmValue = JetspeedResources.CONFIRM_VALUE;
       
  -                user.setConfirmed( confirmValue );
  +                user.setConfirmed( confirmValue );                
   
  -                JetspeedSecurity.addUser(user, pass1);
  -
                   // Store the user object.
                   data.setUser(user);
  +         
  +                JetspeedSecurity.addUser(user, pass1, data);
   
                   data.setMessage(Localization.getString("CREATENEWUSERANDCONFIRM_CREATE"));
                   if (enableMail)
  @@ -242,19 +242,9 @@
             data.setACL(acl);
             data.save();
   
  -           if (JetspeedResources.getBoolean("services.Profiler.enable", false))
  -           {
  -               // As the user is already in the db, we better
  -               // send the email, no matter the error we get here
  -               try {
  -                   Profiler.createUserProfile(data, username);
  -               } catch (Throwable t) {
  -                   Log.error(t);
  -               }
  -           }
             // bring logged on user to homepage with internal redirect
  -          data.setScreenTemplate(TurbineTemplate.getDefaultScreen());
  -          data.setMessage(TurbineResources.getString("login.welcome"));
  +          //data.setScreenTemplate(TurbineTemplate.getDefaultScreen());
  +          data.setScreenTemplate("Home.vm");
           }
           catch ( Exception e )
           {
  
  
  
  1.14      +27 -149   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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- JLoginUser.java	2001/06/07 22:00:21	1.13
  +++ JLoginUser.java	2001/06/28 08:49:41	1.14
  @@ -68,20 +68,15 @@
   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.util.db.pool.DBConnection;
  -import org.apache.turbine.util.db.map.TurbineMapBuilder;
  -import org.apache.turbine.om.peer.BasePeer;
   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.TurbineUser;
  +import org.apache.turbine.om.security.User;
   import org.apache.turbine.util.Log;
  -import com.workingdogs.village.KeyDef;
  -import com.workingdogs.village.TableDataSet;
  -import com.workingdogs.village.QueryDataSet;
  -import com.workingdogs.village.Record;
   import org.apache.jetspeed.services.resources.JetspeedResources;
   import org.apache.jetspeed.services.Profiler;
  +import org.apache.jetspeed.services.JetspeedSecurity;
  +
   /**
       This class is responsible for logging a user into the system. It is also
       responsible for making sure that the user has been marked as confirmed. 
  @@ -105,12 +100,12 @@
           // we are on the ConfirmRegistration page
           Log.note("Entering JLoginUser action");
   
  -        TurbineMapBuilder mapBuilder = (TurbineMapBuilder) BasePeer.getMapBuilder();
  -
           String secretkey = (String) data.getParameters().getString("secretkey", null);
           if ( secretkey != null )
           {
   
  +            // its the first logon - we are verifying the secretkey
  +
               // handle the buttons on the ConfirmRegistration page
               String button1 = data.getParameters().getString ( "submit1", null );
               if ( button1 != null && button1.equalsIgnoreCase("Cancel") )
  @@ -118,156 +113,39 @@
                   data.setScreenTemplate(TurbineTemplate.getDefaultScreen());
                   return;
               }
  -            
  -            // get a connection to the db
  -            DBConnection db = TurbineDB.getConnection();
  -            Connection connection = db.getConnection();
  -            // execute the query
  -            String username = data.getParameters().getString("username", "");
  -            KeyDef kd = new KeyDef().addAttrib(mapBuilder.getUsername());
  -            TableDataSet tds = new TableDataSet( connection, TurbineUserPeer.getTableName(),
kd );
  -            StringBuffer where = new StringBuffer();
  -            where.append ( mapBuilder.getUsername() );
  -            where.append ( "='" );
  -            where.append ( username );
  -            where.append ( "'" );
  -            tds.where ( where.toString() );
  -            TableDataSet tds2 = null;
  -            try
  -            {
  -                tds.fetchRecords(1);
  -                if ( tds.size() == 1 )
  -                {
  -                    Record rec = tds.getRecord(0);
  -                    
  -                    // 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
( JetspeedResources.CONFIRM_VALUE ) )
  -                    {
  -                        data.setMessage(Localization.getString("JLOGINUSER_KEYNOTVALID"));
  -                        data.setScreenTemplate("ConfirmRegistration");
  -                        return;
  -                    }
  -                    
  -                    // if the user is not confirmed
  -                    if ( ! confirm_value.equals ( JetspeedResources.CONFIRM_VALUE ) )
  -                    {
  -                        rec.setValue ( "CONFIRM_VALUE", JetspeedResources.CONFIRM_VALUE
);
  -                        rec.save();
  -            
  -                        // Asign this user the role of authenticated_user.
  -                        // This feature was added at 26.01.2000
  -                        // by Bernie Hoeneisen, ETH Zurich, mailto:bhoeneis@ee.ethz.ch
  -                        String user_id = null;
  -                        String group_id = null;
  -                        String role_id = null;
               
  -                        user_id = rec.getValue(TurbineUserPeer.getColumnName(mapBuilder.getUserId())).asString();
  -                        
  -                        // FIX ME: What value is the group_id supposed to be set to???
  -
  -                        // select role_id of authenticated_user from UserRole
  -                        kd = new KeyDef().addAttrib(mapBuilder.getRoleName());
  -                        tds2 =  new TableDataSet( connection, RolePeer.getTableName(),
kd );
  -                        tds2.where ( mapBuilder.getRoleName() + "='authenticated_user'"
);
  -                        tds2.fetchRecords(1);
  -                        if ( tds2.size() == 1 )
  -                        {
  -                            role_id = tds2.getRecord(0).getValue(mapBuilder.getRoleId()).asString();
  -                        }
  -                        else
  -                        {
  -                            throw new Exception(Localization
  -                                    .getString("JLOGINUSER_NOAUTHUSERROLE"));
  -                        }
  -            
  -                        // add  user_id, group_id, role_id to UserGroupRole
  -                        Criteria crit = new Criteria();
  -                        crit.add ( UserGroupRolePeer.getColumnName(mapBuilder.getUserId()),
user_id );
  -                        crit.add ( UserGroupRolePeer.getColumnName(mapBuilder.getGroupId()),
group_id );
  -                        crit.add ( UserGroupRolePeer.getColumnName(mapBuilder.getRoleId()),
role_id );
  -                        try
  -                        {
  -                            UserGroupRolePeer.doInsert(crit);
  -                        }
  -                        catch ( SQLException e )
  -                        {
  -                            // ignore. there is a possibility that this already exists.
  -                            // because we may be re-confirming a user after the user 
  -                            // edited their email address. in that case, this code 
  -                            // has already been executed and we are set.
  -                        }
  -                        // End: Asign this user the role of authenticated_user.
  -                    }
  -                    
  -                    String password = rec.getValue("PASSWORD_VALUE").asString();
  -                    data.getParameters().add ( "username", username );
  -                    data.getParameters().add ( "password", password );
  -                    data.setMessage (Localization.getString("JLOGINUSER_WELCOME"));
  -                }
  -                else
  -                {
  -                    StringBuffer msg = new StringBuffer();
  -                    msg.append (Localization.getString("JLOGINUSER_NAMENOTVALID"));
  -                    data.setMessage ( msg.toString() );
  -                    data.setScreenTemplate("NewAccount");
  -                    return;
  -                }
  -            }
  -            finally
  +            // check to make sure the user entered the right confirmation key
  +            // if not, then send them to the ConfirmRegistration screen            
  +            User user = data.getUser();           
  +            if (user == null)
  +                return;   
  +
  +            String confirm_value = user.getConfirmed();
  +            if ( ! secretkey.equals ( confirm_value ) && ! confirm_value.equals
( JetspeedResources.CONFIRM_VALUE ) )
               {
  -                if ( tds != null ) tds.close();
  -                if ( tds2 != null ) tds2.close();
  -                TurbineDB.releaseConnection(db);
  +                data.setMessage(Localization.getString("JLOGINUSER_KEYNOTVALID"));
  +                data.setScreenTemplate("ConfirmRegistration");
  +                return;
               }
  +             
  +            user.setConfirmed( JetspeedResources.CONFIRM_VALUE );
  +            JetspeedSecurity.saveUser(user);
  +            data.setMessage (Localization.getString("JLOGINUSER_WELCOME"));
           }
           
           // check for valid username/password - execute Turbine LoginUser action
           ActionLoader.getInstance().exec(data, "LoginUser");
           
           // check for being confirmed before allowing someone to finish logging in
  -        Log.note("User hasLoggedIn1: " + data.getUser().hasLoggedIn() );
  -        if ( data.getUser().hasLoggedIn() )
  -        {
  -           if (JetspeedResources.getBoolean("services.Profiler.enable", false))
  -           {
  -               // As the user is already in the db, we better
  -               // send the email, no matter the error we get here
  -               try {
  -                   String username = data.getParameters().getString("username");
  -                   Profiler.createUserProfile(data, username);
  -               } catch (Throwable t) {
  -                   Log.error(t);
  -               }
  -           }
  -
  -            // get a connection to the db
  -            DBConnection db = TurbineDB.getConnection();
  -            Connection connection = db.getConnection();
  -            // execute the query
  -            StringBuffer sql = new StringBuffer();
  -            sql.append ("select "+ mapBuilder.getConfirmValue() +" from "+ mapBuilder.getTableUser());
  -            sql.append (" where "+ mapBuilder.getUserId() +"=" + ((TurbineUser)data.getUser()).getPrimaryKey()
);
  -            sql.append (" and " );
  -            sql.append ( mapBuilder.getConfirmValue() + "='CONFIRMED'" );
   
  -            QueryDataSet qds = new QueryDataSet(connection, sql.toString() );
  -            try
  -            {
  -                qds.fetchRecords(1);
  -                if ( qds.size() == 0 )
  -                {
  -                    data.setMessage(Localization.getString("JLOGINUSER_CONFIRMFIRST"));
  -                    data.setScreenTemplate("ConfirmRegistration");
  -                    data.getUser().setHasLoggedIn(new Boolean (false) );
  -                    return;
  -                }
  -            }
  -            finally
  +        if ( data.getUser().hasLoggedIn())
  +        {
  +            if (!data.getUser().getConfirmed().equals(JetspeedResources.CONFIRM_VALUE ))
               {
  -                if ( qds != null ) qds.close();
  -                TurbineDB.releaseConnection(db);
  +                data.setMessage(Localization.getString("JLOGINUSER_CONFIRMFIRST"));
  +                data.setScreenTemplate("ConfirmRegistration");
  +                data.getUser().setHasLoggedIn(new Boolean (false) );
  +                return;
               }
           }
           
  
  
  

---------------------------------------------------------------------
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