/**
  * @param Mail $mail
  * @param Users $users
  * @param SignupForm $model
  */
 public function sendMail(Mail $mail, Users $users, SignupForm $model)
 {
     $subject = i18n::t('subjectRegistration', ['site_name' => i18n::t('siteName')]);
     $body = $this->prepareBody($model, $users);
     try {
         $mail->address($users->email)->subject($subject)->body($body)->send();
     } catch (\Exception $e) {
         $model->addError('alerts', i18n::t('failSendEmail'));
         Log::warn(BaseException::convertExceptionToString($e));
     }
 }
 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');
 }
Beispiel #3
0
 /**
  * Translate
  *
  * @param string|array  $keys chain keys
  * @param array $placeholders
  * @param string|null  $category
  * @param string $locale
  * @return null|string
  */
 public static function t($keys, array $placeholders = [], $category = null, $locale = null)
 {
     return i18n::t($keys, $placeholders, $category, $locale);
 }
Beispiel #4
0
 private function _calculateI18N($name, $placeholders = [], $locale = null, $category = null)
 {
     if (!class_exists('rock\\i18n\\i18n')) {
         throw new TemplateException(TemplateException::NOT_INSTALL_I18N);
     }
     return i18n::t(explode('.', $name), $placeholders, $category, $locale);
 }
 public function afterLogin()
 {
     $users = $this->getUsers();
     $users->login_last = DateTime::set()->isoDatetime();
     if (!$users->save()) {
         $this->addError('alerts', i18n::t('failLogin'));
         return;
     }
     $event = new ModelEvent();
     $event->result = $users;
     $this->trigger(self::EVENT_AFTER_LOGIN, $event);
 }
Beispiel #6
0
    } elseif (in_array(current($keys), ['isLogged', 'isAuthenticated'], true)) {
        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');
Beispiel #7
0
<?php

/** @var $this \rock\template\Template */
use rock\helpers\StringHelper;
use rock\widgets\Captcha;
echo $this->getChunk('@frontend.views/sections/top');
?>
<main class="container main form-container" role="main" data-ng-controller="RockFormController"><?php 
echo $this->getSnippet('activeForm', ['model' => $this->getPlaceholder('$root.model', false), 'validate' => true, 'config' => ['action' => '@link.home/signup.html', 'validateOnChanged' => true, 'options' => ['class' => 'form-signup', 'novalidate' => 'novalidate'], 'fieldConfig' => ['template' => "{hint}\n{input}\n{error}"]], 'fields' => ['<h2>[[%signup:upperFirst]]</h2>', 'email' => ['options' => ['inputOptions' => ['class' => 'form-control form-input', 'maxlength' => 30, 'autofocus' => '', 'placeholder' => StringHelper::upperFirst(\rock\i18n\i18n::t('email')), 'data' => ['rock-reset-field-icon' => '']], 'required' => true]], 'username' => ['options' => ['inputOptions' => ['class' => 'form-control form-input', 'maxlength' => 80, 'placeholder' => StringHelper::upperFirst(\rock\i18n\i18n::t('username')), 'data' => ['rock-reset-field-icon' => '']]]], 'password' => ['options' => ['template' => "<div class='inline-column'>{hint}\n{input}<div class='strong-password' data-rock-password-strong='SignupForm.values.password'></div></div>\n{error}", 'inputOptions' => ['class' => 'form-control form-input', 'maxlength' => 20, 'value' => '', 'placeholder' => StringHelper::upperFirst(\rock\i18n\i18n::t('password')), 'data' => ['rock-reset-field-icon' => '']]], 'passwordInput'], 'password_confirm' => ['options' => ['inputOptions' => ['class' => 'form-control form-input', 'maxlength' => 20, 'value' => '', 'placeholder' => StringHelper::upperFirst(\rock\i18n\i18n::t('confirmPassword')), 'data' => ['rock-match' => 'password', 'rock-reset-field-icon' => '']]], 'passwordInput'], 'captcha' => ['options' => ['required' => true], 'widget' => [Captcha::className(), ['template' => '<div class="block-center">{image}</div>{input}', 'output' => Captcha::BASE64, 'options' => ['class' => 'form-control form-input', 'maxlength' => 7, 'value' => '', 'placeholder' => StringHelper::upperFirst(\rock\i18n\i18n::t('captcha'))]]]]], 'submitButton' => [\rock\i18n\i18n::t('signup'), ['class' => 'btn btn-primary', 'name' => 'signup-button']], 'wrapperTpl' => '@INLINE
                    [[!+alerts:notEmpty&then=`@common.views\\elements\\alert-danger`]]
                    [[!+output]]']);
?>
</main>
<script type="text/ng-template" id="form/strong-password">
    <progressbar value="value" type="{{class}}"></progressbar>
</script>
<?php 
echo $this->getChunk('@frontend.views/sections/footer');
Beispiel #8
0
 /**
  * Display notPage layout
  *
  * @param string|null $layout
  * @param array $placeholders list placeholders
  * @return string|void
  */
 public function notPage($layout = null, array $placeholders = [])
 {
     if (isset($this->response)) {
         $this->response->status404();
     }
     $this->getTemplate()->title = StringHelper::upperFirst(i18n::t('notPage'));
     if (!isset($layout)) {
         $layout = '@common.views/layouts/notPage';
     }
     return $this->render($layout, $placeholders);
 }
Beispiel #9
0
 /**
  * @param array $options
  * @return array
  */
 protected function calculateConfirm(array $options)
 {
     $options['data']['rock-match'] = isset($this->formName) ? "{$this->formName}.values.{$options['data']['rock-match']}" : "form.values.{$options['data']['rock-match']}";
     if (!isset($this->ngErrorMessages['match']) && class_exists('\\rock\\i18n\\i18n')) {
         $this->ngErrorMessages['match'] = i18n::t('confirm', [], 'validate');
     }
     return $options;
 }
 public function afterSignup()
 {
     if (!($users = Users::create($this->getAttributes(), $this->defaultStatus, $this->generateToken))) {
         $this->addError('alerts', i18n::t('failSignup'));
         return;
     }
     $this->users = $users;
     $this->users->id = $this->users->primaryKey;
     $event = new ModelEvent();
     $event->result = $users;
     $this->trigger(self::EVENT_AFTER_SIGNUP, $event);
 }
 public function afterRecovery()
 {
     $users = $this->getUsers();
     /** @var Security $security */
     $security = Container::load('security');
     $password = $security->generateRandomString(7);
     $users->setPassword($password);
     if (!$users->save()) {
         $this->addError('alerts', i18n::t('failRecovery'));
         return;
     }
     $event = new ModelEvent();
     $users->password = $password;
     $event->result = $users;
     $this->trigger(self::EVENT_AFTER_RECOVERY, $event);
 }
 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]);
 }
Beispiel #13
0
<?php

return ['db' => ['class' => 'rock\\db\\Connection', 'username' => 'rock', 'password' => 'rock', 'charset' => 'utf8', 'dsn' => 'mysql:host=localhost;dbname=rockdemo;charset=utf8', 'tablePrefix' => 'spt_', 'aliasSeparator' => '__', 'enableSchemaCache' => true], 'template' => ['chroots' => ['@common/views', '@frontend/views']], 'i18n' => ['class' => \rock\i18n\i18n::className(), 'pathsDicts' => ['ru' => ['@common/messages/ru/lang.php', '@common/messages/ru/validate.php', '@frontend/messages/ru/lang.php'], 'en' => ['@common/messages/en/lang.php', '@common/messages/en/validate.php', '@frontend/messages/en/lang.php']]], 'execute' => ['class' => \rock\execute\CacheExecute::className(), 'path' => '@common/runtime/execute'], 'markdown' => ['class' => 'rock\\markdown\\Markdown', 'handlerLinkByUsername' => [\apps\common\configs\MarkdownProperties::className(), 'handlerLinkByUsername']], 'mail' => ['From' => \rock\base\Alias::getAlias('@email')]];