ezsystems/ez-js-rest-client — pull request #41 by dpobel (2014-04-29 07:31:04+00:00)
Title: EZP-22731: As an editor, I want to be able to login in the PlatformUI

JIRA: https://jira.ez.no/browse/EZP-22731

# Description

This PR allows to handle the login/logout separately from the others requests. Before this PR, you had to provide the login and the password at the instantiation time and the login was done lazily while performing the first request:

```js
var capi = new CAPI(
'http://ezpublish5.loc/',
new SessionAuthAgent({
login: 'admin',
password: 'ezpublish5'
})
);

capi.getContentService().loadRoot(function (error, result) {
if ( !error ) {
console.log('Login was done transparently before loading the root');
capi.getUserService().logOut(function (error, result) {
if ( !error ) {
console.log('Bye!');
}
});
}
});
```

With this patch, this is still valid (except the `UserService.logOut` method which has been replaced by `CAPI.logOut`) you can now also write something like:

```js
var capi = new CAPI('http://ezpublish.loc/', new SessionAuthAgent());

capi.logIn({login: 'admin', password: 'publish'}, function (error, result) {
if ( !error ) {
console.log('Youhou, I\'m logged in');
capi.getContentService().loadRoot(function (error, result) {
if ( !error ) {
console.log('the root was loaded');
capi.logOut(function (error, result) {
if ( !error ) {
console.log('Bye!');
}
});
}
});
}
});
```

## API changes in details:

* the CAPI object now has 3 new methods:
* `logIn([credentials,] callback)`
* `logOut(callback)`
* 'isLoggedIn(callback)`
* the auth agents now have 4 new methods:
* `setCredentials(credentials)` (so you are not forced to provide the credentials at build time)
* `logIn(callback)`
* `logOut(callback)`
* `isLoggedIn(callback)`
* the user service has a new method and `logOut` was removed
* `refreshSession(sessionId, callback)` used by to `SessionAuthAgent.isLoggedIn`

# Tests

unit tests + manual tests in PlatformUI (PR to come)

# TODO

* [ ] Rebuild the CAPI before merging
* [ ] Check the Promise version ?