Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class AppController extends Controller {
- var $helpers = array('Html', 'Form', 'Time', 'Number', 'Javascript', 'Cache', 'Text', 'Paypal');
- var $components = array('Auth', 'Email', 'Cookie', 'RequestHandler', 'Paypal');
- var $uses = array('Setting', 'User');
- var $view = 'Theme';
- var $appConfigurations;
- var $emailConfigurations;
- var $paypalConfigurations;
- function beforeFilter() {
- $this->appConfigurations = Configure::read('App');
- $this->set('appConfigurations', $this->appConfigurations);
- // Set the theme if it exists
- if(!empty($this->appConfigurations['theme'])) {
- $this->theme = $this->appConfigurations['theme'];
- }
- // Change the layout to admin if the prefix is admin
- if(isset($this->params['prefix']) && $this->params['prefix'] == 'admin') {
- $this->layout = 'admin';
- } else {
- if(empty($this->params['requested'])){
- // lets get the default meta tags
- $this->pageTitle = $this->Setting->get('default_meta_title');
- $this->set('meta_description', $this->Setting->get('default_meta_description'));
- $this->set('meta_keywords', $this->Setting->get('default_meta_keywords'));
- }
- if(!empty($this->params['url']) &&($this->params['url']['url'] !== 'users/login') && ($this->params['url']['url'] !== 'users/logout')) {
- if(!$this->Auth->user('admin')) {
- // Only call it if not requested(requestAction) and not admin
- if($_SERVER['REQUEST_URI'] !== '/offline' && empty($this->params['requested'])) {
- $setting = $this->Setting->get('site_live');
- if($setting == 'no') {
- $this->redirect('/offline');
- }
- }
- }
- }
- }
- if(isset($this->Auth)) {
- // Setup the field for auth
- $this->Auth->fields = array(
- 'username' => 'username',
- 'password' => 'password'
- );
- $this->Auth->loginAction = array(
- 'controller' => 'users',
- 'action' => 'login'
- );
- // Where the auth will redirect user after logout
- $this->Auth->logoutRedirect = array(
- 'controller' => 'users',
- 'action' => 'login'
- );
- // Set the error message
- $this->Auth->loginError = sprintf(__('Invalid %s or %s. Please try again.', true),
- $this->Auth->fields['username'],
- $this->Auth->fields['password']);
- // Set to off since we do something inside login
- $this->Auth->autoRedirect = false;
- // Set the type of authorization
- $this->Auth->authorize = 'controller';
- // Check if user has a remember me cookie
- if(!$this->Auth->user()) {
- if($id = $this->Cookie->read('User.id')) {
- $user = $this->User->read(null, $id);
- if($this->Auth->login($user)){
- $this->Session->del('Message.Auth');
- }else{
- $this->Cookie->del('User.id');
- }
- }
- }
- // Allowing global function
- $this->Auth->allow('isPeakNow');
- }
- }
Add Comment
Please, Sign In to add comment