Changeset 106

Show
Ignore:
Timestamp:
04/19/07 04:45:59
Author:
danfreak
Message:

"FAL: backend validation=> moved functions from controllers to FAL_validation library, edited views FreakAuth/admin/users/edit and FreakAuth/admin/users/add for complaince with FAL_validation lib, corrected 1 bug in password_backend_check function"

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • FreakAuth/trunk/www/system/application/controllers/admin/admins.php

    r99 r106  
    66 * requests.  It also can verify the logged in status of a user and his permissions. 
    77 * 
    8  * The class requires the use of the DB_Session and FreakAuth libraries. 
     8 * The class requires the use of the DB_Session, FAL_validation and FreakAuth libraries. 
    99 * 
    1010 * @package     FreakAuth 
     
    4848        $this->lang->load('freakauth'); 
    4949        $this->load->model('FreakAuth_light/usermodel', 'usermodel'); 
    50         $this->load->library('validation'); 
    51                 $this->validation->set_error_delimiters($this->config->item('FAL_error_delimiter_open'), $this->config->item('FAL_error_delimiter_close')); 
     50        //lets load the validation class if it hasn't been already loaded 
     51        //it is needed by the FAL_validation library 
     52        if ( ! class_exists('CI_Validation')) 
     53                { 
     54                     $this->load->library('validation'); 
     55                } 
     56        $this->load->library('FAL_validation', 'fal_validation'); 
     57                $this->fal_validation->set_error_delimiters($this->config->item('FAL_error_delimiter_open'), $this->config->item('FAL_error_delimiter_close')); 
    5258 
    5359                //sets the necessary form fields 
     
    6773        //additionalFields($fields); 
    6874         
    69         $this->validation->set_fields($fields); 
     75        $this->fal_validation->set_fields($fields); 
    7076         
    7177    } 
     
    217223    {       
    218224        //set validation rules 
    219         $rules['user_name'] = 'trim|required|xss_clean|callback__username_check|callback__username_duplicate_check'; 
    220         $rules['password'] = 'trim|required|xss_clean|callback__password_check'; 
     225        $rules['user_name'] = 'trim|required|xss_clean|username_check|username_backend_duplicate_check'; 
     226        $rules['password'] = 'trim|required|xss_clean|password_backend_check'; 
    221227        $rules['password_confirm'] = "trim|required|xss_clean|matches[password]"; 
    222         $rules['email'] = 'trim|required|valid_email|xss_clean|callback__email_duplicate_check'; 
     228        $rules['email'] = 'trim|required|valid_email|xss_clean|email_backend_duplicate_check'; 
    223229        $rules['role'] = 'required'; 
    224230        $rules['banned'] = 'is_numeric'; 
    225231         
    226         $this->validation->set_message('is_numeric', 'must be numeric'); 
     232        $this->fal_validation->set_message('is_numeric', 'must be numeric'); 
    227233        //do we want to set the country? 
    228234        //(looks what we set in the freakauth_light.php config) 
     
    239245                    $fields = $data['fields'];  
    240246                     
    241                     $this->validation->set_rules($rules_profile); 
     247                    $this->fal_validation->set_rules($rules_profile); 
    242248                         
    243                     $this->validation->set_fields($fields); 
     249                    $this->fal_validation->set_fields($fields); 
    244250                } 
    245251                         
    246         $this->validation->set_rules($rules); 
     252        $this->fal_validation->set_rules($rules); 
    247253        
    248254         
    249255         
    250256        //if validation unsuccesfull & data not ok 
    251         if ($this->validation->run() == FALSE) 
     257        if ($this->fal_validation->run() == FALSE) 
    252258                { 
    253259                        //$countries = null;             
     
    311317         
    312318        //set validation rules 
    313         $rules['user_name'] = 'trim|required|xss_clean|callback__username_check|callback__username_duplicate_check'; 
    314         $rules['password'] = 'trim|xss_clean|callback__password_check'; 
     319        $rules['user_name'] = 'trim|required|xss_clean|username_check|username_backend_duplicate_check'; 
     320        $rules['password'] = 'trim|xss_clean|password_backend_check'; 
    315321        $rules['password_confirm'] = "trim|xss_clean|matches[password]"; 
    316         $rules['email'] = 'trim|required|valid_email|xss_clean|callback__email_duplicate_check'; 
     322        $rules['email'] = 'trim|required|valid_email|xss_clean|email_backend_duplicate_check'; 
    317323        $rules['role'] = 'required'; 
    318324        $rules['banned'] = 'is_numeric'; 
    319325         
    320326         
    321         $this->validation->set_message('is_numeric', 'must be numeric'); 
     327        $this->fal_validation->set_message('is_numeric', 'must be numeric'); 
    322328        //do we want to set the country? 
    323329        //(looks what we set in the freakauth_light.php config) 
     
    334340                    $fields = $data['fields'];  
    335341                     
    336                     $this->validation->set_rules($rules_profile); 
    337                      
    338                 } 
    339          
    340         $this->validation->set_message('is_numeric', 'must be numeric'); 
    341          
    342         $this->validation->set_rules($rules); 
     342                    $this->fal_validation->set_rules($rules_profile); 
     343                     
     344                } 
     345         
     346        $this->fal_validation->set_message('is_numeric', 'must be numeric'); 
     347         
     348        $this->fal_validation->set_rules($rules); 
    343349         
    344350        //id field needed for validation 
     
    346352        $fields['role'] = 'role'; 
    347353         
    348         $this->validation->set_fields($fields); 
     354        $this->fal_validation->set_fields($fields); 
    349355         
    350356                $data['role_options'] = array_keys($this->config->item('FAL_roles')); 
     
    388394            } 
    389395                         
    390                 if ($this->validation->run() == FALSE) 
     396                if ($this->fal_validation->run() == FALSE) 
    391397        { 
    392398                $data['heading'] = 'Admin management'; 
     
    554560        return false; 
    555561    } 
    556      
    557     // -------------------------------------------------------------------- 
    558          
    559     /** 
    560      * RULES HELPER FUNCTION 
    561      * 
    562      * @param form value $value 
    563      * @return boolean 
    564      */ 
    565         function _password_check($value) 
    566         {        
    567                 if ($value='' AND isset($_POST['id'])) 
    568                 { 
    569                         $callback = '_password_check'; 
    570                         return $this->_is_valid_text($callback, $value, $this->config->item('FAL_user_password_min'), $this->config->item('FAL_user_password_max')); 
    571                 } 
    572             
    573         } 
    574          
    575         // -------------------------------------------------------------------- 
    576  
    577     /** 
    578      * RULES HELPER FUNCTION 
    579      * User name validation callback for validation against min-max length settings 
    580      * 
    581      * @access private 
    582      * @param varchar $value 
    583      * @return boolean 
    584      */ 
    585     function _username_check($value) 
    586         {        
    587                 $callback = '_username_check'; 
    588             return $this->_is_valid_text($callback, $value, $this->config->item('FAL_user_name_min'), $this->config->item('FAL_user_name_max')); 
    589         } 
    590          
    591         // -------------------------------------------------------------------- 
    592          
    593     /** 
    594      * RULES HELPER FUNCTION 
    595      * User name duplicate validation callback for validation against duplicate username in DB 
    596      * 
    597      * @access private 
    598      * @param varchar $value 
    599      * @return boolean 
    600      */ 
    601     function _username_duplicate_check($value) 
    602         { 
    603                 //checks if the request comes from add or edit actions 
    604         $fields='id'; 
    605                 isset($_POST['id']) ? $where = array('id !='=> $_POST['id'], 'user_name'=>$value) : $where=null; 
    606         $query = $this->usermodel->getUsers($fields, $limit=null, $where); 
    607          
    608         //checks if the request comes from add or edit actions 
    609         //query in temporary user table (users waiting for activation) 
    610         $this->load->model('FreakAuth_light/UserTemp'); 
    611         $fields='id'; 
    612         isset($_POST['id']) ? $where = array('id !='=> $_POST['id'], 'user_name'=>$value) : $where=null; 
    613         $query_temp = $this->UserTemp->getUserTemp($fields, $limit=null, $where); 
    614          
    615  
    616         if (($query != null) && ($query->num_rows() > 0) OR ($query_temp != null) && ($query_temp->num_rows() > 0)) 
    617             { 
    618                 $this->validation->set_message('_username_duplicate_check', $this->lang->line('FAL_in_use_validation_message')); 
    619                     return false; 
    620                 } 
    621                  
    622                 return true; 
    623         } 
    624                  
    625          
    626         // -------------------------------------------------------------------- 
    627          
    628     /** 
    629      * RULES HELPER FUNCTION 
    630      * User name duplicate validation callback for validation against duplicate username in DB 
    631      * 
    632      * @access private 
    633      * @param varchar $value 
    634      * @return boolean 
    635      */ 
    636     function _email_duplicate_check($value) 
    637         {        
    638                 //Use the input e-mail and check against 'users' table 
    639             //checks if the request comes from add or edit actions 
    640                 //query in main user table (users already activated) 
    641             $fields='id'; 
    642                 isset($_POST['id']) ? $where = array('id !='=> $_POST['id'], 'email'=>$value) : $where=null; 
    643         $query = $this->usermodel->getUsers($fields, $limit=null, $where); 
    644  
    645          
    646         //query in temporary user table (users waiting for activation) 
    647         //checks if the request comes from add or edit actions 
    648         //query in main user table (users already activated) 
    649              $this->load->model('FreakAuth_light/UserTemp'); 
    650              $fields='id'; 
    651                  isset($_POST['id']) ? $where = array('id !='=> $_POST['id'], 'email'=>$value) : $where=null; 
    652          $query_temp = $this->UserTemp->getUserTemp($fields, $limit=null, $where); 
    653  
    654                  
    655         if (($query != null) && ($query->num_rows() > 0)) 
    656             { 
    657                 $this->validation->set_message('_email_duplicate_check', $this->lang->line('FAL_user_email_duplicate')); 
    658                      
    659                 $query->free_result(); 
    660                 return false; 
    661                 } 
    662                  
    663                  if (($query_temp != null) && ($query_temp->num_rows() > 0)) 
    664             { 
    665                 $this->validation->set_message('_email_duplicate_check', $this->lang->line('FAL_usertemp_email_duplicate')); 
    666                      
    667                 $query_temp->free_result(); 
    668                 return false; 
    669                 } 
    670                  
    671                  
    672                 //return true; 
    673         } 
    674          
    675          
    676         // -------------------------------------------------------------------- 
    677          
    678     /** 
    679      * RULES HELPER FUNCTION 
    680      * Checks if a country has been chosen in the select country form element 
    681      * 
    682      * @access private 
    683      * @param varchar $value 
    684      * @return boolean 
    685      */ 
    686     function _country_check($country_id) 
    687         { 
    688             if ($this->config->item('FAL_use_country')) 
    689             { 
    690             if ($country_id == 0) 
    691             { 
    692                 $this->validation->country_id= $country_id; 
    693                 $this->validation->set_message('_country_check', 'Please specify a country'); 
    694                     return FALSE; 
    695                 } 
    696         } 
    697                  
    698                 return true; 
    699         } 
    700          
    701         // -------------------------------------------------------------------- 
    702          
    703     /** 
    704      * RULES HELPER FUNCTION 
    705      * Determines if a input text has valid characters and meets min/max length requirements 
    706      * 
    707      * @access private 
    708      * @param unknown_type $callback 
    709      * @param varchar $value 
    710      * @param integer $min 
    711      * @param integer $max 
    712      * @param varchar $invalid_message 
    713      * @param unknown_type $expression 
    714      * @return boolean 
    715      */ 
    716     function _is_valid_text($callback, $value, $min, $max, $invalid_message = null, $expression = '/^([a-z0-9])([a-z0-9_\-])*$/ix') 
    717         { 
    718             $message = ''; 
    719             if ((strlen($value) < $min) || 
    720                 (strlen($value) > $max)) 
    721                 $message .= sprintf($this->lang->line('FAL_lenght_validation_message'), $min, $max); 
    722                  
    723             if (!preg_match($expression, $value)) 
    724                 $message .= $this->lang->line('FAL_allowed_characters_validation_message'); 
    725                  
    726                 if ($message != '') 
    727                 { 
    728                     if (!isset($invalid_message)) 
    729                         $invalid_message = $this->lang->line('FAL_invalid_validation_message'); 
    730                     $this->validation->set_message($callback, $invalid_message.$message); 
    731                 return false; 
    732                 } 
    733                  
    734                 return true; 
    735         } 
    736562} 
    737563?> 
  • FreakAuth/trunk/www/system/application/controllers/admin/users.php

    r99 r106  
    66 * requests.  It also can verify the logged in status of a user and his permissions. 
    77 * 
    8  * The class requires the use of the DB_Session and FreakAuth libraries. 
     8 * The class requires the use of the DB_Session, FAL_validation and FreakAuth libraries. 
    99 * 
    1010 * @package     FreakAuth 
     
    4747        $this->lang->load('freakauth'); 
    4848        $this->load->model('FreakAuth_light/usermodel', 'usermodel'); 
    49         $this->load->library('validation'); 
    50                 $this->validation->set_error_delimiters($this->config->item('FAL_error_delimiter_open'), $this->config->item('FAL_error_delimiter_close')); 
     49        //lets load the validation class if it hasn't been already loaded 
     50        //it is needed by the FAL_validation library 
     51        if ( ! class_exists('CI_Validation')) 
     52                { 
     53                     $this->load->library('validation'); 
     54                } 
     55        $this->load->library('FAL_validation', 'fal_validation'); 
     56                $this->fal_validation->set_error_delimiters($this->config->item('FAL_error_delimiter_open'), $this->config->item('FAL_error_delimiter_close')); 
    5157 
    5258                //sets the necessary form fields 
     
    6672        //additionalFields($fields); 
    6773         
    68         $this->validation->set_fields($fields); 
     74        $this->fal_validation->set_fields($fields); 
    6975         
    7076    } 
     
    218224    {       
    219225        //set validation rules 
    220         $rules['user_name'] = 'trim|required|xss_clean|callback__username_check|callback__username_duplicate_check'; 
    221         $rules['password'] = 'trim|required|xss_clean|callback__password_check'; 
     226        $rules['user_name'] = 'trim|required|xss_clean|username_check|username_backend_duplicate_check'; 
     227        $rules['password'] = 'trim|required|xss_clean|password_backend_check'; 
    222228        $rules['password_confirm'] = "trim|required|xss_clean|matches[password]"; 
    223         $rules['email'] = 'trim|required|valid_email|xss_clean|callback__email_duplicate_check'; 
     229        $rules['email'] = 'trim|required|valid_email|xss_clean|email_backend_duplicate_check'; 
    224230        $rules['role'] = 'trim|required'; 
    225231        $rules['banned'] = 'is_numeric'; 
    226232         
    227         $this->validation->set_message('is_numeric', 'must be numeric'); 
     233        $this->fal_validation->set_message('is_numeric', 'must be numeric'); 
    228234        //do we want to set the country? 
    229235        //(looks what we set in the freakauth_light.php config) 
     
    240246                    $fields = $data['fields'];  
    241247                     
    242                     $this->validation->set_rules($rules_profile); 
     248                    $this->fal_validation->set_rules($rules_profile); 
    243249                         
    244                     $this->validation->set_fields($fields); 
     250                    $this->fal_validation->set_fields($fields); 
    245251                } 
    246252                         
    247         $this->validation->set_rules($rules); 
     253        $this->fal_validation->set_rules($rules); 
    248254        
    249255         
    250256         
    251257        //if validation unsuccesfull & data not ok 
    252         if ($this->validation->run() == FALSE) 
     258        if ($this->fal_validation->run() == FALSE) 
    253259                { 
    254260                        //$countries = null;             
     
    324330         
    325331        //set validation rules 
    326         $rules['user_name'] = 'trim|required|xss_clean|callback__username_check|callback__username_duplicate_check'; 
    327         $rules['password'] = 'trim|xss_clean|callback__password_check'; 
     332        $rules['user_name'] = 'trim|required|xss_clean|username_check|username_backend_duplicate_check'; 
     333        $rules['password'] = 'trim|xss_clean|password_backend_check'; 
    328334        $rules['password_confirm'] = "trim|xss_clean|matches[password]"; 
    329         $rules['email'] = 'trim|required|valid_email|xss_clean|callback__email_duplicate_check'; 
     335        $rules['email'] = 'trim|required|valid_email|xss_clean|email_backend_duplicate_check'; 
    330336        $rules['role'] = 'required'; 
    331337        $rules['banned'] = 'is_numeric'; 
    332338         
    333339         
    334         $this->validation->set_message('is_numeric', 'must be numeric'); 
     340        $this->fal_validation->set_message('is_numeric', 'must be numeric'); 
    335341        //do we want to set the country? 
    336342        //(looks what we set in the freakauth_light.php config) 
     
    347353                    $fields = $data['fields'];  
    348354                     
    349                     $this->validation->set_rules($rules_profile); 
    350                      
    351                 } 
    352          
    353         $this->validation->set_message('is_numeric', 'must be numeric'); 
    354          
    355         $this->validation->set_rules($rules); 
     355                    $this->fal_validation->set_rules($rules_profile); 
     356                     
     357                } 
     358         
     359        $this->fal_validation->set_message('is_numeric', 'must be numeric'); 
     360         
     361        $this->fal_validation->set_rules($rules); 
    356362         
    357363        //id field needed for validation 
     
    359365        $fields['role'] = 'role'; 
    360366         
    361         $this->validation->set_fields($fields); 
     367        $this->fal_validation->set_fields($fields); 
    362368         
    363369                $data['role_options'] = array_keys($this->config->item('FAL_roles')); 
     
    401407            } 
    402408                         
    403                 if ($this->validation->run() == FALSE) 
     409                if ($this->fal_validation->run() == FALSE) 
    404410        { 
    405411                $data['heading'] = 'Users management'; 
     
    547553        return false; 
    548554    } 
    549      
    550     // -------------------------------------------------------------------- 
    551          
    552     /** 
    553      * RULES HELPER FUNCTION 
    554      * 
    555      * @param form value $value 
    556      * @return boolean 
    557      */ 
    558         function _password_check($value) 
    559         {        
    560                 if ($value='' AND isset($_POST['id'])) 
    561                 { 
    562                         $callback = '_password_check'; 
    563                         return $this->_is_valid_text($callback, $value, $this->config->item('FAL_user_password_min'), $this->config->item('FAL_user_password_max')); 
    564                 } 
    565             
    566         } 
    567          
    568         // -------------------------------------------------------------------- 
    569  
    570     /** 
    571      * RULES HELPER FUNCTION 
    572      * User name validation callback for validation against min-max length settings 
    573      * 
    574      * @access private 
    575      * @param varchar $value 
    576      * @return boolean 
    577      */ 
    578     function _username_check($value) 
    579         {        
    580                 $callback = '_username_check'; 
    581             return $this->_is_valid_text($callback, $value, $this->config->item('FAL_user_name_min'), $this->config->item('FAL_user_name_max')); 
    582         } 
    583          
    584         // -------------------------------------------------------------------- 
    585          
    586     /** 
    587      * RULES HELPER FUNCTION 
    588      * User name duplicate validation callback for validation against duplicate username in DB 
    589      * 
    590      * @access private 
    591      * @param varchar $value 
    592      * @return boolean 
    593      */ 
    594     function _username_duplicate_check($value) 
    595         { 
    596                 //checks if the request comes from add or edit actions 
    597         $fields='id'; 
    598                 isset($_POST['id']) ? $where = array('id !='=> $_POST['id'], 'user_name'=>$value) : $where=null; 
    599         $query = $this->usermodel->getUsers($fields, $limit=null, $where); 
    600          
    601         //checks if the request comes from add or edit actions 
    602         //query in temporary user table (users waiting for activation) 
    603         $this->load->model('FreakAuth_light/UserTemp'); 
    604         $fields='id'; 
    605         isset($_POST['id']) ? $where = array('id !='=> $_POST['id'], 'user_name'=>$value) : $where=null; 
    606         $query_temp = $this->UserTemp->getUserTemp($fields, $limit=null, $where); 
    607          
    608  
    609         if (($query != null) && ($query->num_rows() > 0) OR ($query_temp != null) && ($query_temp->num_rows() > 0)) 
    610             { 
    611                 $this->validation->set_message('_username_duplicate_check', $this->lang->line('FAL_in_use_validation_message')); 
    612                     return false; 
    613                 } 
    614                  
    615                 return true; 
    616         } 
    617                  
    618          
    619         // -------------------------------------------------------------------- 
    620          
    621     /** 
    622      * RULES HELPER FUNCTION 
    623      * User name duplicate validation callback for validation against duplicate username in DB 
    624      * 
    625      * @access private 
    626      * @param varchar $value 
    627      * @return boolean 
    628      */ 
    629     function _email_duplicate_check($value) 
    630         {        
    631                 //Use the input e-mail and check against 'users' table 
    632             //checks if the request comes from add or edit actions 
    633                 //query in main user table (users already activated) 
    634             $fields='id'; 
    635                 isset($_POST['id']) ? $where = array('id !='=> $_POST['id'], 'email'=>$value) : $where=null; 
    636         $query = $this->usermodel->getUsers($fields, $limit=null, $where); 
    637  
    638          
    639         //query in temporary user table (users waiting for activation) 
    640         //checks if the request comes from add or edit actions 
    641         //query in main user table (users already activated) 
    642              $this->load->model('FreakAuth_light/UserTemp'); 
    643              $fields='id'; 
    644                  isset($_POST['id']) ? $where = array('id !='=> $_POST['id'], 'email'=>$value) : $where=null; 
    645          $query_temp = $this->UserTemp->getUserTemp($fields, $limit=null, $where); 
    646  
    647                  
    648         if (($query != null) && ($query->num_rows() > 0)) 
    649             { 
    650                 $this->validation->set_message('_email_duplicate_check', $this->lang->line('FAL_user_email_duplicate')); 
    651                      
    652                 $query->free_result(); 
    653                 return false; 
    654                 } 
    655                  
    656                  if (($query_temp != null) && ($query_temp->num_rows() > 0)) 
    657             { 
    658                 $this->validation->set_message('_email_duplicate_check', $this->lang->line('FAL_usertemp_email_duplicate')); 
    659                      
    660                 $query_temp->free_result(); 
    661                 return false; 
    662                 } 
    663                  
    664                  
    665                 //return true; 
    666         } 
    667          
    668          
    669         // -------------------------------------------------------------------- 
    670          
    671     /** 
    672      * RULES HELPER FUNCTION 
    673      * Checks if a country has been chosen in the select country form element 
    674      * 
    675      * @access private 
    676      * @param varchar $value 
    677      * @return boolean 
    678      */ 
    679     function _country_check($country_id) 
    680         { 
    681             if ($this->config->item('FAL_use_country')) 
    682             { 
    683             if ($country_id == 0) 
    684             { 
    685                 $this->validation->country_id= $country_id; 
    686                 $this->validation->set_message('_country_check', 'Please specify a country'); 
    687                     return FALSE; 
    688                 } 
    689         } 
    690                  
    691                 return true; 
    692         } 
    693          
    694         // -------------------------------------------------------------------- 
    695          
    696     /** 
    697      * RULES HELPER FUNCTION 
    698      * Determines if a input text has valid characters and meets min/max length requirements 
    699      * 
    700      * @access private 
    701      * @param unknown_type $callback 
    702      * @param varchar $value 
    703      * @param integer $min 
    704      * @param integer $max 
    705      * @param varchar $invalid_message 
    706      * @param unknown_type $expression 
    707      * @return boolean 
    708      */ 
    709     function _is_valid_text($callback, $value, $min, $max, $invalid_message = null, $expression = '/^([a-z0-9])([a-z0-9_\-])*$/ix') 
    710         { 
    711             $message = ''; 
    712             if ((strlen($value) < $min) || 
    713                 (strlen($value) > $max)) 
    714                 $message .= sprintf($this->lang->line('FAL_lenght_validation_message'), $min, $max); 
    715                  
    716             if (!preg_match($expression, $value)) 
    717                 $message .= $this->lang->line('FAL_allowed_characters_validation_message'); 
    718                  
    719                 if ($message != '') 
    720                 { 
    721                     if (!isset($invalid_message)) 
    722                         $invalid_message = $this->lang->line('FAL_invalid_validation_message'); 
    723                     $this->validation->set_message($callback, $invalid_message.$message); 
    724                 return false; 
    725                 } 
    726                  
    727                 return true; 
    728         } 
    729555} 
    730556?> 
  • FreakAuth/trunk/www/system/application/libraries/FAL_validation.php

    r93 r106  
    3838 * @license                     http://www.gnu.org/licenses/lgpl.html 
    3939 * @link                        http://www.ciforge.com/freakauth/ 
    40  * @todo                        Optimization 
     40 * @todo                        eliminate some hardcoded languages, check validation against user_temp table 
    4141 * @version             1.0.3 
    4242 * @tutorial        http://www.ciforge.com/trac/freakauth/wiki/FreakAuthDoc 
     
    7171                $callback = 'password_check'; 
    7272            return $this->is_valid_text($callback, $value, $this->CI->config->item('FAL_user_password_min'), $this->CI->config->item('FAL_user_password_max')); 
     73        } 
     74         
     75        // -------------------------------------------------------------------- 
     76         
     77    /** 
     78     * Rule used in admin backend: it get applyed only if the password field 
     79     * has a value, namely if the password get changed 
     80     * 
     81     * @param form value $value 
     82     * @return boolean 
     83     */ 
     84        function password_backend_check($value) 
     85        {        
     86                if ($value!='' AND isset($_POST['id'])) 
     87                { 
     88                        $callback = 'password_backend_check'; 
     89                        return $this->is_valid_text($callback, $value, $this->CI->config->item('FAL_user_password_min'), $this->CI->config->item('FAL_user_password_max')); 
     90                } 
     91            
    7392        } 
    7493         
     
    228247        $query = $this->CI->UserModel->getUserByUsername($value); 
    229248        //query in temporary user table (users waiting for activation) 
    230         $this->load->model('Usertemp', 'UserTemp'); 
    231249        $fields='id'; 
    232250        $where=array('user_name'=>$value); 
    233         $query_temp = $this->UserTemp->getUserTempWhere($fields, $where); 
     251        $query_temp = $this->CI->UserTemp->getUserTempWhere($fields, $where); 
    234252 
    235253        if (($query != null) && ($query->num_rows() > 0) OR ($query_temp != null) && ($query_temp->num_rows() > 0)) 
    236254            { 
    237255                $this->set_message('username_duplicate_check', $this->CI->lang->line('FAL_in_use_validation_message')); 
     256                    return false; 
     257                } 
     258                 
     259                return true; 
     260        } 
     261         
     262        // -------------------------------------------------------------------- 
     263         
     264    /** 
     265     * User name duplicate validation callback for validation against duplicate username in DB. 
     266     * Used in backend. 
     267     * 
     268     * @access private 
     269     * @param varchar $value 
     270     * @return boolean 
     271     */ 
     272    function username_backend_duplicate_check($value) 
     273        { 
     274                //checks if the request comes from add or edit actions 
     275        $fields='id'; 
     276                $where= isset($_POST['id']) ? array('id !='=> $_POST['id'], 'user_name'=>$value) : null; 
     277        $query = $this->CI->UserModel->getUsers($fields, $limit=null, $where); 
     278         
     279        //checks if the request comes from add or edit actions 
     280        //query in temporary user table (users waiting for activation) 
     281        $fields='id'; 
     282        $where = isset($_POST['id']) ?  array('id !='=> $_POST['id'], 'user_name'=>$value) : null; 
     283        $query_temp = $this->CI->UserTemp->getUserTemp($fields, $limit=null, $where); 
     284         
     285 
     286        if (($query != null) && ($query->num_rows() > 0) OR ($query_temp != null) && ($query_temp->num_rows() > 0)) 
     287            { 
     288                $this->set_message('username_backend_duplicate_check', $this->CI->lang->line('FAL_in_use_validation_message')); 
    238289                    return false; 
    239290                } 
     
    260311                $fields='id'; 
    261312        $where=array('email'=>$value); 
    262         $query_temp = $this->UserTemp->getUserTempWhere($fields, $where); 
     313        $query_temp = $this->CI->UserTemp->getUserTempWhere($fields, $where); 
    263314         
    264315        if (($query != null) && ($query->num_rows() > 0)) 
     
    276327                 
    277328                return true; 
     329        } 
     330         
     331        // -------------------------------------------------------------------- 
     332         
     333    /** 
     334     * User name duplicate validation callback for validation against duplicate username in DB. 
     335     * This function is used in the backend administration 
     336     * 
     337     * @access private 
     338     * @param varchar $value 
     339     * @return boolean 
     340     */ 
     341    function email_backend_duplicate_check($value) 
     342        {        
     343                //Use the input e-mail and check against 'users' table 
     344            //checks if the request comes from add or edit actions 
     345                //query in main user table (users already activated) 
     346            $fields='id'; 
     347                $where = isset($_POST['id']) ?  array('id !='=> $_POST['id'], 'email'=>$value) : null; 
     348        $query = $this->CI->UserModel->getUsers($fields, $limit=null, $where); 
     349 
     350         
     351        //query in temporary user table (users waiting for activation) 
     352        //checks if the request comes from add or edit actions 
     353        //query in main user table (users already activated) 
     354             $fields='id'; 
     355                 $where = isset($_POST['id']) ?  array('id !='=> $_POST['id'], 'email'=>$value) : null; 
     356         $query_temp = $this->CI->UserTemp->getUserTemp($fields, $limit=null, $where); 
     357 
     358                 
     359        if (($query != null) && ($query->num_rows() > 0)) 
     360            { 
     361                $this->set_message('email_backend_duplicate_check', $this->CI->lang->line('FAL_user_email_duplicate')); 
     362                     
     363                $query->free_result(); 
     364                return false; 
     365                } 
     366                 
     367                 if (($query_temp != null) && ($query_temp->num_rows() > 0)) 
     368            { 
     369                $this->set_message('email_backend_duplicate_check', $this->CI->lang->line('FAL_usertemp_email_duplicate')); 
     370                     
     371                $query_temp->free_result(); 
     372                return false; 
     373                } 
     374                 
     375                 
     376                //return true; 
    278377        } 
    279378         
     
    319418            if ($country_id == 0) 
    320419            { 
    321                 $this->validation->country_id= $country_id; 
     420                //$this->validation->country_id= $country_id; 
    322421                $this->set_message('country_check', $this->CI->lang->line('FAL_country_validation_message')); 
    323422                    return FALSE; 
  • FreakAuth/trunk/www/system/application/views/FreakAuth_light/template_admin/users/add.php

    r41 r106  
    1616                            'maxlength'=>'45',  
    1717                            'size'=>'25', 
    18                             'value'=>(isset($this->validation) ? $this->validation->{$field} : '')))?> 
    19           <?=(isset($this->validation) ? $this->validation->{$field.'_error'} : '')?></p> 
     18                            'value'=>(isset($this->fal_validation) ? $this->fal_validation->{$field} : '')))?> 
     19          <?=(isset($this->fal_validation) ? $this->fal_validation->{$field.'_error'} : '')?></p> 
    2020 
    2121<?php } 
     
    3737                               'maxlength'=>'45',  
    3838                               'size'=>'35', 
    39                                'value'=>(isset($this->validation) ? $this->validation->{'user_name'} : '')))?> 
    40           <?=(isset($this->validation) ? $this->validation->{'user_name'.'_error'} : '')?> 
     39                               'value'=>(isset($this->fal_validation) ? $this->fal_validation->{'user_name'} : '')))?> 
     40          <?=(isset($this->fal_validation) ? $this->fal_validation->{'user_name'.'_error'} : '')?> 
    4141          </p> 
    4242     
     
    4646                               'maxlength'=>'120',  
    4747                               'size'=>'35', 
    48                                'value'=>(isset($this->validation) ? $this->validation->{'email'} : '')))?> 
    49         <?=(isset($this->validation) ? $this->validation->{'email'.'_error'} : '')?> 
     48                               'value'=>(isset($this->fal_validation) ? $this->fal_validation->{'email'} : '')))?> 
     49        <?=(isset($this->fal_validation) ? $this->fal_validation->{'email'.'_error'} : '')?> 
    5050      </p> 
    5151 
     
    5555                               'maxlength'=>'16',  
    5656                               'size'=>'16', 
    57                                'value'=>(isset($this->validation) ? $this->validation->{'password'} : '')))?> 
    58         <?=(isset($this->validation) ? $this->validation->{'password'.'_error'} : '')?> 
     57                               'value'=>(isset($this->fal_validation) ? $this->fal_validation->{'password'} : '')))?> 
     58        <?=(isset($this->fal_validation) ? $this->fal_validation->{'password'.'_error'} : '')?> 
    5959      </p> 
    6060 
     
    6464                               'maxlength'=>'16',  
    6565                               'size'=>'16', 
    66                                'value'=>(isset($this->validation) ? $this->validation->{'password_confirm'} : '')))?> 
    67     <?=(isset($this->validation) ? $this->validation->{'password_confirm'.'_error'} : '')?> 
     66                               'value'=>(isset($this->fal_validation) ? $this->fal_validation->{'password_confirm'} : '')))?> 
     67    <?=(isset($this->fal_validation) ? $this->fal_validation->{'password_confirm'.'_error'} : '')?> 
    6868     </p> 
    6969 
     
    7474      <?=form_dropdown('country_id', 
    7575                         $countries, 
    76                          (isset($this->validation) ? $this->validation->country_id : 0))?> 
    77         <?=(isset($this->validation) ? $this->validation->{'country_id'.'_error'} : '')?> 
     76                         (isset($this->fal_validation) ? $this->fal_validation->country_id : 0))?> 
     77        <?=(isset($this->fal_validation) ? $this->fal_validation->{'country_id'.'_error'} : '')?> 
    7878    </p> 
    7979     
     
    8585         <?php foreach ($role_options as $value) 
    8686         {?> 
    87                 <option value="<?=$value?>" <?=$this->validation->set_select('role', $value)?>><?=$value?></option> 
     87                <option value="<?=$value?>" <?=$this->fal_validation->set_select('role', $value)?>><?=$value?></option> 
    8888         <?php  
    8989         } 
    9090         ?> 
    9191         </select> 
    92          <?=(isset($this->validation) ? $this->validation->{'role'.'_error'} : '')?> 
     92         <?=(isset($this->fal_validation) ? $this->fal_validation->{'role'.'_error'} : '')?> 
    9393        </p> 
    9494 
  • FreakAuth/trunk/www/system/application/views/FreakAuth_light/template_admin/users/edit.php