-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtemplates.go
195 lines (185 loc) · 4.5 KB
/
templates.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// Copyright 2016 Lars Wiegman. All rights reserved. Use of this source code is
// governed by a BSD-style license that can be found in the LICENSE file.
package multipass
import "html/template"
const (
notfoundPage = iota
loginPage
tokenInvalidPage
tokenSentPage
continueOrSignoutPage
errorPage
)
type page struct {
PJAX bool
Page int
NextURL string
LoginPath string
SignoutPath string
CSRFField template.HTML
ErrorMessage string
}
func loadTemplates() *template.Template {
tmpl := template.New("")
template.Must(tmpl.New("head").Parse(`<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="Multipass">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Multipass</title>
<style>{{ template "style" }}</style>
</head>
<body>`))
template.Must(tmpl.New("tail").Parse(`</body></html>`))
template.Must(tmpl.New("loginform").Parse(`
<form action="{{ .LoginPath }}" method=POST class="login-form">
<input type=hidden name=next value="{{ .NextURL }}" />
<input type=email name=handle placeholder="Your handle ..." />
<input type=submit value="Submit" class="btn btn-default">
{{ .CSRFField }}
</form>`))
template.Must(tmpl.New("signoutform").Parse(`
<form action="{{ .SignoutPath }}" method=POST class="login-form">
<input type=hidden name=next value="{{ .NextURL }}" />
<input type=submit value="Signout" class="btn btn-danger">
{{ .CSRFField }}
</form>`))
template.Must(tmpl.New("page").Parse(`
{{ if ne .PJAX true }}{{ template "head"}}{{end}}
<div class="wrapper">
<section>
<article class="login-box">
<h1>Multipass</h1>
{{ if eq .Page 1 }}
{{ template "loginform" . }}
<p class="notice">This resource is protected. Submit your handle to gain access.</p>
{{ else if eq .Page 2 }}
<p class="notice">Your access token has expired or is invalid. Submit your handle to request a new one.</p>
{{ template "loginform" . }}
<p class="notice">This resource is protected.</p>
{{ else if eq .Page 3 }}
<p>A message with an access token was sent to your handle; Follow the login link in the message to gain access.</p>
{{ else if eq .Page 4 }}
<p class="notice">Continue to access the private resource or signout.</p>
<a href="{{ .NextURL }}" class="btn btn-success">Continue</a>
{{ template "signoutform" . }}
<p class="notice">This resource is protected.</p>
{{ else if eq .Page 5 }}
<p>{{ .ErrorMessage }}</p>
{{ else }}
<h4>Not Found (404)</p>
<p>Sorry, couldn't find what you're looking for.</p>
{{ end }}
</article>
</section>
</div>
{{ if ne .PJAX true }}{{ template "tail" }}{{ end }}`))
template.Must(tmpl.New("style").Parse(`
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
article, aside, details, figcaption, figure, footer, header, hgroup,
main, nav, section, summary {
display: block;
}
body {
margin: 0;
}
input { -webkit-appearance: none; }
.wrapper {
display: -webkit-flex;
-webkit-flex-direction: column;
}
.login-box {
width: 480px;
margin: 4rem auto;
text-align: center;
padding: 1rem 0;
border: solid .2rem #0d8eba;
border-radius: .8rem;
padding: 1rem 2rem;
background-color: #fff;
}
.login-box h1 {
font-family: sans-serif;
font-size: 3rem;
color: #444;
}
.login-form {
}
.login-form input {
}
.login-form input[type=text], .login-form input[type=email] {
font-size: 1.2rem;
padding: 0 1rem;
border-color: #ddd;
color: #444;
margin: .6rem 0;
width: 100%;
height: 2.8rem;
border-radius: .4rem;
border-style: solid;
border-width: .2rem;
}
.login-form input[type=submit] {
}
.btn {
font-family: sans-serif;
font-size: 1.2rem;
margin: 1rem 0;
padding: .5rem 1rem;
width: 100%;
height: 2.8rem;
border-radius: .4rem;
border-style: solid;
border-width: .16rem;
text-transform: uppercase;
color: #fff;
height: 3rem;
cursor: pointer;
display: inline-block;
line-height: 2rem;
}
a.btn {
text-decoration: none;
color: white;
}
.btn-default {
background-color: #0d8eba;
border-color: #0d8eba;
}
.btn-success {
background-color: #0dba77;
border-color: #0dba77;
}
.btn-danger {
background-color: #ba2f0d;
border-color: #ba2f0d;
}
.notice {
font-style: italic;
color: #666;
}
/* Narrow */
@media only screen and (max-width: 480px) {
body {
background-color: #0d8eba;
}
.login-box {
width: 100%;
border: none;
border-radius: 0;
}
}
/* Medium */
@media only screen and (min-width: 481px) and (max-width: 960px) {
}
/* Wide */
@media only screen and (min-width: 961px) {
}
`))
return tmpl
}