Skip to content

Commit

Permalink
Merge pull request #623 from ericchiang/dev-port-oob-template
Browse files Browse the repository at this point in the history
*: port oob template
  • Loading branch information
ericchiang authored Oct 19, 2016
2 parents 86b2d93 + 7084a80 commit ea52bf2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
3 changes: 1 addition & 2 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions server/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -23,6 +24,7 @@ var requiredTmpls = []string{
tmplApproval,
tmplLogin,
tmplPassword,
tmplOOB,
}

// TemplateConfig describes.
Expand Down Expand Up @@ -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
}

Expand All @@ -120,6 +123,7 @@ type templates struct {
loginTmpl *template.Template
approvalTmpl *template.Template
passwordTmpl *template.Template
oobTmpl *template.Template
}

type connectorInfo struct {
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions server/templates_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" . }}
Expand Down
11 changes: 11 additions & 0 deletions web/templates/oob.html
Original file line number Diff line number Diff line change
@@ -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" . }}

0 comments on commit ea52bf2

Please sign in to comment.