Last change
on this file since 468 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
|
Rev | Line | |
---|
[466] | 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 |
---|
[468] | 9 | |
---|
[466] | 10 | get: () -> |
---|
| 11 | @info |
---|
[468] | 12 | |
---|
[466] | 13 | restore: () -> |
---|
| 14 | request '/api/login', |
---|
| 15 | method: "GET" |
---|
| 16 | handleAs: "json" |
---|
| 17 | .then (res) => |
---|
| 18 | @_set res |
---|
| 19 | , () => |
---|
[468] | 20 | throw (@_set null) |
---|
| 21 | |
---|
[466] | 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 | , () => |
---|
[468] | 32 | throw (@_set null) |
---|
| 33 | |
---|
[466] | 34 | logout: () -> |
---|
| 35 | request '/api/logout', |
---|
| 36 | method: "POST" |
---|
| 37 | handleAs: "json" |
---|
[468] | 38 | .then (res) => |
---|
| 39 | @_set null |
---|
| 40 | , () => |
---|
| 41 | @_set null |
---|
[466] | 42 | |
---|
| 43 | _set: (newInfo) -> |
---|
[468] | 44 | if (newInfo isnt @info) |
---|
| 45 | @info = newInfo |
---|
| 46 | @emit 'change', @info |
---|
| 47 | @info |
---|
[466] | 48 | |
---|
| 49 | new Session() |
---|
Note: See
TracBrowser
for help on using the repository browser.