public function authenticate() { $userName = strtolower(trim($this->username, '')); $encriptPassword = UsefullFunction::encriptPassword($this->password); $user = Users::model()->find(array('condition' => 'username=:username AND status=:status', 'params' => array(':username' => $userName, ':status' => Users::STATUS_ACTIVE))); if ($user === NULL) { $this->errorCode = self::ERROR_USERNAME_INVALID; } elseif ($user->password !== $encriptPassword) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { //$this->setState('userType', $user->typeId); $user->loginCount = $user->loginCount + 1; $user->ipAddress = $_SERVER['SERVER_ADDR']; $user->save(); $this->setState('userid', $user->id); $this->setState('username', $user->username); $this->setState('userType', $user->typeId); $this->_id = $user->id; if ($user->typeId != Users::IS_ADMIN) { Yii::app()->session['userBy'] = $user->id; Yii::app()->session['userType'] = $user->typeId; } //$this->setState('lastLoginTime', $user->lastLoginTime); $this->errorCode = self::ERROR_NONE; } return !$this->errorCode; }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $msg = ''; $model = $this->loadModel($id); $oldPass = $model->password; $model->password = ''; // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['Users'])) { $model->attributes = $_POST['Users']; $model->username = strtolower(trim($model->username, '')); if (strlen($model->password) > 0) { $model->password = UsefullFunction::encriptPassword($model->password); } else { $model->password = $oldPass; } if ($model->save()) { $msg = "<div class='alert alert-success fade in'><i data-dismiss='alert' class='icon-remove close'></i>Users Update Successfully</div>"; } } $this->render('_form', array('model' => $model, 'msg' => $msg)); }