oauth2-proxy/templates.go

52 lines
1.2 KiB
Go
Raw Normal View History

2012-12-11 05:59:23 +04:00
package main
import (
"html/template"
"log"
)
func getTemplates() *template.Template {
t, err := template.New("foo").Parse(`{{define "sign_in.html"}}
<!DOCTYPE html>
<html lang="en" charset="utf-8">
<head><title>Sign In</title></head>
<body>
2012-12-11 05:59:23 +04:00
<form method="GET" action="/oauth2/start">
<input type="hidden" name="rd" value="{{.Redirect}}">
2012-12-11 05:59:23 +04:00
<button type="submit">Sign In w/ Google</button>
{{.SignInMessage}}
</form>
{{ if .Htpasswd }}
<fieldset>
<form method="POST" action="/oauth2/sign_in">
<input type="hidden" name="rd" value="{{.Redirect}}">
<label>Username: <input type="text" name="username" size="10"></label><br/>
<label>Password: <input type="password" name="password" size="10"></label><br/>
<button type="submit">Sign In</button>
</form>
</fieldset>
{{ end }}
</body>
</html>
2012-12-11 05:59:23 +04:00
{{end}}`)
if err != nil {
log.Fatalf("failed parsing template %s", err.Error())
}
2012-12-17 22:38:33 +04:00
2012-12-11 05:59:23 +04:00
t, err = t.Parse(`{{define "error.html"}}
<!DOCTYPE html>
<html lang="en" charset="utf-8">
<head><title>{{.Title}}</title></head>
2012-12-11 05:59:23 +04:00
<body>
<h2>{{.Title}}</h2>
<p>{{.Message}}</p>
<hr>
2012-12-17 22:15:23 +04:00
<p><a href="/oauth2/sign_in">Sign In</a></p>
2012-12-11 05:59:23 +04:00
</body>
</html>{{end}}`)
if err != nil {
log.Fatalf("failed parsing template %s", err.Error())
}
return t
}