Guest User

Untitled

a guest
Jun 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. <?php
  2. class AppController extends Controller {
  3. var $helpers = array('Html', 'Form', 'Time', 'Number', 'Javascript', 'Cache', 'Text', 'Paypal');
  4. var $components = array('Auth', 'Email', 'Cookie', 'RequestHandler', 'Paypal');
  5. var $uses = array('Setting', 'User');
  6. var $view = 'Theme';
  7.  
  8. var $appConfigurations;
  9. var $emailConfigurations;
  10. var $paypalConfigurations;
  11.  
  12. function beforeFilter() {
  13. $this->appConfigurations = Configure::read('App');
  14. $this->set('appConfigurations', $this->appConfigurations);
  15.  
  16. // Set the theme if it exists
  17. if(!empty($this->appConfigurations['theme'])) {
  18. $this->theme = $this->appConfigurations['theme'];
  19. }
  20.  
  21. // Change the layout to admin if the prefix is admin
  22. if(isset($this->params['prefix']) && $this->params['prefix'] == 'admin') {
  23. $this->layout = 'admin';
  24. } else {
  25. if(empty($this->params['requested'])){
  26. // lets get the default meta tags
  27. $this->pageTitle = $this->Setting->get('default_meta_title');
  28. $this->set('meta_description', $this->Setting->get('default_meta_description'));
  29. $this->set('meta_keywords', $this->Setting->get('default_meta_keywords'));
  30. }
  31.  
  32. if(!empty($this->params['url']) &&($this->params['url']['url'] !== 'users/login') && ($this->params['url']['url'] !== 'users/logout')) {
  33. if(!$this->Auth->user('admin')) {
  34. // Only call it if not requested(requestAction) and not admin
  35. if($_SERVER['REQUEST_URI'] !== '/offline' && empty($this->params['requested'])) {
  36. $setting = $this->Setting->get('site_live');
  37.  
  38. if($setting == 'no') {
  39. $this->redirect('/offline');
  40. }
  41. }
  42. }
  43. }
  44. }
  45.  
  46. if(isset($this->Auth)) {
  47. // Setup the field for auth
  48. $this->Auth->fields = array(
  49. 'username' => 'username',
  50. 'password' => 'password'
  51. );
  52.  
  53.  
  54. $this->Auth->loginAction = array(
  55. 'controller' => 'users',
  56. 'action' => 'login'
  57. );
  58.  
  59. // Where the auth will redirect user after logout
  60. $this->Auth->logoutRedirect = array(
  61. 'controller' => 'users',
  62. 'action' => 'login'
  63. );
  64.  
  65. // Set the error message
  66. $this->Auth->loginError = sprintf(__('Invalid %s or %s. Please try again.', true),
  67. $this->Auth->fields['username'],
  68. $this->Auth->fields['password']);
  69.  
  70. // Set to off since we do something inside login
  71. $this->Auth->autoRedirect = false;
  72.  
  73. // Set the type of authorization
  74. $this->Auth->authorize = 'controller';
  75.  
  76. // Check if user has a remember me cookie
  77. if(!$this->Auth->user()) {
  78. if($id = $this->Cookie->read('User.id')) {
  79. $user = $this->User->read(null, $id);
  80. if($this->Auth->login($user)){
  81. $this->Session->del('Message.Auth');
  82. }else{
  83. $this->Cookie->del('User.id');
  84. }
  85. }
  86. }
  87.  
  88. // Allowing global function
  89. $this->Auth->allow('isPeakNow');
  90. }
  91. }
Add Comment
Please, Sign In to add comment