fatkulnurk
7/13/2018 - 2:24 AM

actionLogin()


    public function actionLogin()
    {
        if (!Yii::$app->user->isGuest) {
            return $this->goHome();
        }

        $session = Yii::$app->session;
        $session->open();



        if (!$session['user']['login']){
            $model = new LoginForm();
            if ($model->load(Yii::$app->request->post()) && $model->login()) {
                //return $this->goBack();
                $userdata = BackendUser::find()->where(['id'=>Yii::$app->user->getId()])->asArray()->all();
                $session['user'] = array(
                    "login" => true,
                    "id" => $userdata[0]['id'],
                    "username" => $userdata[0]['username'],
                    "fullname" => $userdata[0]['fullname'],
                );

                return $this->redirect(["site/index"]);
            } else {
                $model->password = '';

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