summaryrefslogtreecommitdiffstats
path: root/templates/persona/provisioning.html
blob: a693cac03738943097ba07f63e92e9f4517bd000 (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
58
59
60
61
62
{% extends "master.html" %}
{% block main %}
<div class="col-sm-12">
  <div id="welcome">
      <p>This page is used internally</p>
  </div>
</div>

<script type="text/javascript" src="https://login.persona.org/provisioning_api.js"></script>
<script type="text/javascript">
    var xmlhttp = new XMLHttpRequest()

    var loggedin = {{ loggedin|lower }};

    xmlhttp.onreadystatechange = function()
    {
        if(xmlhttp.readyState == 4)
        {
            if(xmlhttp.status == 200)
            {
                navigator.id.registerCertificate(xmlhttp.responseText);
            }
            else if((xmlhttp.status == 401) || (xmlhttp.status == 403))
            {
                navigator.id.raiseProvisioningFailure('Error in provisioning!');
            }
            else
            {
                alert("Response code: " + xmlhttp.status);
                alert("Response text: " + xmlhttp.responseText);
            }
        }
    }

    function generateServerSide(email, publicKey, certDuration, callback)
    {
        xmlhttp.open("POST", "Sign/", true);
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlhttp.send("email=" + encodeURIComponent(email)
                     + "&publicKey=" + encodeURIComponent(publicKey)
                     + "&certDuration=" + encodeURIComponent(certDuration));
    }

    function startProvisioning()
    {
        navigator.id.beginProvisioning(function(email, certDuration)
        {
            if(loggedin)
            {
                navigator.id.genKeyPair(function(publicKey)
                {
                    generateServerSide(email, publicKey, certDuration);
                });
            } else {
                navigator.id.raiseProvisioningFailure('user is not authenticated');
            }
        });
    }

    startProvisioning();
</script>
{% endblock %}