*: 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 { if authReq.RedirectURI == redirectURIOOB {
// TODO(ericchiang): Add a proper template. s.templates.oob(w, code.ID)
fmt.Fprintf(w, "Code: %s", code.ID)
return return
} }
q.Set("code", code.ID) q.Set("code", code.ID)

View file

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

View file

@ -313,6 +313,18 @@ var defaultTemplates = map[string]string{
</div> </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" . }} {{ template "footer.html" . }}
`, `,
"password.html": `{{ template "header.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" . }}