/**
  * Load user model
  * @param null $id
  * @return YdUser
  */
 public function getUser($id = null)
 {
     if ($this->_userModel === null && YdHelper::tableExists(YdUser::model()->tableName())) {
         $this->_userModel = YdUser::model()->findByPk($id !== null ? $id : $this->id);
     }
     return $this->_userModel;
 }
 /**
  * Authentication for Change User
  *
  * @return bool
  */
 public function authenticateChangeUser()
 {
     $username = strtolower($this->username);
     $user = YdUser::model()->find('(LOWER(username)=? OR LOWER(email)=?) AND web_status=1 AND deleted IS NULL', array($username, $username));
     if ($user === null) {
         return $this->errorCode = self::ERROR_USERNAME_INVALID;
     }
     if ($this->password != Yii::app()->user->user->password) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
     } else {
         $this->_id = $user->id;
         $this->username = $user->username ? $user->username : $user->email;
         $this->errorCode = self::ERROR_NONE;
         $this->setState('UserIdentity_method', 'authenticateChangeUser');
     }
     // returns true if no error, false if error
     return $this->errorCode == self::ERROR_NONE;
 }
 /**
  * @return bool
  */
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     // create user
     $user = new YdUser();
     $user->username = $this->username;
     $user->first_name = $this->first_name;
     $user->last_name = $this->last_name;
     $user->email = $this->email;
     $user->password = $user->hashPassword($this->password);
     $user->web_status = 1;
     if (!$user->save()) {
         return false;
     }
     YdEMailHelper::sendUserWelcome($user);
     // login
     $this->login();
     return $user;
 }
 /**
  * Deletes a particular model.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id = null)
 {
     $task = YdHelper::getSubmittedField('task', 'YdUser') == 'undelete' ? 'undelete' : 'delete';
     if (YdHelper::getSubmittedField('confirm', 'YdUser')) {
         foreach (YdHelper::getGridIds($id) as $_id) {
             $user = YdUser::model()->findByPk($_id);
             // check access
             if (!$user->checkUserAccess(Yii::app()->user->id)) {
                 continue;
             }
             call_user_func(array($user, $task));
             Yii::app()->user->addFlash(strtr('User :name has been :tasked.', array(':name' => $user->getName(), ':tasked' => $task . 'd')), 'success');
         }
         $this->redirect(Yii::app()->returnUrl->getUrl(Yii::app()->user->getState('index.user', array('/user/index'))));
     }
     $this->render('delete', array('id' => $id, 'task' => $task));
 }