public function actionRegister() { if (!Application::$app->getUser()->getIsGuest()) { Application::$app->getSession()->setFlash('register-warning', 'You must be unauthorized'); return $this->redirect('site/index'); } if (!empty($_POST) && (!isset($_POST['email']) || empty($_POST['email']) || !isset($_POST['password']) || empty($_POST['password']) || !isset($_POST['repeat_password']) || empty($_POST['repeat_password']))) { Application::$app->getSession()->setFlash('register-danger', 'Please fill all fields.'); } elseif (!empty($_POST) && $_POST['password'] !== $_POST['repeat_password']) { Application::$app->getSession()->setFlash('register-danger', 'Passwords not match.'); } elseif (!empty($_POST)) { //check email $model = User::findIdentityByEmail($_POST['email']); if (!empty($model)) { Application::$app->getSession()->setFlash('register-danger', 'User with email ' . HtmlPurifier::process($_POST['email']) . ' already registered.'); return $this->redirect('user/register'); } $model = new User(); $model->load($_POST); $model->insert(); Application::$app->getSession()->setFlash('register-success', 'User successfully created.'); return $this->redirect('user/login'); } return $this->render('user/register'); }
/** * Renders a static string by applying a layout. * @param string $content the static string being rendered * @return string the rendering result of the layout with the given static string as the `$content` variable. */ public function renderContent($content) { $layoutFile = $this->findLayoutFile(); if ($layoutFile !== false) { $htmlPurifier = new HtmlPurifier(); $htmlPurifier->process($content); return $this->getView()->renderFile($layoutFile, ['content' => $content]); } else { return $content; } }