public function _restPutResource($id) {

    $oldUser = clone $this->model;
    $this->model->loadFromExternalSource($this->getApp()->getRequest()->getBody());

    if (!empty($this->model->password)) {
      if (strlen($this->model->password) < 6) {
        $this->getApp()->returnError(Errors::$SHORT_PASSWORD);
      }

      $this->model->passHash = Identity::passHash($this->model->password, $oldUser->salt);
      $this->model->password = NULL;

      /**
       * Deletes all sessions except for the current one for the user whose password changed
       *
       * @var $session Session
       */
      $session = call_user_func($this->sessionModelClass . '::init', $this->getApp());

      $deleteSessions = $session->findAllByField('userId', $id);
      foreach ($deleteSessions as $session) {
        if ($session->sessionId == $this->getApp()->getRequest()->session->sessionId) {
          continue;
        }
        $session->delete();
      }
    }

    if (empty($this->model->email)) {
      $this->getApp()->returnError(Errors::$EMAIL_REQUIRED);
    }

    if ($this->model->email != $oldUser->email && $this->model->findByField('email', $this->model->email)) {
      $this->getApp()->returnError(Errors::$EMAIL_EXISTS);
    }

    $this->model->created = $oldUser->created;
    $this->model->salt = $oldUser->salt;
    $this->model->lastAccessed = $oldUser->lastAccessed;
    $this->model->save();
    echo $this->model->outputJSON();
  }
public function _restPutResource($id) {

    $oldUser = clone $this->model;
    $this->model->loadFromExternalSource($this->getApp()->getRequest()->getBody());

    if (!empty($this->model->password)) {
      if (strlen($this->model->password) < 6) {
        $this->getApp()->returnError(Errors::$SHORT_PASSWORD);
      }

      $this->model->passHash = Identity::passHash($this->model->password, $oldUser->salt);
      $this->model->password = NULL;

      /**
       * Deletes all sessions except for the current one for the user whose password changed
       *
       * @var $session Session
       */
      $session = call_user_func($this->sessionModelClass . '::init', $this->getApp());

      $deleteSessions = $session->findAllByField('userId', $id);
      foreach ($deleteSessions as $session) {
        if ($session->sessionId == $this->getApp()->getRequest()->session->sessionId) {
          continue;
        }
        $session->delete();
      }
    }

    if (empty($this->model->email)) {
      $this->getApp()->returnError(Errors::$EMAIL_REQUIRED);
    }

    if ($this->model->email != $oldUser->email && $this->model->findByField('email', $this->model->email)) {
      $this->getApp()->returnError(Errors::$EMAIL_EXISTS);
    }

    $this->model->created = $oldUser->created;
    $this->model->salt = $oldUser->salt;
    $this->model->lastAccessed = $oldUser->lastAccessed;
    $this->model->save();
    echo $this->model->outputJSON();
  }
public function _restPutResource ( $ id ) { $ oldUser = clone $ this -> model ; $ this -> model -> loadFromExternalSource ( $ this -> getApp ( ) -> getRequest ( ) -> getBody ( ) ) ; if ( ! empty ( $ this -> model -> password ) ) { if ( strlen ( $ this -> model -> password ) < 6 ) { $ this -> getApp ( ) -> returnError ( Errors :: $ SHORT_PASSWORD ) ; } $ this -> model -> passHash = Identity :: passHash ( $ this -> model -> password , $ oldUser -> salt ) ; $ this -> model -> password = NULL ; /**
       * Deletes all sessions except for the current one for the user whose password changed
       *
       * @var $session Session
       */ $ session = call_user_func ( $ this -> sessionModelClass . '::init' , $ this -> getApp ( ) ) ; $ deleteSessions = $ session -> findAllByField ( 'userId' , $ id ) ; foreach ( $ deleteSessions as $ session ) { if ( $ session -> sessionId == $ this -> getApp ( ) -> getRequest ( ) -> session -> sessionId ) { continue ; } $ session -> delete ( ) ; } } if ( empty ( $ this -> model -> email ) ) { $ this -> getApp ( ) -> returnError ( Errors :: $ EMAIL_REQUIRED ) ; } if ( $ this -> model -> email != $ oldUser -> email && $ this -> model -> findByField ( 'email' , $ this -> model -> email ) ) { $ this -> getApp ( ) -> returnError ( Errors :: $ EMAIL_EXISTS ) ; } $ this -> model -> created = $ oldUser -> created ; $ this -> model -> salt = $ oldUser -> salt ; $ this -> model -> lastAccessed = $ oldUser -> lastAccessed ; $ this -> model -> save ( ) ; echo $ this -> model -> outputJSON ( ) ; }
Updates a user's info.  All fields will be replaced with the values given.  Empty fields will be set to null.

~~~
{
"userId": userId,
"created": timeDate,
"firstName": string,
"lastName": string,
"email": string,
"password": null,
"newSessionId": null,
}
~~~

@docs-param user string body required A user object to create in the database

@param $id string The id of the user you are trying to update
Updates a user s info . All fields will be replaced with the values given . Empty fields will be set to null .