summaryrefslogtreecommitdiffstats
path: root/extensions/BrowserID/template/en/default/hook/account/auth/login-additional_methods.html.tmpl
blob: 2b6f4b85a892af82caa44fa810b95d0cb1400d8b (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
[% IF Param('user_info_class').split(',').contains('BrowserID') %]

[% USE Bugzilla %]
[% cgi = Bugzilla.cgi %]

<script src="https://browserid.org/include.js" type="text/javascript"></script>

<script type="text/javascript">
function browserid_sign_in() {
    navigator.id.getVerifiedEmail(function(assertion) {
        if (assertion) {
            // This code will be invoked once the user has successfully
            // selected an email address they control to sign in with.
            var browseridForm = document.createElement('form');
            browseridForm.action = '[% target FILTER js %]';
            browseridForm.method = 'POST';
            browseridForm.style.display = 'none';
            
            var tokenField = document.createElement('input');
            tokenField.type = 'hidden';
            tokenField.name = 'token';
            tokenField.value = '[% issue_hash_token(['login']) FILTER js %]';
            browseridForm.appendChild(tokenField);

            var assertionField = document.createElement('input');
            assertionField.type = 'hidden';
            assertionField.name = 'browserid_assertion';
            assertionField.value = assertion;
            browseridForm.appendChild(assertionField);

            var hidden_fields =[];
            var field_count = 0;
            [% FOREACH field = cgi.param() %]
              [% NEXT IF field.search("^(Bugzilla_(login|password|restrictlogin)|token|browserid_assertion)$") %]
              [% FOREACH mvalue = cgi.param(field).slice(0) %]
                hidden_fields[field_count] = document.createElement('input');
                hidden_fields[field_count].type = 'hidden';
                hidden_fields[field_count].name = '[% field FILTER js %]';
                hidden_fields[field_count].value = '[% mvalue FILTER html_linebreak FILTER js %]';
                browseridForm.appendChild(hidden_fields[field_count]);
              [% END %]
              field_count++;
            [% END %]

            document.body.appendChild(browseridForm);
            browseridForm.submit();
            return true;
        }
    });
}
</script>

<p>
Or, log in with BrowserID: 
<img src="extensions/BrowserID/web/sign_in_orange.png" onclick="browserid_sign_in()">
</p>
[% END %]