addReCaptchaScript(); } } /** * Facebook login link * * @return string */ public function facebookLogin() { return $this->Html->link($this->Html->tag('i', '', [ 'class' => 'fa fa-facebook' ]) . __d('Users', 'Sign in with Facebook'), '/auth/facebook', [ 'escape' => false, 'class' => 'btn btn-social btn-facebook' ]); } /** * Twitter login link * * @return string */ public function twitterLogin() { return $this->Html->link($this->Html->tag('i', '', [ 'class' => 'fa fa-twitter' ]) . __d('Users', 'Sign in with Twitter'), '/auth/twitter', [ 'escape' => false, 'class' => 'btn btn-social btn-twitter' ]); } /** * Logout link * * @param null $message logout message info. * @param array $options Array with option data. * @return string */ public function logout($message = null, $options = []) { return $this->Html->link(empty($message) ? __d('Users', 'Logout') : $message, [ 'plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'logout' ], $options); } /** * Generate a link if the target url is authorized for the logged in user * * @param type $title link's title. * @param type $url url that the user is making request. * @param array $options Array with option data. * @return string */ public function link($title, $url = null, array $options = []) { $event = new Event(UsersAuthComponent::EVENT_IS_AUTHORIZED, $this, ['url' => $url]); $result = $this->_View->eventManager()->dispatch($event); if ($result->result) { $linkOptions = $options; unset($linkOptions['before'], $linkOptions['after']); return Hash::get($options, 'before') . $this->Html->link($title, $url, $linkOptions) . Hash::get($options, 'after'); } return false; } /** * Retunrs true if the target url is authorized for the logged in user * * @param type $url url that the user is making request. * @return bool */ public function isAuthorized($url = null) { $event = new Event(UsersAuthComponent::EVENT_IS_AUTHORIZED, $this, ['url' => $url]); $result = $this->_View->eventManager()->dispatch($event); return $result->result; } /** * Welcome display * @return mixed */ public function welcome() { $userId = $this->request->session()->read('Auth.User.id'); if (empty($userId)) { return; } $profileUrl = Configure::read('Users.Profile.route'); $label = __d('Users', 'Welcome, {0}', $this->Html->link($this->request->session()->read('Auth.User.first_name'), $profileUrl)); return $this->Html->tag('span', $label, ['class' => 'welcome']); } /** * Add reCaptcha script * @return void */ public function addReCaptchaScript() { $this->Html->script('https://www.google.com/recaptcha/api.js', [ 'block' => 'script', ]); } /** * Add reCaptcha to the form * @return mixed */ public function addReCaptcha() { if (!Configure::check('Users.Registration.reCaptcha')) { return false; } $this->Form->unlockField('g-recaptcha-response'); return $this->Html->tag('div', '', [ 'class' => 'g-recaptcha', 'data-sitekey' => Configure::read('reCaptcha.key') ]); } }