/** * @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'); }
/** * 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); }
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); }
<?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');
/** * 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); }
/** * @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]); }