github.com/pusher/oauth2_proxy@v3.2.0+incompatible/templates.go (about) 1 package main 2 3 import ( 4 "html/template" 5 "log" 6 "path" 7 ) 8 9 func 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 19 } 20 21 func 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 } 60 61 .btn:hover { 62 background-color: #3071a9; 63 border-color: #285e8e; 64 text-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="{{.ProxyPrefix}}/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 {{.ProviderName}}</button><br/> 119 </form> 120 </div> 121 122 {{ if .CustomLogin }} 123 <div class="signin"> 124 <form method="POST" action="{{.ProxyPrefix}}/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 <script> 133 if (window.location.hash) { 134 (function() { 135 var inputs = document.getElementsByName('rd'); 136 for (var i = 0; i < inputs.length; i++) { 137 inputs[i].value += window.location.hash; 138 } 139 })(); 140 } 141 </script> 142 <footer> 143 {{ if eq .Footer "-" }} 144 {{ else if eq .Footer ""}} 145 Secured with <a href="https://github.com/pusher/oauth2_proxy#oauth2_proxy">OAuth2 Proxy</a> version {{.Version}} 146 {{ else }} 147 {{.Footer}} 148 {{ end }} 149 </footer> 150 </body> 151 </html> 152 {{end}}`) 153 if err != nil { 154 log.Fatalf("failed parsing template %s", err) 155 } 156 157 t, err = t.Parse(`{{define "error.html"}} 158 <!DOCTYPE html> 159 <html lang="en" charset="utf-8"> 160 <head> 161 <title>{{.Title}}</title> 162 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> 163 </head> 164 <body> 165 <h2>{{.Title}}</h2> 166 <p>{{.Message}}</p> 167 <hr> 168 <p><a href="{{.ProxyPrefix}}/sign_in">Sign In</a></p> 169 </body> 170 </html>{{end}}`) 171 if err != nil { 172 log.Fatalf("failed parsing template %s", err) 173 } 174 return t 175 }