public function actionLogin($scenario = null)
    {
        /** @var LoginForm */
        $model = $this->module->createFormModel('LoginForm');
        $scenarios = $model->scenarios();
        if ($scenario !== null && in_array($scenario, array_keys($scenarios))) {
            $model->scenario = $scenario;
        }

        if ($model->load($_POST)) {
            if (Yii::$app->request->isAjax) {
                Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

                return \yii\widgets\ActiveForm::validate($model);
            }
            if ($model->validate()) {
                if (($model->scenario !== 'reset' || $model->resetPassword($model->newPassword)) && $model->login($this->module->rememberMeDuration)) {
                    return $this->afterLogin();
                } else {
                    Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to change password or log in using new password.'));
                }
            }
        }
        list($view, $params) = $this->getScenarioView($model->scenario, 'login');

        return $this->render($view, array_merge(['model' => $model], $params));
    }