aboutsummaryrefslogtreecommitdiff
path: root/www/authenticate-with-password.js
blob: 776d1e3b20d57df1d25d37e770ae24079aaca6a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
});