define [ "dojo/_base/declare", "dojo/_base/json", "dojo/Evented", "dojo/request" ], (declare, json, Evented, request) -> Session = declare [Evented], info: null get: () -> @info restore: () -> request '/api/login', method: "GET" handleAs: "json" .then (res) => @_set res , () => throw (@_set null) login: (username, password) -> request '/api/login', method: "POST" handleAs: "json" data: username: username password: password .then (res) => @_set res , () => throw (@_set null) logout: () -> request '/api/logout', method: "POST" handleAs: "json" .then (res) => @_set null , () => @_set null _set: (newInfo) -> if (newInfo isnt @info) @info = newInfo @emit 'change', @info @info new Session()