diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2014-05-05 14:36:43 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2014-05-13 21:07:24 +0200 |
commit | 0db96cce9f83f09b07a46f31f9930e5b7cc19f6f (patch) | |
tree | 577ed4c85e1346193b5fe5e4e6fef0a4abb77d87 /www/authenticate-with-password.js | |
parent | d8907f11f5c255727b8a814746a0114e5c62e30a (diff) |
Fix bugs introduced by the previous patch.
Diffstat (limited to 'www/authenticate-with-password.js')
-rw-r--r-- | www/authenticate-with-password.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/www/authenticate-with-password.js b/www/authenticate-with-password.js new file mode 100644 index 0000000..776d1e3 --- /dev/null +++ b/www/authenticate-with-password.js @@ -0,0 +1,35 @@ +jQuery(function($) { + var getParameterByName = function(name) { + // https://stackoverflow.com/a/5158301 + var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search); + return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); + }; + + var email = getParameterByName('email'); + $('#email').val(email); + + var onAuthentication = function() { + var password = $('#password').val(); + $.ajax({ + type: 'POST', + url: '/browserid/login.pl', + dataType: 'json', + data: { email: email, password: password }, + success: function(sig, status, xhr) { + console.log("Login successful!"); + navigator.id.completeAuthentication(); + }, + error: function(reason, status, xhr) { + navigator.id.raiseAuthenticationFailure(reason.responseText); + } + }); + return false; + }; + + var onCancel = function() { + navigator.id.cancelAuthentication(); + }; + + $('#auth-form').submit(onAuthentication); + $('.cancel').click(onCancel); +}); |