$.cookie.json = true @Botleagues = url: 'https://api.local.botleagues.camilstaps.nl' cookie_login_email: 'botleagues_login_email' cookie_login_user_id: 'botleagues_login_user_id' cookie_login_token: 'botleagues_login_token' cookie_login_valid_till: 'botleagues_login_valid_till' request: (user_options) -> callback = user_options.callback options = method: 'GET' dataType: 'json' complete: (data) -> callback data.responseJSON url = Botleagues.url + '/' + user_options.endpoint delete user_options.callback delete user_options.endpoint for key, option of user_options options[key] = option jQuery.ajax url, options return login: (email, password) -> Botleagues.request endpoint: 'user_token' method: 'POST' callback: BotleaguesCallback.login headers: 'Authorization': 'Basic ' + btoa(email + ':' + password) $.cookie Botleagues.cookie_login_email, email return logout: -> Botleagues.clearLoginCookies() window.location = '/' return clearLoginCookies: -> $.removeCookie Botleagues.cookie_login_email $.removeCookie Botleagues.cookie_login_user_id $.removeCookie Botleagues.cookie_login_token $.removeCookie Botleagues.cookie_login_valid_till return