public function actionLogin() { $modelLoginFrom = new LoginForm(); if ($modelLoginFrom->load(\Yii::$app->getRequest()->getBodyParams(), '') && $modelLoginFrom->login()) { $post = \Yii::$app->getRequest()->getBodyParams(); $modelUser = new User(); $modelRole = new Role(); $result = $modelRole->find()->where(['=', 'id', \Yii::$app->user->identity->getRole()])->all(); $resultuserdata = $modelUser->find()->where(['=', 'name', $post['name']])->one(); $session = new Session(); $session->open(); $session->set('role', $result[0]->name); $session->close(); return ['username' => $post['name'], 'role' => $result[0]->name, 'isLogined' => true, 'userDataID' => $resultuserdata->id]; } else { return $modelLoginFrom; } }
public function checkLogin() { if (!isset($_POST['username']) || !isset($_POST['password']) || empty($_POST['username'])) { Session::set('error', "Login credentials were empty or missing."); header("Location: " . BASE_URL . "/login"); exit; } # Check credentials and then get the account id $accountID = $this->model->checkCredentials(); if (!$accountID) { Session::set('error', $this->model->errorMsg); header("Location: " . BASE_URL . "/login"); exit; } # Check for account info and assign to session if (isset($accountID) && !empty($accountID)) { Session::set('accountID', $accountID); header("Location: " . BASE_URL . "/home"); exit; } Session::set('error', "Login has failed."); header("Location: " . BASE_URL . "/login"); exit; }