05.21 php saved
aarkerio
Tags add more
auth  
Note
Using Auth in this way, is correct?
  1. File:   APP/app_controler.php
  2.  
  3.  public $components = array('Auth', 'Cookie', 'Session');       
  4.  
  5.  public function beforeFilter()
  6.  {
  7.      $this->Auth->fields         = array('username' => 'email', 'password' => 'pwd');
  8.      $this->Auth->loginAction    = array('controller' => 'users', 'action' => 'login');
  9.      $this->Auth->loginRedirect  = array('controller' => 'news', 'action' => 'display');
  10.      $this->Auth->logoutRedirect = '/news/display';
  11.      $this->Auth->loginError     = 'Invalid e-mail / password combination. Please try again';
  12.      $this->Auth->authorize      = 'controller';
  13.      $this->Auth->deny('*');
  14.  
  15.      $this->set('cU', $this->Auth->user())// $cU current user array to use in the views if user logged in                               
  16.  }
  17.  
  18. in controller:
  19.  
  20.  public function beforeFilter()
  21.  {
  22.     parent::beforeFilter();
  23.     $this->Auth->allow(array('display'));
  24.  }
  25.  
  26.  public function isAuthorized()
  27.  {
  28.    if (isset( $this->params[Configure::read('Routing.admin')] )):
  29.        if ($this->Auth->user('group_id') == 1 ||  $this->Auth->user('group_id') == 2 )// admin and teachers                             
  30.               return true;
  31.        else:
  32.               return false;
  33.        endif;
  34.    endif;
  35.    
  36.    return true;
  37.  }
  38.  
  39.  
Parsed in 0.085 seconds, using GeSHi 1.0.7.14

Modify this Paste