Last change
on this file since 478 was
468,
checked in by hendrikvanantwerpen, 12 years ago
|
Improved authentication
- Authentication cannot be cancelled, removing a lot of weird race
conditions.
- We offer a request provider that has automatic retry in case of
authentication failures.
- Reduced dependency on LoginDialog? by having it act independent
based on events. Other modules can just depend on 'session'.
|
File size:
1.2 KB
|
Line | |
---|
1 | define [ |
---|
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 | |
---|
10 | get: () -> |
---|
11 | @info |
---|
12 | |
---|
13 | restore: () -> |
---|
14 | request '/api/login', |
---|
15 | method: "GET" |
---|
16 | handleAs: "json" |
---|
17 | .then (res) => |
---|
18 | @_set res |
---|
19 | , () => |
---|
20 | throw (@_set null) |
---|
21 | |
---|
22 | login: (username, password) -> |
---|
23 | request '/api/login', |
---|
24 | method: "POST" |
---|
25 | handleAs: "json" |
---|
26 | data: |
---|
27 | username: username |
---|
28 | password: password |
---|
29 | .then (res) => |
---|
30 | @_set res |
---|
31 | , () => |
---|
32 | throw (@_set null) |
---|
33 | |
---|
34 | logout: () -> |
---|
35 | request '/api/logout', |
---|
36 | method: "POST" |
---|
37 | handleAs: "json" |
---|
38 | .then (res) => |
---|
39 | @_set null |
---|
40 | , () => |
---|
41 | @_set null |
---|
42 | |
---|
43 | _set: (newInfo) -> |
---|
44 | if (newInfo isnt @info) |
---|
45 | @info = newInfo |
---|
46 | @emit 'change', @info |
---|
47 | @info |
---|
48 | |
---|
49 | new Session() |
---|
Note: See
TracBrowser
for help on using the repository browser.