*: port oob template

This commit is contained in:
Eric Chiang 2016-10-19 12:45:17 -07:00
parent 86b2d93966
commit 7084a801d7
4 changed files with 36 additions and 2 deletions

View File

@ -384,8 +384,7 @@ func (s *Server) sendCodeResponse(w http.ResponseWriter, r *http.Request, authRe
}
if authReq.RedirectURI == redirectURIOOB {
// TODO(ericchiang): Add a proper template.
fmt.Fprintf(w, "Code: %s", code.ID)
s.templates.oob(w, code.ID)
return
}
q.Set("code", code.ID)

View File

@ -15,6 +15,7 @@ const (
tmplApproval = "approval.html"
tmplLogin = "login.html"
tmplPassword = "password.html"
tmplOOB = "oob.html"
)
const coreOSLogoURL = "https://coreos.com/assets/images/brand/coreos-wordmark-135x40px.png"
@ -23,6 +24,7 @@ var requiredTmpls = []string{
tmplApproval,
tmplLogin,
tmplPassword,
tmplOOB,
}
// TemplateConfig describes.
@ -106,6 +108,7 @@ func loadTemplates(config TemplateConfig) (*templates, error) {
loginTmpl: tmpls.Lookup(tmplLogin),
approvalTmpl: tmpls.Lookup(tmplApproval),
passwordTmpl: tmpls.Lookup(tmplPassword),
oobTmpl: tmpls.Lookup(tmplOOB),
}, nil
}
@ -120,6 +123,7 @@ type templates struct {
loginTmpl *template.Template
approvalTmpl *template.Template
passwordTmpl *template.Template
oobTmpl *template.Template
}
type connectorInfo struct {
@ -175,6 +179,14 @@ func (t *templates) approval(w http.ResponseWriter, state, username, clientName
renderTemplate(w, t.approvalTmpl, data)
}
func (t *templates) oob(w http.ResponseWriter, code string) {
data := struct {
TemplateConfig
Code string
}{t.globalData, code}
renderTemplate(w, t.oobTmpl, data)
}
// small io.Writer utilitiy to determine if executing the template wrote to the underlying response writer.
type writeRecorder struct {
wrote bool

View File

@ -313,6 +313,18 @@ var defaultTemplates = map[string]string{
</div>
{{ template "footer.html" . }}
`,
"oob.html": `{{ template "header.html" . }}
<div class="panel">
<h2 class="heading">Login Successful</h2>
Please copy this code, switch to your application and paste it there:
<br/>
<input type="text" value="{{ .Code }}" />
</div>
{{ template "footer.html" . }}
`,
"password.html": `{{ template "header.html" . }}

11
web/templates/oob.html Normal file
View File

@ -0,0 +1,11 @@
{{ template "header.html" . }}
<div class="panel">
<h2 class="heading">Login Successful</h2>
Please copy this code, switch to your application and paste it there:
<br/>
<input type="text" value="{{ .Code }}" />
</div>
{{ template "footer.html" . }}