source: Dev/trunk/src/client/qed-client/session.coffee @ 490

Last change on this file since 490 was 487, checked in by hendrikvanantwerpen, 11 years ago

Completed migration to API, without CouchDB proxy.

Move to API is now completed. The full API is password protected, a very
limited API is exposed for respondents, which works with secrets that
are passed in URLs.

Serverside the HTTPResult class was introduced, which is similar to
Promises, but specifically for HTTP. It carries a status code and
response and makes it easier to extract parts of async handling in
separate functions.

Fixed a bug in our schema (it seems optional attributes don't exist but
a required list does). Verification of our schema by grunt-tv4 didn't
work yet. Our schema is organized the wrong way (this is fixable),
but the json-schema schema has problems with simple types and $refs.

File size: 1.2 KB
Line 
1define [
2    "dojo/_base/declare",
3    "dojo/_base/json",
4    "dojo/Deferred",
5    "dojo/Evented",
6    "dojo/request"
7], (declare, json, Deferred, Evented, request) ->
8    Session = declare [Evented],
9        info: null
10
11        get: () ->
12            @info
13
14        restore: () ->
15            request '/api/login',
16                method: "GET"
17                handleAs: "json"
18            .then (res) =>
19                @_set res
20            , () =>
21                new Deferred().reject (@_set null)
22
23        login: (username, password) ->
24            request '/api/login',
25                method: "POST"
26                handleAs: "json"
27                data:
28                    username: username
29                    password: password
30            .then (res) =>
31                @_set res
32            , () =>
33                new Deferred().reject (@_set null)
34
35        logout: () ->
36            request '/api/logout',
37                method: "POST"
38                handleAs: "json"
39            .then (res) =>
40                @_set null
41            , () =>
42                @_set null
43       
44        _set: (newInfo) ->
45            if (newInfo isnt @info)
46                @info = newInfo
47                @emit 'change', @info
48            @info
49
50    new Session()
Note: See TracBrowser for help on using the repository browser.