-
Notifications
You must be signed in to change notification settings - Fork 6
/
list_blessings.go
135 lines (122 loc) · 4.2 KB
/
list_blessings.go
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package templates
import "html/template"
var ListBlessings = template.Must(listWithHeader.Parse(sidebarPartial))
var listWithHead = template.Must(listBlessings.Parse(headPartial))
var listWithHeader = template.Must(listWithHead.Parse(headerPartial))
var listBlessings = template.Must(template.New("auditor").Parse(`<!doctype html>
<html>
<head>
<title>Blessings for {{.Email}} - Vanadium Identity Provider</title>
{{template "head" .}}
<link rel="stylesheet" href="{{.AssetsPrefix}}/identity/toastr.css">
</head>
<body class="identityprovider-layout">
{{template "header" .}}
<main>
<h1 class="page-head">Authorize Vanadium apps with Google</h1>
<p>
The Vanadium Identity Provider authorizes Vanadium blessings based on your Google Account.<br>
<a href="https://vanadium.github.io/glossary.html#identity-provider">Learn more</a>
</p>
<div class="blessings-list">
<div class="blessings-header">
<h1>Your blessings</h1>
<h5>Issued</h5>
<h5>Revoked</h5>
</div>
{{range .Log}}
{{if .Error}}
<h1>Error</h1>
<p>
Failed to read audit log.<br>
{{.Error}}
</p>
{{else}} {{/* if .Error */}}
<div class="blessings-item">
<div class="blessing-details">
<h3>{{.Blessed}}</h3>
<p>
<b>Public Key</b><br>
{{.Blessed.PublicKey}}
</p>
<p class="blessing-caveats">
<b>Caveats</b><br>
{{range .Caveats}}
{{.}}<br>
{{end}}
</p>
</div>
<div class="blessing-issued unixtime" data-unixtime={{.Timestamp.Unix}}>{{.Timestamp.String}}</div>
<div class="blessing-revoked">
{{if .Token}}
<button class="revoke button-passive" value="{{.Token}}">Revoke</button>
{{else if not .RevocationTime.IsZero}}
<p class="unixtime" data-unixtime={{.RevocationTime.Unix}}>{{.RevocationTime.String}}</p>
{{end}}
</div>
</div>
{{end}} {{/* if .Error */}}
{{else}} {{/* range .Log */}}
<p>
<a href="https://vanadium.github.io/installation/">Install Vanadium</a> to set up your first blessing.
</p>
{{end}} {{/* range .Log */}}
</div>
{{template "sidebar" .}}
</main>
<script src="{{.AssetsPrefix}}/identity/toastr.js"></script>
<script src="{{.AssetsPrefix}}/identity/moment.js"></script>
<script src="{{.AssetsPrefix}}/identity/jquery.js"></script>
<script>
function setTimeText(elem) {
var timestamp = elem.data("unixtime");
var m = moment(timestamp*1000.0);
var style = elem.data("style");
if (style === "absolute") {
elem.html("<a href='#'>" + m.format("MMM DD, YYYY h:mm:ss a") + "</a>");
elem.data("style", "fromNow");
} else {
elem.html("<a href='#'>" + m.fromNow() + "</a>");
elem.data("style", "absolute");
}
}
$(document).ready(function() {
$(".unixtime").each(function() {
// clicking the timestamp should toggle the display format.
$(this).click(function() { setTimeText($(this)); });
setTimeText($(this));
});
// Setup the revoke buttons click events.
$(".revoke").click(function() {
var revokeButton = $(this);
$.ajax({
url: "/auth/google/{{.RevokeRoute}}",
type: "POST",
data: JSON.stringify({
"Token": revokeButton.val()
})
}).done(function(data) {
if (data.success == "false") {
failMessage(revokeButton);
return;
}
revokeButton.replaceWith("<div>Revoked just now</div>");
}).fail(function(xhr, textStatus){
failMessage(revokeButton);
console.error('Bad request: %s', status, xhr)
});
});
});
function failMessage(revokeButton) {
revokeButton.parent().parent().fadeIn(function(){
$(this).addClass("bg-danger");
});
toastr.options.closeButton = true;
toastr.error('Unable to revoke identity', 'Error')
}
</script>
</body>
</html>`))