aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorCamil Staps2015-05-12 22:31:07 +0200
committerCamil Staps2015-05-12 22:31:07 +0200
commitf51ce6f4acf28c224ec4a02f35ae35726cdc4c38 (patch)
treea71ce2023602daf1bb3caf0d31bab34b86939905 /src/js
parentLogin form start (diff)
Working login, but doesn't save token yet
Diffstat (limited to 'src/js')
-rw-r--r--src/js/Botleagues.js24
-rw-r--r--src/js/BotleaguesCallback.js13
-rw-r--r--src/js/BotleaguesFrontend.js8
-rw-r--r--src/js/forms.js7
4 files changed, 40 insertions, 12 deletions
diff --git a/src/js/Botleagues.js b/src/js/Botleagues.js
index f9d34b7..2ab1bc7 100644
--- a/src/js/Botleagues.js
+++ b/src/js/Botleagues.js
@@ -2,7 +2,9 @@ function Botleagues(){}
Botleagues.url = 'https://api.local.botleagues.camilstaps.nl';
-Botleagues.request = function(user_options, callback) {
+Botleagues.request = function(user_options) {
+ var callback = user_options.callback;
+
var options = {
endpoint: null,
method: 'GET',
@@ -11,16 +13,30 @@ Botleagues.request = function(user_options, callback) {
callback(data.responseJSON);
}
};
+
+ var url = Botleagues.url + '/' + user_options['endpoint'];
+ delete user_options['callback'];
+ delete user_options['endpoint'];
+
for (var name in user_options) {
options[name] = user_options[name];
}
- var url = Botleagues.url + '/' + options['endpoint'];
- delete options['endpoint'];
-
jQuery.ajax(url, options);
};
Botleagues.redirect = function(user_options) {
window.location = Botleagues.url + '/' + user_options['endpoint'];
+};
+
+Botleagues.login = function(username, password) {
+ Botleagues.request({
+ endpoint: 'user_token',
+ method: 'POST',
+ callback: BotleaguesCallback.login,
+ async: false,
+ headers: {
+ 'Authorization': 'Basic ' + btoa(username + ':' + password)
+ }
+ });
}; \ No newline at end of file
diff --git a/src/js/BotleaguesCallback.js b/src/js/BotleaguesCallback.js
index f162e7c..3b1de02 100644
--- a/src/js/BotleaguesCallback.js
+++ b/src/js/BotleaguesCallback.js
@@ -29,4 +29,17 @@ BotleaguesCallback.register = function(data) {
}
}
}
+};
+
+BotleaguesCallback.login = function(data) {
+ if (data.user_token) {
+ BotleaguesFrontend.error({
+ message: "Login successful!",
+ type: 'success'
+ });
+ } else {
+ BotleaguesFrontend.error({
+ message: data.error ? data.error : "Could not login."
+ });
+ }
}; \ No newline at end of file
diff --git a/src/js/BotleaguesFrontend.js b/src/js/BotleaguesFrontend.js
index e9ab570..c25a7f2 100644
--- a/src/js/BotleaguesFrontend.js
+++ b/src/js/BotleaguesFrontend.js
@@ -18,11 +18,5 @@ BotleaguesFrontend.error = function(user_options) {
html = $(html);
- html.prependTo(options.prepend_to).delay(3000).fadeOut().queue(html.remove);
-};
-
-BotleaguesFrontend.login = function() {
- Botleagues.redirect({
- endpoint: 'user/login?redirect=http://local.botleagues.camilstaps.nl/'
- });
+ html.hide().prependTo(options.prepend_to).slideDown().delay(3000).fadeOut().queue(html.remove);
}; \ No newline at end of file
diff --git a/src/js/forms.js b/src/js/forms.js
index e096794..c6bdffe 100644
--- a/src/js/forms.js
+++ b/src/js/forms.js
@@ -14,4 +14,9 @@ $('form.form-register').submit(function(){
$('.btn-botleagues-login').focus(function(){
$('#login-block').slideDown();
$('#login-email').focus();
-}); \ No newline at end of file
+});
+var login = function(){
+ Botleagues.login($('#login-email').val(), $('#login-password').val());
+};
+$('#login-submit').click(login);
+$('#login-form').submit(login); \ No newline at end of file