git.iko.soy/typeable/oauth2-proxy
on v1.1 help sign in
typeable/oauth2-proxy/templates.go
160 lines 3.8 kB history raw
1package main
3import (
4 "html/template"
5 "log"
6 "path"
7)
9func loadTemplates(dir string) *template.Template {
10 if dir == "" {
11 return getTemplates()
12 }
13 log.Printf("using custom template directory %q", dir)
14 t, err := template.New("").ParseFiles(path.Join(dir, "sign_in.html"), path.Join(dir, "error.html"))
15 if err != nil {
16 log.Fatalf("failed parsing template %s", err)
17 }
18 return t
21func getTemplates() *template.Template {
22 t, err := template.New("foo").Parse(`{{define "sign_in.html"}}
23<!DOCTYPE html>
24<html lang="en" charset="utf-8">
25<head>
26 <title>Sign In</title>
27 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
28 <style>
29 body {
30 font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
31 font-size: 14px;
32 line-height: 1.42857143;
33 color: #333;
34 background: #f0f0f0;
35 }
36 .signin {
37 display:block;
38 margin:20px auto;
39 max-width:400px;
40 background: #fff;
41 border:1px solid #ccc;
42 border-radius: 10px;
43 padding: 20px;
44 }
45 .center {
46 text-align:center;
47 }
48 .btn {
49 color: #fff;
50 background-color: #428bca;
51 border: 1px solid #357ebd;
52 -webkit-border-radius: 4;
53 -moz-border-radius: 4;
54 border-radius: 4px;
55 font-size: 14px;
56 padding: 6px 12px;
57 text-decoration: none;
58 cursor: pointer;
59 }
61 .btn:hover {
62 background-color: #3071a9;
63 border-color: #285e8e;
64 ext-decoration: none;
65 }
66 label {
67 display: inline-block;
68 max-width: 100%;
69 margin-bottom: 5px;
70 font-weight: 700;
71 }
72 input {
73 display: block;
74 width: 100%;
75 height: 34px;
76 padding: 6px 12px;
77 font-size: 14px;
78 line-height: 1.42857143;
79 color: #555;
80 background-color: #fff;
81 background-image: none;
82 border: 1px solid #ccc;
83 border-radius: 4px;
84 -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
85 box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
86 -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
87 -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
88 transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
89 margin:0;
90 box-sizing: border-box;
91 }
92 footer {
93 display:block;
94 font-size:10px;
95 color:#aaa;
96 text-align:center;
97 margin-bottom:10px;
98 }
99 footer a {
100 display:inline-block;
101 height:25px;
102 line-height:25px;
103 color:#aaa;
104 text-decoration:underline;
105 }
106 footer a:hover {
107 color:#aaa;
108 }
109 </style>
110</head>
111<body>
112 <div class="signin center">
113 <form method="GET" action="/oauth2/start">
114 <input type="hidden" name="rd" value="{{.Redirect}}">
115 {{ if .SignInMessage }}
116 <p>{{.SignInMessage}}</p>
117 {{ end}}
118 <button type="submit" class="btn">Sign in with a Google Account</button><br/>
119 </form>
120 </div>
122 {{ if .CustomLogin }}
123 <div class="signin">
124 <form method="POST" action="/oauth2/sign_in">
125 <input type="hidden" name="rd" value="{{.Redirect}}">
126 <label for="username">Username:</label><input type="text" name="username" id="username" size="10"><br/>
127 <label for="password">Password:</label><input type="password" name="password" id="password" size="10"><br/>
128 <button type="submit" class="btn">Sign In</button>
129 </form>
130 </div>
131 {{ end }}
132 <footer>
133 Secured with <a href="https://github.com/bitly/google_auth_proxy#google_auth_proxy">Google Auth Proxy</a> version {{.Version}}
134 </footer>
135</body>
136</html>
137{{end}}`)
138 if err != nil {
139 log.Fatalf("failed parsing template %s", err)
140 }
142 t, err = t.Parse(`{{define "error.html"}}
143<!DOCTYPE html>
144<html lang="en" charset="utf-8">
145<head>
146 <title>{{.Title}}</title>
147 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
148</head>
149<body>
150 <h2>{{.Title}}</h2>
151 <p>{{.Message}}</p>
152 <hr>
153 <p><a href="/oauth2/sign_in">Sign In</a></p>
154</body>
155</html>{{end}}`)
156 if err != nil {
157 log.Fatalf("failed parsing template %s", err)
158 }
159 return t