public function authenticate() { $userData = $this->username; $password = $this->password; $hashedPassword = md5($password); //Client $user = User::model()->find(array('condition' => "Num_bank_cart = '{$userData}'")); $pass = User::model()->find(array('condition' => "Password = '******'")); //Inspector $insp = Inspector::model()->find(array('condition' => "Login = '******'")); $inspPass = Inspector::model()->find(array('condition' => "Password = '******'")); $client = !empty($user); $inspLog = !empty($insp); if ($client || $userData == 'admin' || $inspLog) { $hashedPassword = md5($password); if (!empty($pass) || $password == 'admin' || !empty($inspPass)) { $session = new CHttpSession(); $session->open(); $session['login'] = $userData; if ($client != "") { $data = 'client'; } else { if ($inspLog != "") { $data = 'inspector'; } else { $data = 'admin'; } } $session['data'] = $data; $session->closeSession(true); $this->errorCode = self::ERROR_NONE; } else { $this->errorCode = self::ERROR_PASSWORD_INVALID; } } else { $this->errorCode = self::ERROR_USERNAME_INVALID; } return !$this->errorCode; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Inspector the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Inspector::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }