05.04
php
saved
AppControllerwAuth
Note
AppControllerwAuth did not leave a note
AppControllerwAuth did not leave a note
- <?php
- class AppController extends Controller {
- /**
- * Load the Authentication
- *
- * @access public
- */
- function beforeFilter(){
- //Set up Auth Component
- $this->Auth->logoutRedirect = '/users/login';
- //$this->Auth->allow('display'); // We want to force a login for all pages.
- // Controller autorization is the simplest form.
- $this->Auth->authorize = 'controller';
- $this->Auth->loginError = 'Login failed. Invalid username or password.';
- $this->Auth->authError = 'Please login in order to access the requested resource.';
- // Additional criteria for loging.
- $this->recordActivity();
- $this->log('Last line in AppController::beforeFilter()');
- }
- /**
- * Ensure user is authorized.
- *
- * In its purest form, this function MUST be present and return true. It works sort of like a prevalidation for additional criteria.
- * I've done a little extra to make sure the user with admin routing is the admin:
- * If using admin route, ensure user is admin (group_id ==1). If not, don't authorize.
- * @access public
- */
- function isAuthorized() {
- if ($this->Auth->user('group_id') != 1) {
- return false;
- }
- }
- return true;
- }
- function recordActivity() {
- $this->data['Tracker']['user_id'] = $this->Auth->user('id');
- $this->data['Tracker']['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
- $this->data['Tracker']['user_ip'] = $_SERVER['REMOTE_ADDR'];
- $params = $pages;
- }
- $this->data['Tracker']['referer'] = $_SERVER['HTTP_REFERER'];
- } else {
- $this->data['Tracker']['referer'] = '';
- }
- $this->Tracker->save($this->data);
- }
- }
- ?>
Parsed in 0.146 seconds, using GeSHi 1.0.7.14