Changeset 266
- Timestamp:
- 05/28/07 08:26:19
- Files:
-
- FreakAuth/trunk/www/system/application/config/freakauth_light.php (modified) (1 diff)
- FreakAuth/trunk/www/system/application/libraries/FAL_front.php (modified) (1 diff)
- FreakAuth/trunk/www/system/application/libraries/FAL_validation.php (modified) (5 diffs)
- FreakAuth/trunk/www/system/application/libraries/Freakauth_light.php (modified) (9 diffs)
- FreakAuth/trunk/www/system/application/models/FreakAuth_light/usertemp.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
FreakAuth/trunk/www/system/application/config/freakauth_light.php
r259 r266 115 115 $config['FAL_allow_user_registration'] = TRUE; 116 116 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 */ 117 143 $config['FAL_user_name_min'] = 4; //min username length 118 144 $config['FAL_user_name_max'] = 16; //max username length FreakAuth/trunk/www/system/application/libraries/FAL_front.php
r253 r266 267 267 { 268 268 $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 } 270 279 //$this->CI->output->enable_profiler(TRUE); 271 280 } FreakAuth/trunk/www/system/application/libraries/FAL_validation.php
r253 r266 197 197 //query in main user table (users already activated) 198 198 $query = $this->CI->UserModel->getUserByUsername($value); 199 199 200 //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) 205 221 { 206 222 $this->set_message('username_duplicate_check', $this->CI->lang->line('FAL_in_use_validation_message')); 207 223 return false; 208 224 } 209 210 return true; 225 else 226 { 227 return true; 228 } 211 229 } 212 230 … … 229 247 230 248 //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) 237 269 { 238 270 $this->set_message('username_backend_duplicate_check', $this->CI->lang->line('FAL_in_use_validation_message')); 239 271 return false; 240 } 241 242 return true; 272 } 273 else 274 { 275 return true; 276 } 243 277 } 244 278 … … 258 292 //query in main user table (users already activated) 259 293 $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);264 294 265 295 if (($query != null) && ($query->num_rows() > 0)) … … 269 299 } 270 300 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 278 316 return true; 279 317 } … … 298 336 $query = $this->CI->UserModel->getUsers($fields, $limit=null, $where); 299 337 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 308 338 if (($query != null) && ($query->num_rows() > 0)) 309 339 { 310 340 $this->set_message('email_backend_duplicate_check', $this->CI->lang->line('FAL_user_email_duplicate')); 311 312 341 $query->free_result(); 313 342 return false; 314 343 } 315 344 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; 326 363 } 327 364 FreakAuth/trunk/www/system/application/libraries/Freakauth_light.php
r265 r266 69 69 * Function FreakAuth inizialises the class loading the right libraries, helpers and models 70 70 * 71 * @uses libraries (encrypt, db_session), helpers (form, url, FreakAuth), modules ( Usermodel)71 * @uses libraries (encrypt, db_session), helpers (form, url, FreakAuth), modules (usermodel) 72 72 * */ 73 73 function Freakauth_light() … … 82 82 $this->CI->load->helper('freakauth_light'); 83 83 $this->CI->load->model('FreakAuth_light/usertemp', 'UserTemp'); 84 $this->CI->load->model(' Usermodel', 'usermodel');84 $this->CI->load->model('usermodel', 'usermodel'); 85 85 if($this->CI->config->item('FAL_create_user_profile')) 86 86 $this->CI->load->model('Userprofile', 'userprofile'); … … 192 192 * 193 193 * 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 196 200 */ 197 201 function denyAccess($role) … … 312 316 * Returns true if a valid user is logged, false otherwise 313 317 * 314 * @return unknown318 * @return boolean 315 319 */ 316 320 function isValidUser() … … 509 513 { 510 514 //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 } 512 520 513 521 //let's check if the system is turned on and if we allow users to register … … 527 535 $password_email=$password; 528 536 $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')) 541 544 { 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 548 588 } 549 589 } 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 } 556 598 } 557 599 … … 569 611 { 570 612 //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 } 572 618 573 619 if (($id > 0) && ($activation_code != '')) … … 670 716 /** 671 717 * recalls the function getUserForForgottenPasswordReset($id, $activation_code) 672 * from the class Usermodel718 * from the class usermodel 673 719 * it queries the database looking for the user's $id and $activation_code 674 720 */ … … 1348 1394 1349 1395 } 1350 1351 ?>FreakAuth/trunk/www/system/application/models/FreakAuth_light/usertemp.php
r229 r266 147 147 function getUserTempCreated() 148 148 { 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); 150 150 151 151 }
