Changeset 266

Show
Ignore:
Timestamp:
05/28/07 08:26:19
Author:
danfreak
Message:

added config option for direct activation, and modified needed libraries accordingly

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • FreakAuth/trunk/www/system/application/config/freakauth_light.php

    r259 r266  
    115115 $config['FAL_allow_user_registration'] = TRUE; 
    116116  
     117 /* 
     118 |------------------------------------------------------------------------------ 
     119 | Whether the registration/activation process requires e-mail verification 
     120 |  
     121 | If set to FALSE, the registration process is as follows: 
     122 | 1) the user registers to the website (data stored in user_temp table) 
     123 | 2) the user gets a registration e-mail with an activation link 
     124 | 3) if the user clicks the activation link (data moved to user table) 
     125 |    he get finally registered and can login with his credentials 
     126 | 
     127 | If set to TRUE: 
     128 | 1) the user registers to the website (data stored in user table) 
     129 | 2) the user can immediately login 
     130 | 3) no e-mail is sent to the user to remember him his credentials 
     131 |    i.e. username and password 
     132 | 
     133 |------------------------------------------------------------------------------ 
     134 */ 
     135 $config['FAL_register_direct'] = FALSE; 
     136  
     137  
     138 /* 
     139 |------------------------------------------------------------------------------ 
     140 | Usernames and passwords config 
     141 |------------------------------------------------------------------------------ 
     142 */ 
    117143 $config['FAL_user_name_min'] = 4;       //min username length 
    118144 $config['FAL_user_name_max'] = 16;      //max username length 
  • FreakAuth/trunk/www/system/application/libraries/FAL_front.php

    r253 r266  
    267267        { 
    268268                        $data['heading'] = $this->CI->lang->line('FAL_register_label'); 
    269                 return $this->CI->load->view($this->CI->config->item('FAL_register_success_view'), $data, TRUE); 
     269                        //normal registration with e-mail validation 
     270                        if (!$this->CI->config->item('FAL_register_direct')) 
     271                        { 
     272                            return $this->CI->load->view($this->CI->config->item('FAL_register_success_view'), $data, TRUE); 
     273                        } 
     274                        //direct registration 
     275                        else 
     276                        { 
     277                            redirect($this->CI->config->item('FAL_login_uri'), 'location'); 
     278                        } 
    270279                        //$this->CI->output->enable_profiler(TRUE); 
    271280        } 
  • FreakAuth/trunk/www/system/application/libraries/FAL_validation.php

    r253 r266  
    197197        //query in main user table (users already activated) 
    198198        $query = $this->CI->UserModel->getUserByUsername($value); 
     199         
    199200        //query in temporary user table (users waiting for activation) 
    200         $fields='id'; 
    201         $where=array('user_name'=>$value); 
    202         $query_temp = $this->CI->UserTemp->getUserTempWhere($fields, $where); 
    203  
    204         if (($query != null) && ($query->num_rows() > 0) OR ($query_temp != null) && ($query_temp->num_rows() > 0)) 
     201        //only if registration with email verification 
     202        if (!$this->CI->config->item('FAL_register_direct')) 
     203        { 
     204            $fields='id'; 
     205            $where=array('user_name'=>$value); 
     206            $query_temp = $this->CI->UserTemp->getUserTempWhere($fields, $where); 
     207        } 
     208         
     209        //setting the right condition depending on registration type 
     210        if ($this->CI->config->item('FAL_register_direct')) 
     211        { 
     212            $condition = (($query != null) && ($query->num_rows() > 0)) ?  TRUE : FALSE; 
     213        } 
     214        else  
     215        { 
     216            $condition = (($query != null) && ($query->num_rows() > 0) OR ($query_temp != null) && ($query_temp->num_rows() > 0)) ? TRUE : FALSE; 
     217        } 
     218         
     219        //checking if condition satisfied 
     220        if ($condition == TRUE) 
    205221            { 
    206222                $this->set_message('username_duplicate_check', $this->CI->lang->line('FAL_in_use_validation_message')); 
    207223                    return false; 
    208224                } 
    209                  
    210                 return true; 
     225                else  
     226                { 
     227                    return true; 
     228                } 
    211229        } 
    212230         
     
    229247         
    230248        //query in temporary user table (users waiting for activation) 
    231         $fields='id'; 
    232         $where = array('user_name'=>$value); 
    233         $query_temp = $this->CI->UserTemp->getUserTemp($fields, $limit=null, $where); 
    234          
    235  
    236         if (($query != null) && ($query->num_rows() > 0) OR ($query_temp != null) && ($query_temp->num_rows() > 0)) 
     249        //only if registration with email verification 
     250        if (!$this->CI->config->item('FAL_register_direct')) 
     251        { 
     252            $fields='id'; 
     253            $where = array('user_name'=>$value); 
     254            $query_temp = $this->CI->UserTemp->getUserTemp($fields, $limit=null, $where); 
     255        } 
     256         
     257        //setting the right condition depending on registration type 
     258        if ($this->CI->config->item('FAL_register_direct')) 
     259        { 
     260            $condition = (($query != null) && ($query->num_rows() > 0)) ?  TRUE : FALSE; 
     261        } 
     262        else  
     263        { 
     264            $condition = (($query != null) && ($query->num_rows() > 0) OR ($query_temp != null) && ($query_temp->num_rows() > 0)) ? TRUE : FALSE; 
     265        } 
     266         
     267        //checking if condition satisfied 
     268        if ($condition == TRUE) 
    237269            { 
    238270                $this->set_message('username_backend_duplicate_check', $this->CI->lang->line('FAL_in_use_validation_message')); 
    239271                    return false; 
    240                 } 
    241                  
    242                 return true; 
     272            } 
     273            else 
     274            { 
     275                return true; 
     276            } 
    243277        } 
    244278         
     
    258292        //query in main user table (users already activated) 
    259293        $query = $this->CI->UserModel->getUserForForgottenPassword($value); 
    260         //query in temporary user table (users waiting for activation) 
    261                 $fields='id'; 
    262         $where=array('email'=>$value); 
    263         $query_temp = $this->CI->UserTemp->getUserTempWhere($fields, $where); 
    264294         
    265295        if (($query != null) && ($query->num_rows() > 0)) 
     
    269299                } 
    270300                 
    271                  if (($query_temp != null) && ($query_temp->num_rows() > 0)) 
    272             { 
    273                 $this->set_message('email_duplicate_check', $this->CI->lang->line('FAL_usertemp_email_duplicate')); 
    274                     return false; 
    275                 } 
    276                  
    277                  
     301        //query in temporary user table (users waiting for activation) 
     302        //only if registration with email verification 
     303        if (!$this->CI->config->item('FAL_register_direct')) 
     304        { 
     305                $fields='id'; 
     306            $where=array('email'=>$value); 
     307            $query_temp = $this->CI->UserTemp->getUserTempWhere($fields, $where); 
     308             
     309            if (($query_temp != null) && ($query_temp->num_rows() > 0)) 
     310            { 
     311                $this->set_message('email_duplicate_check', $this->CI->lang->line('FAL_usertemp_email_duplicate')); 
     312                    return false; 
     313                } 
     314        } 
     315         
    278316                return true; 
    279317        } 
     
    298336        $query = $this->CI->UserModel->getUsers($fields, $limit=null, $where); 
    299337 
    300          
    301         //query in temporary user table (users waiting for activation) 
    302         //query in main user table (users already activated) 
    303              $fields='id'; 
    304                  $where = array('email'=>$value); 
    305          $query_temp = $this->CI->UserTemp->getUserTemp($fields, $limit=null, $where); 
    306  
    307                  
    308338        if (($query != null) && ($query->num_rows() > 0)) 
    309339            { 
    310340                $this->set_message('email_backend_duplicate_check', $this->CI->lang->line('FAL_user_email_duplicate')); 
    311                      
    312341                $query->free_result(); 
    313342                return false; 
    314343                } 
    315344                 
    316                  if (($query_temp != null) && ($query_temp->num_rows() > 0)) 
    317             { 
    318                 $this->set_message('email_backend_duplicate_check', $this->CI->lang->line('FAL_usertemp_email_duplicate')); 
    319                      
    320                 $query_temp->free_result(); 
    321                 return false; 
    322                 } 
    323                  
    324                  
    325                 //return true; 
     345        //query in temporary user table (users waiting for activation) 
     346        //only if registration with email verification 
     347        if (!$this->CI->config->item('FAL_register_direct')) 
     348        { 
     349            $fields='id'; 
     350            $where=array('email'=>$value); 
     351            $query_temp = $this->CI->UserTemp->getUserTempWhere($fields, $where); 
     352             
     353            if (($query_temp != null) && ($query_temp->num_rows() > 0)) 
     354            { 
     355                $this->set_message('email_backend_duplicate_check', $this->CI->lang->line('FAL_usertemp_email_duplicate')); 
     356                     
     357                $query_temp->free_result(); 
     358                return false; 
     359                } 
     360        } 
     361                 
     362        return true; 
    326363        } 
    327364         
  • FreakAuth/trunk/www/system/application/libraries/Freakauth_light.php

    r265 r266  
    6969        * Function FreakAuth inizialises the class loading the right libraries, helpers and models 
    7070        *  
    71         * @uses libraries (encrypt, db_session), helpers (form, url, FreakAuth), modules (Usermodel) 
     71        * @uses libraries (encrypt, db_session), helpers (form, url, FreakAuth), modules (usermodel) 
    7272        * */ 
    7373    function Freakauth_light() 
     
    8282        $this->CI->load->helper('freakauth_light'); 
    8383        $this->CI->load->model('FreakAuth_light/usertemp', 'UserTemp'); 
    84         $this->CI->load->model('Usermodel', 'usermodel'); 
     84        $this->CI->load->model('usermodel', 'usermodel'); 
    8585        if($this->CI->config->item('FAL_create_user_profile')) 
    8686            $this->CI->load->model('Userprofile', 'userprofile'); 
     
    192192     * 
    193193     * else displays the FAL_denied_page (see config file) 
    194      * 
    195      * @param $role : the role of the one we are denying the access 
     194     * ------------------------------- 
     195     * EXAMPLE USAGE (in a controller) 
     196     * ------------------------------- 
     197     * $this->freakauth_light->denyAccess('user') 
     198     *  
     199     * @param string the role of the one we are denying the access 
    196200     */ 
    197201    function denyAccess($role) 
     
    312316     * Returns true if a valid user is logged, false otherwise 
    313317     *  
    314      * @return unknow
     318     * @return boolea
    315319     */ 
    316320    function isValidUser() 
     
    509513    { 
    510514        //let's clean the user_temp table 
    511         $this->cleanExpiredUserTemp(); 
     515        //if we use registration with e-mail verification 
     516        if (!$this->CI->config->item('FAL_register_direct')) 
     517        { 
     518           $this->cleanExpiredUserTemp(); 
     519        } 
    512520         
    513521        //let's check if the system is turned on and if we allow users to register 
     
    527535                $password_email=$password; 
    528536                $password = $this->_encode($password); 
    529                 $activation_code = $this->_generateRandomString(50, 50); 
    530  
    531                 $values['password'] = $password; 
    532                 $values['activation_code'] = $activation_code; 
    533  
    534                 $query = $this->CI->UserTemp->insertUserForRegistration($values); 
    535  
    536                 //Use the input username and password and check against 'users' table 
    537                 $query = $this->CI->UserTemp->getUserLoginData($username, $password); 
    538  
    539                 $user_id = 0; 
    540                 if (($query != null) && ($query->num_rows() > 0)) 
     537                 
     538                //reassignement to the encoded password 
     539                $values['password'] = $password; 
     540                 
     541                //if we go for standard activation with e-mail verification 
     542                //namely i.e. $config['FAL_register_direct'] = FALSE 
     543                if (!$this->CI->config->item('FAL_register_direct')) 
    541544                { 
    542                     $row = $query->row(); 
    543                     $user_id = $row->id; 
    544  
    545                     $this->_sendActivationEmail($user_id, $username, $password_email, $email, $activation_code); 
    546  
    547                     return true; 
     545                    //generates the activation code 
     546                    $activation_code = $this->_generateRandomString(); 
     547                    $values['activation_code'] = $activation_code; 
     548                    $query = $this->CI->UserTemp->insertUserForRegistration($values); 
     549                     
     550                    //Use the input username and password and check against 'user_temp' table 
     551                    //needed to find the user_temp ID for the activation link 
     552                    $query = $this->CI->UserTemp->getUserLoginData($username, $password); 
     553 
     554                    $user_id = 0; 
     555                    if (($query != null) && ($query->num_rows() > 0)) 
     556                    { 
     557                        $row = $query->row(); 
     558                        $user_id = $row->id; 
     559     
     560                        $this->_sendActivationEmail($user_id, $username, $password_email, $email, $activation_code); 
     561     
     562                        return true; 
     563                    } 
     564                } 
     565                //do we skipp e-mail verification? 
     566                //namely if we go for direct activation i.e. $config['FAL_register_direct'] = TRUE 
     567                else  
     568                { 
     569                    //let's insert the values in the user table 
     570                    $query = $this->CI->usermodel->insertUser($values); 
     571                     
     572                    //if affected rows ==1 set a flash message and redirect to login 
     573                    if ($this->CI->db->affected_rows() == 1) 
     574                    { 
     575                        //if we want the user profile as well 
     576                        if($this->CI->config->item('FAL_create_user_profile')) 
     577                        {        
     578                                //let's get the last insert id 
     579                                $data_profile['id'] = $this->CI->db->insert_id(); 
     580                                $this->CI->userprofile->insertUserProfile($data_profile); 
     581                        } 
     582                         
     583                        flashMsg( $this->CI->lang->line('FAL_activation_success_message') ); 
     584                        return true;  
     585                    } 
     586                     
     587                      
    548588                } 
    549589            } 
    550         } 
    551                  
    552         //set FLASH MESSAGE 
    553         flashMsg( $this->CI->lang->line('FAL_invalid_register_message') ); 
    554         // FIXME : if false is returned, no redirection is done in FAL_front 
    555         return false; 
     590            else  
     591            { 
     592                //set FLASH MESSAGE 
     593                flashMsg( $this->CI->lang->line('FAL_invalid_register_message') ); 
     594                // FIXME : if false is returned, no redirection is done in FAL_front 
     595                return false; 
     596            } 
     597        } 
    556598    } 
    557599     
     
    569611    {    
    570612        //let's clean the user_temp table 
    571         $this->cleanExpiredUserTemp(); 
     613        //if we use registration with e-mail verification 
     614        if (!$this->CI->config->item('FAL_register_direct')) 
     615        { 
     616           $this->cleanExpiredUserTemp(); 
     617        } 
    572618                 
    573619        if (($id > 0) && ($activation_code != '')) 
     
    670716                /** 
    671717                 * recalls the function getUserForForgottenPasswordReset($id, $activation_code) 
    672                  * from the class Usermodel 
     718                 * from the class usermodel 
    673719                 * it queries the database looking for the user's $id and $activation_code 
    674720                 */ 
     
    13481394                 
    13491395} 
    1350  
    1351 ?> 
  • FreakAuth/trunk/www/system/application/models/FreakAuth_light/usertemp.php

    r229 r266  
    147147        function getUserTempCreated() 
    148148        {        
    149                 return$this->db->query('SELECT id AS id, UNIX_TIMESTAMP(created) AS created FROM '.$this->_table); 
     149                return $this->db->query('SELECT id AS id, UNIX_TIMESTAMP(created) AS created FROM '.$this->_table); 
    150150                  
    151151        }