public function actionLogout(User $user, CSRF $CSRF) { $valid = $CSRF->check(Request::get($CSRF->csrfParam)); if ($valid) { $user->logout(true); } $this->redirect(Url::set()->removeAllArgs()->getAbsolute())->send(true); }
protected function prepareBody(SignupForm $model, Users $users) { $placeholders = $users->toArray(); $placeholders['password'] = $model->password; if ($model->generateToken) { $placeholders['url'] = Url::set($this->activateUrl)->addArgs(['token' => $placeholders['token']])->getAbsolute(); } return $this->template->getChunk($this->emailBodyTpl, $placeholders); }
public function init() { if (isset($this->service)) { return; } //$serviceFactory = new ServiceFactory(); // Session storage $storage = new Session(); // Setup the credentials for the requests $credentials = new Credentials($this->clientId, $this->clientSecret, Url::modify([$this->redirectUrl], Url::ABS)); $this->service = new Vkontakte($credentials, new StreamClient(), $storage, $this->scopes); }
public function init() { if (isset($this->service)) { return; } $serviceFactory = new ServiceFactory(); // Session storage $storage = new Session(); // Setup the credentials for the requests $credentials = new Credentials($this->clientId, $this->clientSecret, Url::modify($this->redirectUrl, Url::ABS)); $this->service = $serviceFactory->createService('facebook', $credentials, $storage, $this->scopes); }
public function init() { if (isset($this->service)) { return; } $serviceFactory = new ServiceFactory(); // Session storage $storage = new Session(false); // Setup the credentials for the requests $credentials = new Credentials($this->clientId, $this->clientSecret, Url::modify($this->redirectUrl, Url::ABS)); // Instantiate the Google service using the credentials, http client and storage mechanism for the token $this->service = $serviceFactory->createService('google', $credentials, $storage, $this->scopes); }
public function actionIndex(User $user, Session $session) { $placeholders = []; if ($session->hasFlash($this->keySessionFlash)) { $placeholders['content'] = i18n::t('successActivate'); return $this->render('success', $placeholders); } elseif ($user->isGuest() && ($users = Users::activate(Request::get('token')))) { // auto-login $user->addMulti($users->toArray(['id', 'username', 'url'])); $user->login(); $session->setFlash($this->keySessionFlash); $this->response->redirect(Url::set()->removeAllArgs()->getAbsoluteUrl(true))->send(true); return null; } return $this->notPage('@frontend.views/layouts/notPage'); }
/** * Renders the widget. */ public function run() { if ($this->hasModel() && $this->activeField) { $this->options = $this->activeField->calculateClientInputOption($this->options); $input = ActiveHtml::activeTextInput($this->model, $this->attribute, $this->options); } else { $input = Html::textInput($this->name, $this->value, $this->options); } if ($this->output === self::BASE64) { $src = $this->captcha->getDataUri(); } else { $src = Url::modify([$this->captchaAction, 'v' => uniqid()], Url::ABS); } $image = Html::img($src, $this->imageOptions); echo strtr($this->template, ['{input}' => $input, '{image}' => $image]); }
/** * Modify url. * * @param string $url * @param array $params params: * * - modify: modify arguments. * - csrf: adding a CSRF-token. * - scheme: adduce URL to: {@see \rock\url\Url::ABS}, {@see \rock\url\Url::HTTP}, * and {@see \rock\url\Url::HTTPS}. * @param Template $template * @return string * @throws \rock\url\UrlException */ public static function modifyUrl($url, array $params = [], Template $template) { if (empty($url)) { return '#'; } if (!isset($params['modify'])) { $params['modify'] = []; } array_unshift($params['modify'], $url); $config = isset($params['config']) ? $params['config'] : []; if (isset($params['csrf'])) { $config['csrf'] = (bool) $params['csrf']; } if (isset($params['scheme'])) { $params['modify']['@scheme'] = $params['scheme']; } $config['request'] = $template->request; return Url::modify($params['modify'], $config); }
/** * Returns the URL that the browser should be redirected to after successful login. * * This method reads the return URL from the session. It is usually used by the login action which * may call this method to redirect the browser to where it goes after successful authentication. * * @param string|array $defaultUrl the default return URL in case it was not set previously. * If this is null and the return URL was not set previously, {@see \rock\request\Request::getHomeUrl()} will be redirected to. * @return string the URL that the user should be redirected to after login. */ public function getReturnUrl($defaultUrl = null) { $url = $this->storage->get($this->returnUrlParam, $defaultUrl); return $url === null ? $this->request->getHomeUrl() : Url::modify($url); }
protected static function modifyInternal(Url $self, array $modify) { $placeholders = []; foreach ($modify as $key => $value) { if (is_int($key)) { if (empty($value)) { continue; } if ($value === '!#') { $self->removeFragment(); continue; } if ($value === '!') { $self->removeQuery(); continue; } if ($value[0] === '!') { $self->removeQueryParams([mb_substr($value, 1, mb_strlen($value, 'UTF-8'), 'UTF-8')]); continue; } continue; } if ($key === '#') { $self->setFragment($value); continue; } if ($key[0] === '@') { $self->{substr($key, 1)} = $value; continue; } if ($key[0] === '+') { $placeholders[mb_substr($key, 1, mb_strlen($key, 'UTF-8'), 'UTF-8')] = $value; continue; } $self->addQueryParams([$key => $value]); } $self->replace($placeholders); return $self; }
return !Rock::$app->user->isGuest(); } return \rock\helpers\ArrayHelper::getValue(Rock::$app->user->getAll(), $keys); }, 'call' => function (array $call, array $params = [], Template $template) { if (!isset($call[1])) { $call[1] = null; } list($class, $method) = $call; if ($class === 'context') { $object = $template->context; $function = [$object, $method]; } elseif (function_exists($class) && !$class instanceof \Closure) { return call_user_func_array($class, $params); } else { $object = \rock\di\Container::load($class); if (!method_exists($object, $method)) { throw new \rock\base\BaseException(\rock\base\BaseException::UNKNOWN_METHOD, ['method' => "{$class}::{$method}"]); } $function = [$object, $method]; } return call_user_func_array($function, $params); }], 'title' => 'Demo', 'metaTags' => ['charset' => '<meta charset="' . Rock::$app->charset . '" />'], 'linkTags' => ['favicon' => '<link rel="Shortcut Icon" type="image/x-icon" href="/favicon.ico?10">'], 'snippets' => ['request.get' => ['class' => \rock\snippets\request\Get::className()], 'request.post' => ['class' => \rock\snippets\request\Post::className()], 'csrf' => ['class' => \rock\snippets\CSRF::className()], 'captchaView' => ['class' => \rock\snippets\CaptchaView::className()], 'activeForm' => ['class' => \rock\snippets\ActiveForm::className()]]], 'execute' => ['class' => \rock\execute\CacheExecute::className()], 'i18n' => ['class' => \rock\i18n\i18n::className(), 'pathsDicts' => ['ru' => ['@rock/messages/ru/lang.php', '@rock/messages/ru/validate.php'], 'en' => ['@rock/messages/en/lang.php', '@rock/messages/en/validate.php']], 'locale' => [\rock\LocaleProperties::className(), 'locale']], 'date' => ['class' => \rock\date\DateTime::className(), 'locale' => [\rock\LocaleProperties::className(), 'locale'], 'formats' => ['dmy' => function (\rock\date\DateTime $dateTime) { $nowYear = date('Y'); $lastYear = $dateTime->format('Y'); return $nowYear > $lastYear ? $dateTime->format('j F Y') : $dateTime->format('d F'); }, 'dmyhm' => function (\rock\date\DateTime $dateTime) { $nowYear = date('Y'); $lastYear = $dateTime->format('Y'); return $nowYear > $lastYear ? $dateTime->format('j F Y H:i') : $dateTime->format('j F H:i'); }]], 'mail' => ['class' => \rock\mail\Mail::className(), 'From' => 'support@' . (new \rock\request\Request())->getHost(), 'FromName' => 'Rock Framework'], 'url' => ['class' => \rock\url\Url::className()], 'request' => ['class' => \rock\request\Request::className(), 'locale' => [\rock\LocaleProperties::className(), 'locale']], 'response' => ['class' => \rock\response\Response::className(), 'locale' => [\rock\LocaleProperties::className(), 'locale']], 'htmlResponseFormatter' => ['class' => \rock\response\HtmlResponseFormatter::className()], 'jsonResponseFormatter' => ['class' => \rock\response\JsonResponseFormatter::className()], 'xmlResponseFormatter' => ['class' => \rock\response\XmlResponseFormatter::className()], 'rssResponseFormatter' => ['class' => \rock\response\RssResponseFormatter::className()], 'session' => ['class' => \rock\session\Session::className(), 'cookieParams' => ['httponly' => true, 'lifetime' => 60 * 60 * 24 * 60, 'setUseCookies' => \rock\session\Session::USE_ONLY_COOKIES]], 'cookie' => ['class' => \rock\cookie\Cookie::className()], 'security' => ['class' => Security::className()], 'sanitize' => ['class' => \rock\sanitize\Sanitize::className()], 'validate' => ['class' => \rock\validate\Validate::className(), 'locale' => [\rock\LocaleProperties::className(), 'locale']], 'csrf' => ['class' => \rock\csrf\CSRF::className()], 'captcha' => ['class' => \rock\captcha\Captcha::className(), 'length' => 0, 'whiteNoiseDensity' => 1 / 6, 'blackNoiseDensity' => 1 / 30], 'user' => ['class' => \rock\user\User::className(), 'container' => 'user'], 'rbac' => ['class' => \rock\rbac\DBManager::className()], 'log' => ['class' => \rock\log\Log::className()], Role::className() => ['class' => Role::className()], Permission::className() => ['class' => Permission::className()]], require __DIR__ . '/widgets.php');
/** * Creates a URL for sorting the data by the specified attribute. * This method will consider the current sorting status given by {@see \rock\data\Sort::$attributeOrders}. * For example, if the current page already sorts the data by the specified attribute in ascending order, * then the URL created will lead to a page that sorts the data by the specified attribute in descending order. * @param string $attribute the attribute name * @return string the URL for sorting. False if the attribute is invalid. * @see attributeOrders * @see params */ public function createUrl($attribute) { $params = [$this->sortParam => $this->createSortParam($attribute)]; if (is_array($this->url)) { return Url::modify(array_merge($this->url, $params)); } elseif ($this->url instanceof Url) { return $this->url->setQueryParams($params)->get(); } return Url::modify($params); }
/** * Redirects the browser to the specified URL. * This method is a shortcut to {@see \rock\response\Response::redirect()}. * * You can use it in an action by returning the {@see \rock\response\Response} directly: * * ```php * // stop executing this action and redirect to login page * return $this->redirect(['login']); * ``` * * @param string|array $url the URL to be redirected to. This can be in one of the following formats: * * - a string representing a URL (e.g. "http://example.com") * - a string representing a URL alias (e.g. "@example.com") * * Any relative URL will be converted into an absolute one by prepending it with the host info * of the current request. * * @param integer $statusCode the HTTP status code. Defaults to 302. * See <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html> * for details about HTTP status code * @return Response the current response object */ public function redirect($url, $statusCode = 302) { return $this->response->redirect(Url::modify($url, Url::ABS), $statusCode); }
/** * @inheritdoc */ public function get() { return \rock\url\Url::modify($this->modify, $this->config); }
/** * Refreshes the current page. * * The effect of this method call is the same as the user pressing the refresh button of his browser * (without re-posting data). * * In a controller action you may use this method like this: * * ``php * return Rock::$app->response->refresh(); * ``` * * @param array $modify * @return Response the response object itself */ public function refresh(array $modify = null) { return $this->redirect(Url::modify($modify, Url::ABS)); }
/** * Generates relative URL * * @param string $url the parameter to be used to generate a valid URL * @param array $config * @return string the generated relative URL */ public function url($url, $config = []) { return Url::modify($url, $config); }
/** * Generates an image tag. * * @param array|string $src the image URL. This parameter will be * processed by {@see \rock\url\Url::getAbsoluteUrl()} . * @param array $options the tag options in terms of name-value pairs. These will be rendered as * the attributes of the resulting tag. The values will be HTML-encoded using {@see \rock\template\Html::encode()} . * If a value is null, the corresponding attribute will not be rendered. * See {@see \rock\template\Html::renderTagAttributes()} for details on how attributes are being rendered. * @return string the generated image tag */ public static function img($src, $options = []) { if (!empty($src) && strpos($src, 'data:') !== 0) { $src = (array) $src; if (!isset($src['@scheme'])) { $src['@scheme'] = Url::ABS; } $src = Url::modify($src); } $options['src'] = $src; if (!isset($options['alt'])) { $options['alt'] = ''; } return static::tag('img', '', $options); }
protected function calculateLastPage(array $data, $pageParam) { if (!($pageLast = (int) $data['pageLast'])) { return null; } $this->_pageArgs[$pageParam] = $pageLast; $placeholders = ['url' => $url = Url::modify($this->url + $this->_pageArgs, ['request' => $this->template->request]), 'pageLastName' => $this->template->replace($this->pageLastName)]; return $this->template->replaceByPrefix($this->pageLastTpl, $placeholders); }
/** * Creates the URL suitable for pagination with the specified page number. * This method is mainly called by pagers when creating URLs used to perform pagination. * @param integer $page the zero-based page number that the URL should point to. * @param null $limit * @return string the created URL * @throws \rock\url\UrlException */ public function createUrl($page, $limit = null) { $params = [$this->pageParam => (int) $page]; $limit = (int) $limit; if ($limit <= 0) { $limit = $this->getLimit(); } if ($limit != $this->defaultLimit) { $params[$this->limitParam] = $limit; } else { unset($params[$this->limitParam]); } if (is_array($this->url)) { return Url::modify(array_merge($this->url, $params)); } elseif ($this->url instanceof Url) { return $this->url->setQueryParams($params)->get(); } return Url::modify($params); }
protected function getMessageLogout(CSRF $CSRF, $key, $layout = '@common.views/elements/alert-info') { $args = [$CSRF->csrfParam => $CSRF->get(), 'service' => 'logout']; $content = i18n::t($key, ['url' => Url::set()->addArgs($args)->getRelative()]); return $this->template->getChunk($layout, ['output' => $content]); }