aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2015-05-12 22:31:07 +0200
committerCamil Staps2015-05-12 22:31:07 +0200
commitf51ce6f4acf28c224ec4a02f35ae35726cdc4c38 (patch)
treea71ce2023602daf1bb3caf0d31bab34b86939905
parentLogin form start (diff)
Working login, but doesn't save token yet
-rw-r--r--gulpfile.js2
-rw-r--r--src/css/forms.less6
-rw-r--r--src/include/layout-main.jade10
-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
7 files changed, 51 insertions, 19 deletions
diff --git a/gulpfile.js b/gulpfile.js
index 23b113c..181462c 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -92,7 +92,7 @@ gulp.task('styles', function() {
return file;
}
}}))
- .pipe(changed(dst, { destination: 'style.css' }))
+ //.pipe(changed(dst, { destination: 'style.css' }))
.pipe(gulpif(isBootswatchFile, foreach(function(stream, file) {
var themeName = path.basename(path.dirname(file.path)),
content = replaceAll(baseContent, bootswatch_theme, themeName),
diff --git a/src/css/forms.less b/src/css/forms.less
index 6ddc244..e29f4d7 100644
--- a/src/css/forms.less
+++ b/src/css/forms.less
@@ -1,3 +1,9 @@
#login-block {
display: none;
+
+ #login-form {
+ display: inline-block;
+ float: right;
+ margin-bottom: 0.5em;
+ }
} \ No newline at end of file
diff --git a/src/include/layout-main.jade b/src/include/layout-main.jade
index df3fdc5..7b15138 100644
--- a/src/include/layout-main.jade
+++ b/src/include/layout-main.jade
@@ -24,15 +24,13 @@ html(lang="en")
#messages
#login-block
- form.form-inline#login-form
+ form.form-inline#login-form(action='#',method='post')
.form-group
- label.control-label(for='login-email') Email:
- input.form-control#login-email(type='email')
+ input.form-control#login-email(type='email',placeholder='Email')
.form-group
- label.control-label(for='login-password') Password:
- input.form-control#login-password(type='password')
+ input.form-control#login-password(type='password',placeholder='Password')
a.btn.btn-default#login-submit(href='#') Login
-
+ br(style='clear:both;')
block content
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