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

Last change on this file since 467 was 466, checked in by hendrikvanantwerpen, 12 years ago

Added authentication (fixed user now).

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