blob: 66334a732d0ef4fe6850114948f1eeb6256fbc16 [file] [log] [blame]
Suharsh Sivakumara76dba62014-12-22 16:00:34 -08001package oauth
2
3import "html/template"
4
5var tmplViewBlessings = template.Must(template.New("auditor").Parse(`<!doctype html>
6<html>
7<head>
8<meta charset="UTF-8">
9<title>Blessings for {{.Email}}</title>
10<meta name="viewport" content="width=device-width, initial-scale=1.0">
11<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
12<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css">
13<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.min.js"></script>
14<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
15<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script>
16<script src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
17<script>
18function setTimeText(elem) {
19 var timestamp = elem.data("unixtime");
20 var m = moment(timestamp*1000.0);
21 var style = elem.data("style");
22 if (style === "absolute") {
23 elem.html("<a href='#'>" + m.format("dd, MMM Do YYYY, h:mm:ss a") + "</a>");
24 elem.data("style", "fromNow");
25 } else {
26 elem.html("<a href='#'>" + m.fromNow() + "</a>");
27 elem.data("style", "absolute");
28 }
29}
30
31$(document).ready(function() {
32 $(".unixtime").each(function() {
33 // clicking the timestamp should toggle the display format.
34 $(this).click(function() { setTimeText($(this)); });
35 setTimeText($(this));
36 });
37
38 // Setup the revoke buttons click events.
39 $(".revoke").click(function() {
40 var revokeButton = $(this);
41 $.ajax({
42 url: "/google/{{.RevokeRoute}}",
43 type: "POST",
44 data: JSON.stringify({
45 "Token": revokeButton.val()
46 })
47 }).done(function(data) {
48 if (data.success == "false") {
49 failMessage(revokeButton);
50 return;
51 }
52 revokeButton.replaceWith("<div>Just Revoked!</div>");
53 }).fail(function(xhr, textStatus){
54 failMessage(revokeButton);
55 console.error('Bad request: %s', status, xhr)
56 });
57 });
58});
59
60function failMessage(revokeButton) {
61 revokeButton.parent().parent().fadeIn(function(){
62 $(this).addClass("bg-danger");
63 });
64 toastr.options.closeButton = true;
65 toastr.error('Unable to revoke identity!', 'Error!')
66}
67
68</script>
69</head>
70<body>
71<div class="container">
72<h3>Blessing log for {{.Email}}</h3>
73<table class="table table-bordered table-hover table-responsive">
74<thead>
75 <tr>
76 <th>Blessed as</th>
77 <th>Public Key</th>
78 <th>Issued</th>
79 <th>Caveats</th>
80 <th>Revoked</th>
81 </tr>
82</thead>
83<tbody>
84{{range .Log}}
85 {{if .Error}}
86 <tr class="bg-danger">
87 <td colspan="5">Failed to read audit log: Error: {{.Error}}</td>
88 </tr>
89 {{else}}
90 <tr>
91 <td>{{.Blessed}}</td>
92 <td>{{.Blessed.PublicKey}}</td>
93 <td><div class="unixtime" data-unixtime={{.Timestamp.Unix}}>{{.Timestamp.String}}</div></td>
94 <td>
95 {{range .Caveats}}
96 {{.}}</br>
97 {{end}}
98 </td>
99 <td>
100 {{ if .Token }}
101 <button class="revoke" value="{{.Token}}">Revoke</button>
102 {{ else if not .RevocationTime.IsZero }}
103 <div class="unixtime" data-unixtime={{.RevocationTime.Unix}}>{{.RevocationTime.String}}</div>
104 {{ end }}
105 </td>
106 </tr>
107 {{end}}
108{{else}}
109 <tr>
110 <td colspan=5>No blessings issued</td>
111 </tr>
112{{end}}
113</tbody>
114</table>
115<hr/>
116</div>
117</body>
118</html>`))