/** * Denied access * @param ForbiddenException $exception * @return \Bluz\Controller\Controller|null */ public function forbidden(ForbiddenException $exception) { if (AuthProxy::getIdentity()) { $message = Translator::translate("You don't have permissions to access this page"); } else { $message = Translator::translate("You don't have permissions, please sign in"); } // for AJAX and API calls (over JSON) $jsonOrApi = Request::isXmlHttpRequest() || Request::getAccept([Request::TYPE_HTML, Request::TYPE_JSON]) == Request::TYPE_JSON; // for guest, for requests if (!AuthProxy::getIdentity() && !$jsonOrApi) { // save URL to session and redirect make sense if presentation is null Session::set('rollback', Request::getUri()->__toString()); // add error notice Messages::addError($message); // redirect to Sign In page $url = Router::getUrl('users', 'signin'); return $this->redirect($url); } else { return $this->error(new ForbiddenException($message, 403, $exception)); } }
/** * Add message to container * * @param string $type One of error, notice or success * @param string $message * @param string[] $text * @return void */ protected function add($type, $message, ...$text) { $this->init(); $this->getMessagesStore()[$type][] = Translator::translate($message, ...$text); }
* * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ /** * @namespace */ namespace Bluz\View\Helper; use Bluz\View\View; use Bluz\Proxy\Request; use Bluz\Proxy\Translator; return function ($text, $href, array $attributes = []) { // if href is settings for url helper if (is_array($href)) { $href = $this->url(...$href); } // href can be null, if access is denied if (null === $href) { return ''; } if ($href == Request::getRequestUri()) { if (isset($attributes['class'])) { $attributes['class'] .= ' on'; } else { $attributes['class'] = 'on'; } } $attributes = $this->attributes($attributes); return '<a href="' . $href . '" ' . $attributes . '>' . Translator::translate($text) . '</a>'; };
/** * Send email * @api * @param \PHPMailer $mail * @return bool * @throws MailerException * @todo Add mail to queue */ public function send(\PHPMailer $mail) { if ($template = $this->getOption('subjectTemplate')) { /** @var string $template */ $mail->Subject = Translator::translate($template, $mail->Subject); } if (!$mail->Send()) { // Why you don't use "Exception mode" of PHPMailer // Because we need our Exception in any case throw new MailerException('Error mail send: ' . $mail->ErrorInfo); } return true; }