Esempio n. 1
0
 /**
  * beforeFilter method
  * Do automatic login
  * If cannot login, delete cookie
  * @param Cake\Event\Event $event event
  * @return void
  */
 public function beforeFilter(Event $event)
 {
     //Automaticaly Login.
     if (!$this->Auth->user() && $this->Cookie->read(Setting::read('Remember.key'))) {
         $user = $this->Auth->identify();
         if ($user) {
             $this->Auth->setUser($user);
         } else {
             $this->Cookie->delete(Setting::read('Remember.key'));
         }
     }
 }
Esempio n. 2
0
 /**
  * The main method which you want to schedule for the most frequent interval
  *
  * @access public
  * @return void
  */
 public function main()
 {
     // read in the config
     if ($config = Setting::read($this->configKey)) {
         if (isset($config['storePath'])) {
             $this->storePath = $config['storePath'];
         }
         if (isset($config['storeFile'])) {
             $this->storeFile = $config['storeFile'];
         }
         if (isset($config['processingTimeout'])) {
             $this->processingTimeout = $config['processingTimeout'];
         }
         // read in the jobs from the config
         if (isset($config['jobs'])) {
             foreach ($config['jobs'] as $k => $v) {
                 $v = $v + ['action' => 'main', 'pass' => []];
                 $this->connect($k, $v['interval'], $v['task'], $v['action'], $v['pass']);
             }
         }
     }
     // ok, run them when they're ready
     $this->runjobs();
 }
Esempio n. 3
0
 /**
  * beforeDispatch function
  * @param \Cake\Event\Event $event event
  * @return /Cake/Network/Response|null
  */
 public function beforeDispatch(Event $event)
 {
     parent::beforeDispatch($event);
     $maintenance = Setting::read('Maintenance');
     // Allow ip in the list only.
     // Allow all if empty restrict ip
     if (!$maintenance['enable'] || empty($maintenance['allowedIp'])) {
         return null;
     }
     $userIP = $this->_getUserIpAddr();
     $ips = explode(',', trim($maintenance['allowedIp']));
     foreach ($ips as $ip) {
         if ($this->_compareIp($userIP, trim($ip))) {
             return null;
         }
     }
     $view = $this->_getView();
     $body = $view->render('Public/maintenance', 'error');
     $response = $event->data['response'];
     $response->statusCode(503);
     $response->body($body);
     $event->stopPropagation();
     return $response;
 }
Esempio n. 4
0
 * Inflector::rules('irregular', ['red' => 'redlings']);
 * Inflector::rules('uninflected', ['dontinflectme']);
 * Inflector::rules('transliteration', ['/å/' => 'aa']);
 */
/**
 * Plugins need to be loaded manually, you can either load them one by one or all of them in a single call
 * Uncomment one of the lines below, as you need. make sure you read the documentation on Plugin to use more
 * advanced ways of loading plugins
 *
 * Plugin::loadAll(); // Loads all plugins at once
 * Plugin::load('Migrations'); //Loads a single plugin named Migrations
 *
 */
Plugin::load('Migrations');
// Override debug by Setting Debug
Configure::write('debug', (bool) Setting::read('App.Debug'));
// Only try to load DebugKit in development mode
// Debug Kit should not be installed on a production system
if (Configure::read('debug')) {
    Plugin::load('DebugKit', ['bootstrap' => true]);
}
/**
 * Connect middleware/dispatcher filters.
 */
DispatcherFactory::add('Asset');
DispatcherFactory::add('Routing');
DispatcherFactory::add('ControllerFactory');
DispatcherFactory::add('Maintenance');
/**
 * Enable immutable time objects in the ORM.
 *
Esempio n. 5
0
 /**
  * Deactive method
  *
  * @return \Cake\Network\Response|null Redirects to referer
  * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
  */
 public function deactive()
 {
     $this->request->allowMethod(['post', 'put']);
     if (!Setting::read('Member.AnyoneCanDeactive')) {
         throw new NotFoundException(__('Page not found'));
     }
     if ($this->Users->deactive($this->Auth->user('id'))) {
         $url = Router::url(['prefix' => 'admin', 'controller' => 'Users', 'action' => 'login', '_full' => true]);
         TableRegistry::get('EmailQueue')->enqueue($this->Auth->user('email'), ['user' => $this->Auth->user(), 'url' => $url], ['subject' => __('Your account has been deactivated'), 'template' => 'Users/deactivated', 'format' => 'html', 'layout' => 'default']);
         return $this->redirect(['action' => 'logout']);
     }
     $this->Flash->error(__('Unable to deactive your account. Please try again or contact to your administrator'));
     return $this->redirect($this->referer());
 }