Class frontend\controllers\SiteController
Inheritance | frontend\controllers\SiteController » yii\web\Controller |
---|---|
Source Code | https://github.com/yiisoft/yii2-app-advanced/blob/master/frontend/controllers/SiteController.php |
Site controller
Public Methods
Method | Description | Defined By |
---|---|---|
actionAbout() | Displays about page. | frontend\controllers\SiteController |
actionContact() | Displays contact page. | frontend\controllers\SiteController |
actionIndex() | Displays homepage. | frontend\controllers\SiteController |
actionLogin() | Logs in a user. | frontend\controllers\SiteController |
actionLogout() | Logs out the current user. | frontend\controllers\SiteController |
actionRequestPasswordReset() | Requests password reset. | frontend\controllers\SiteController |
actionResendVerificationEmail() | Resend verification email | frontend\controllers\SiteController |
actionResetPassword() | Resets password. | frontend\controllers\SiteController |
actionSignup() | Signs user up. | frontend\controllers\SiteController |
actionVerifyEmail() | Verify email address | frontend\controllers\SiteController |
actions() | frontend\controllers\SiteController | |
behaviors() | frontend\controllers\SiteController |
Method Details
Displays about page.
public mixed actionAbout ( ) |
public function actionAbout()
{
return $this->render('about');
}
Displays contact page.
public mixed actionContact ( ) |
public function actionContact()
{
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
} else {
Yii::$app->session->setFlash('error', 'There was an error sending your message.');
}
return $this->refresh();
}
return $this->render('contact', [
'model' => $model,
]);
}
Displays homepage.
public mixed actionIndex ( ) |
public function actionIndex()
{
return $this->render('index');
}
Logs in a user.
public mixed actionLogin ( ) |
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
}
$model->password = '';
return $this->render('login', [
'model' => $model,
]);
}
Logs out the current user.
public mixed actionLogout ( ) |
public function actionLogout()
{
Yii::$app->user->logout();
return $this->goHome();
}
Requests password reset.
public mixed actionRequestPasswordReset ( ) |
public function actionRequestPasswordReset()
{
$model = new PasswordResetRequestForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->sendEmail()) {
Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
return $this->goHome();
}
Yii::$app->session->setFlash('error', 'Sorry, we are unable to reset password for the provided email address.');
}
return $this->render('requestPasswordResetToken', [
'model' => $model,
]);
}
Resend verification email
public mixed actionResendVerificationEmail ( ) |
public function actionResendVerificationEmail()
{
$model = new ResendVerificationEmailForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->sendEmail()) {
Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
return $this->goHome();
}
Yii::$app->session->setFlash('error', 'Sorry, we are unable to resend verification email for the provided email address.');
}
return $this->render('resendVerificationEmail', [
'model' => $model
]);
}
Resets password.
public mixed actionResetPassword ( $token ) | ||
$token | string | |
throws | \yii\web\BadRequestHttpException |
---|
public function actionResetPassword($token)
{
try {
$model = new ResetPasswordForm($token);
} catch (InvalidArgumentException $e) {
throw new BadRequestHttpException($e->getMessage());
}
if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
Yii::$app->session->setFlash('success', 'New password saved.');
return $this->goHome();
}
return $this->render('resetPassword', [
'model' => $model,
]);
}
Signs user up.
public mixed actionSignup ( ) |
public function actionSignup()
{
$model = new SignupForm();
if ($model->load(Yii::$app->request->post()) && $model->signup()) {
Yii::$app->session->setFlash('success', 'Thank you for registration. Please check your inbox for verification email.');
return $this->goHome();
}
return $this->render('signup', [
'model' => $model,
]);
}
Verify email address
public \frontend\controllers\yii\web\Response actionVerifyEmail ( $token ) | ||
$token | string | |
throws | \yii\web\BadRequestHttpException |
---|
public function actionVerifyEmail($token)
{
try {
$model = new VerifyEmailForm($token);
} catch (InvalidArgumentException $e) {
throw new BadRequestHttpException($e->getMessage());
}
if (($user = $model->verifyEmail()) && Yii::$app->user->login($user)) {
Yii::$app->session->setFlash('success', 'Your email has been confirmed!');
return $this->goHome();
}
Yii::$app->session->setFlash('error', 'Sorry, we are unable to verify your account with provided token.');
return $this->goHome();
}
public void actions ( ) |
public function actions()
{
return [
'error' => [
'class' => \yii\web\ErrorAction::class,
],
'captcha' => [
'class' => \yii\captcha\CaptchaAction::class,
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
public void behaviors ( ) |
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::class,
'only' => ['logout', 'signup'],
'rules' => [
[
'actions' => ['signup'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'logout' => ['post'],
],
],
];
}