示例#1
0
    /**
     * Display recaptcha function
     * @return string|bool
     */
    public function display()
    {
        if (!Setting::readOrFail('Recaptcha.enable')) {
            return false;
        }
        $sitekey = Setting::readOrFail('Recaptcha.sitekey');
        $lang = Setting::readOrFail('Recaptcha.lang');
        $theme = Setting::readOrFail('Recaptcha.theme');
        $type = Setting::readOrFail('Recaptcha.type');
        return <<<EOF
<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl={$lang}" async defer></script>
<div class="g-recaptcha" data-sitekey="{$sitekey}" data-theme="{$theme}" data-type="{$type}"></div>
<noscript>
  <div>
    <div style="width: 302px; height: 422px; position: relative;">
      <div style="width: 302px; height: 422px; position: absolute;">
        <iframe src="https://www.google.com/recaptcha/api/fallback?k={$sitekey}"
                frameborder="0" scrolling="no"
                style="width: 302px; height:422px; border-style: none;">
        </iframe>
      </div>
    </div>
    <div style="width: 300px; height: 60px; border-style: none;
                   bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px;
                   background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px;">
      <textarea id="g-recaptcha-response" name="g-recaptcha-response"
                   class="g-recaptcha-response"
                   style="width: 250px; height: 40px; border: 1px solid #c1c1c1;
                          margin: 10px 25px; padding: 0px; resize: none;" >
      </textarea>
    </div>
  </div>
</noscript>
EOF;
    }
示例#2
0
 /**
  * _getOptions method
  *
  * @return mix|bool
  */
 protected function _getOptions()
 {
     if (array_key_exists('name', $this->_properties)) {
         $options = Setting::options($this->_properties['name']);
         if (is_callable($options)) {
             return $options();
         }
         return $options;
     }
     return false;
 }
示例#3
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'));
         }
     }
 }
示例#4
0
 /**
  * verify recaptcha
  * @return bool
  */
 public function verify()
 {
     if (!Setting::readOrFail('Recaptcha.enable')) {
         return true;
     }
     $controller = $this->_registry->getController();
     if (isset($controller->request->data['g-recaptcha-response'])) {
         $response = (new Client())->post('https://www.google.com/recaptcha/api/siteverify', ['secret' => Setting::readOrFail('Recaptcha.secret'), 'response' => $controller->request->data['g-recaptcha-response'], 'remoteip' => $controller->request->clientIp()]);
         return json_decode($response->body)->success;
     }
     return false;
 }
示例#5
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();
 }
示例#6
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;
 }
示例#7
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.
 *
示例#8
0
 /**
  * Index method
  *
  * @param string $key key
  * @return \Cake\Network\Response|null
  */
 public function index($key = null)
 {
     if (!$key) {
         return $this->redirect(['action' => 'index', 'App']);
     }
     if (!$this->prefixExists($key)) {
         throw new NotFoundException("The prefix-setting {$key} could not be found");
     }
     $prefix = Hash::get($this->prefixes, ucfirst($key));
     $settings = $this->Configurations->find('all')->where(['name LIKE' => $key . '%', 'editable' => 1])->order(['weight', 'id']);
     if ($this->request->is(['patch', 'put', 'post'])) {
         $settings = $this->Configurations->patchEntities($settings, $this->request->data);
         foreach ($settings as $setting) {
             if ($this->Configurations->save($setting)) {
                 $this->Flash->success(__('The setting has been saved'));
             } else {
                 $this->Flash->error(__('The setting could not be saved. Please try again.'));
             }
         }
         Setting::clear(true);
         Setting::autoload();
         return $this->redirect([]);
     }
     $this->set(compact('settings', 'prefix'));
     $this->set('_serialize', ['settings']);
 }
示例#9
0
 /**
  * Active Account
  * @param string $token hash from $user->email . $user->token_created . $user->id
  * @param string $email email
  * @return Cake\Network\Response
  */
 public function activeAccount($token = null, $email = null)
 {
     if (!$token || !$email) {
         throw new NotFoundException(__('Missing required information. Please read email carefully and try again.'));
     }
     $user = $this->Users->findByEmailAndStatus($email, false)->first();
     if (!$user) {
         throw new RecordNotFoundException(__('Account not found or already activated. Please read email carefully and try again.'));
     }
     if ($token != Security::hash($user->email . $user->token_created . $user->id, 'sha1', true)) {
         throw new ForbiddenException(__('Invalid token. Please read email carefully and try again.'));
     }
     if (!$user->token_created->wasWithinLast(Setting::readOrFail('Member.RegisterTokenExpired'))) {
         throw new ForbiddenException(__('Your request has been expired. Please contact to your administrator.'));
     }
     unset($user->password);
     if ($this->request->is('put')) {
         $allowedToChange = ['password', 're_password', 'full_name'];
         $data = array_intersect_key($this->request->data, array_flip($allowedToChange));
         $user = $this->Users->patchEntity($user, $data, ['validate' => 'ActiveAccount']);
         $user->status = true;
         if ($this->Users->save($user)) {
             unset($user->password);
             $url = Router::url(['prefix' => 'admin', 'controller' => 'Users', 'action' => 'login', '_full' => true]);
             TableRegistry::get('EmailQueue')->enqueue($user->email, ['user' => $user, 'url' => $url], ['subject' => __('Your account has been activated'), 'template' => 'Users/account_verified', 'layout' => 'default', 'format' => 'html']);
             $this->Flash->success(__('Your account has been activated. You can login right now'));
             return $this->redirect(['action' => 'login']);
         }
     }
     $this->set(compact('user'));
 }