Class frontend\controllers\SiteController

Inheritancefrontend\controllers\SiteController » yii\web\Controller
Source Code https://github.com/yiisoft/yii2-app-advanced/blob/master/frontend/controllers/SiteController.php

Site controller

Method Details

Hide inherited methods

actionAbout() public method

Displays about page.

public mixed actionAbout ( )

                public function actionAbout()
{
    return $this->render('about');
}

            
actionContact() public method

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,
    ]);
}

            
actionIndex() public method

Displays homepage.

public mixed actionIndex ( )

                public function actionIndex()
{
    return $this->render('index');
}

            
actionLogin() public method

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,
    ]);
}

            
actionLogout() public method

Logs out the current user.

public mixed actionLogout ( )

                public function actionLogout()
{
    Yii::$app->user->logout();
    return $this->goHome();
}

            
actionRequestPasswordReset() public method

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,
    ]);
}

            
actionResendVerificationEmail() public method

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
    ]);
}

            
actionResetPassword() public method

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,
    ]);
}

            
actionSignup() public method

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,
    ]);
}

            
actionVerifyEmail() public method

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();
}

            
actions() public method

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,
        ],
    ];
}

            
behaviors() public method

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'],
            ],
        ],
    ];
}