aboutsummaryrefslogtreecommitdiff
path: root/src/js/Botleagues.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/Botleagues.coffee')
-rw-r--r--src/js/Botleagues.coffee54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/js/Botleagues.coffee b/src/js/Botleagues.coffee
new file mode 100644
index 0000000..06ace76
--- /dev/null
+++ b/src/js/Botleagues.coffee
@@ -0,0 +1,54 @@
+$.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 \ No newline at end of file