Advertisement
Guest User

Users Controller with strange bug

a guest
Sep 2nd, 2011
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.41 KB | None | 0 0
  1. <?php
  2.  
  3. App::import ('Sanitize');
  4.  
  5. class UsersController extends AppController {
  6.     var $name = 'Users';
  7.    
  8.     var $uses = array (
  9.         'User',
  10.         'Student',
  11.         'Company'
  12.     );
  13.    
  14.     function beforeFilter () {
  15.         parent::beforeFilter();
  16.        
  17.         $this->Auth->allow (array (
  18.             'login', 'logout', 'validate_email'
  19.         ));
  20.     }
  21.    
  22.     public function login () { 
  23.         $this->set ('title_for_layout', 'ARE · Gestió de Pràctiques externes');
  24.         $this->set ('header_text', 'ARE · Gestió de Pràctiques externes');
  25.        
  26.         if (isset ($this->data) && $this->Auth->login ($this->data) == 0) {    
  27.             $this->set ('cleanLogin', false);
  28.         } else {           
  29.             $this->set ('cleanLogin', true);
  30.         }
  31.     }
  32.    
  33.     public function logout () {
  34.         $this->Session->delete ('Role');
  35.         $this->Auth->logout ();
  36.         $this->redirect(array(
  37.             'controller' => 'users',
  38.             'action' => 'login'
  39.         ));
  40.     }
  41.    
  42.     public function dashboard () {
  43.         $this->set ('title_for_layout', 'ARE · Panell de gestió');
  44.         $this->set ('header_text', 'ARE · Panell de gestió');
  45.        
  46.         $userinfo = $this->Auth->user ();
  47.        
  48.         $groupid = $userinfo['User']['group_id'];
  49.         $dashboard = $this->requestAction (
  50.             array (
  51.                 'controller' => $this->group_numbers[$groupid],
  52.                 'action' => 'dashboard'
  53.             ),
  54.             array (
  55.                 'named' => array (),
  56.                 'pass' => array (),
  57.                 'return'
  58.             )
  59.         );
  60.        
  61.         $this->set ('dashboard', $dashboard);
  62.     }
  63.    
  64.     public function validate_email () {
  65.         if (count ($this->params) < 2) {
  66.             $this->redirect (array(
  67.                 'controller' => 'users',
  68.                 'action' => 'dashboard'
  69.             ));
  70.         }
  71.        
  72.         $username = Sanitize::paranoid (
  73.             $this->params['pass'][0],
  74.             array ('_')
  75.         );
  76.         $code = Sanitize::paranoid (
  77.             $this->params['pass'][1],
  78.             array ('-', '.')
  79.         );
  80.        
  81.         $db_code = $this->User->field (
  82.             'validate',
  83.             array (
  84.                 'username' => $username,
  85.             )
  86.         );
  87.            
  88.         if ($db_code == 'v:'.$code) {
  89.             $this->set ('title_for_layout', 'ARE · Validació d\'usuari');
  90.             $this->set ('header_text', 'ARE · Validació d\'usuari');
  91.            
  92.             $this->User->updateAll (
  93.                 array (
  94.                     'validate' => '\'' . $this->genPass (64) . '\''
  95.                 ),
  96.                 array (
  97.                     'username' => $username
  98.                 )
  99.             );
  100.            
  101.             $this->set ('validated', true);
  102.         } else {
  103.             $this->set ('title_for_layout', 'ARE · Validació incorrecta');
  104.             $this->set ('header_text', 'ARE · Validació incorrecta');
  105.             $this->set ('validated', false);
  106.         }
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement