Skip to content

Commit

Permalink
Merge pull request #520 from squat/add-absolute-path-to-templates
Browse files Browse the repository at this point in the history
backend: add absolute path to template links
  • Loading branch information
ericchiang authored Jul 22, 2016
2 parents 1759b96 + 0cc0c73 commit 216d269
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
14 changes: 12 additions & 2 deletions server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net/url"
"os"
"path"
"path/filepath"
texttemplate "text/template"
"time"
Expand Down Expand Up @@ -63,7 +64,7 @@ func (cfg *ServerConfig) Server() (*Server, error) {
return nil, err
}

tpl, err := getTemplates(cfg.IssuerName, cfg.IssuerLogoURL, cfg.EnableRegistration, cfg.TemplateDir)
tpl, err := getTemplates(cfg.IssuerName, cfg.IssuerURL, cfg.IssuerLogoURL, cfg.EnableRegistration, cfg.TemplateDir)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -281,8 +282,14 @@ func (cfg *MultiServerConfig) Configure(srv *Server) error {
return nil
}

func getTemplates(issuerName, issuerLogoURL string,
func getTemplates(issuerName, issuerURL, issuerLogoURL string,
enableRegister bool, dir string) (*template.Template, error) {
u, err := url.Parse(issuerURL)
if err != nil {
return nil, err
}
issuerPath := u.Path

tpl := template.New("").Funcs(map[string]interface{}{
"issuerName": func() string {
return issuerName
Expand All @@ -293,6 +300,9 @@ func getTemplates(issuerName, issuerLogoURL string,
"enableRegister": func() bool {
return enableRegister
},
"absPath": func(p string) string {
return path.Join(issuerPath, p)
},
})

return tpl.ParseGlob(dir + "/*.html")
Expand Down
2 changes: 1 addition & 1 deletion server/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func makeTestFixturesWithOptions(options testFixtureOptions) (*testFixtures, err
return nil, err
}

tpl, err := getTemplates("dex",
tpl, err := getTemplates("dex", "https://coreos.com",
"https://coreos.com/assets/images/brand/coreos-mark-30px.png",
true, templatesLocation)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions static/html/ldap-login.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="panel">
<h2 class="heading">Log in to Your Account</h2>
<form method="post" action="{{.PostURL}}">
<form method="post" action="{{.PostURL | absPath }}">
<div class="form-row">
LDAP
<div class="input-desc">
Expand All @@ -13,7 +13,7 @@ <h2 class="heading">Log in to Your Account</h2>
<div class="form-row">
<div class="input-desc">
<label for="password">Password</label>
<span class="subtle-text input-label-right">Forgot? <a href="/send-reset-password?session_key={{ .SessionKey }}">Reset Password</a></span>
<span class="subtle-text input-label-right">Forgot? <a href="{{ "/send-reset-password" | absPath }}?session_key={{ .SessionKey }}">Reset Password</a></span>
</div>
<input tabindex="2" required id="password" name="password" type="password" class="input-box" placeholder="password"/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions static/html/local-login.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="panel">
<h2 class="heading">Log in to Your Account</h2>
<form method="post" action="{{.PostURL}}">
<form method="post" action="{{.PostURL | absPath}}">
<div class="form-row">
<div class="input-desc">
<label for="userid">Email Address</label>
Expand All @@ -12,7 +12,7 @@ <h2 class="heading">Log in to Your Account</h2>
<div class="form-row">
<div class="input-desc">
<label for="password">Password</label>
<span class="subtle-text input-label-right">Forgot? <a href="/send-reset-password?session_key={{ .SessionKey }}">Reset Password</a></span>
<span class="subtle-text input-label-right">Forgot? <a href="{{ "/send-reset-password" | absPath }}?session_key={{ .SessionKey }}">Reset Password</a></span>
</div>
<input tabindex="2" required id="password" name="password" type="password" class="input-box" placeholder="password"/>
</div>
Expand Down
8 changes: 4 additions & 4 deletions static/html/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h2 class="heading">Log in to {{ issuerName }} </h2>
{{ if .Register }}
{{ range $c := .Links }}
<div class="form-row">
<a href="{{ $c.URL }}" target="_self">
<a href="{{ $c.URL | absPath }}" target="_self">
<button class="btn btn-provider">
<span class="btn-icon btn-icon-{{ $c.ID }}"></span>
<span class="btn-text">Use {{ $c.DisplayName }}</span>
Expand All @@ -51,7 +51,7 @@ <h2 class="heading">Log in to {{ issuerName }} </h2>
{{ else }}
{{ range $c := .Links }}
<div class="form-row">
<a href="{{ $c.URL }}" target="_self">
<a href="{{ $c.URL | absPath }}" target="_self">
<button class="btn btn-provider">
<span class="btn-icon btn-icon-{{ $c.ID }}"></span>
<span class="btn-text">Log in with {{ $c.DisplayName }}</span>
Expand All @@ -68,10 +68,10 @@ <h2 class="heading">Log in to {{ issuerName }} </h2>
{{ if not .Error }}
<div class="footer subtle-text">
{{ if .Register }}
Already have an account? <a href="{{ .RegisterOrLoginURL }}">Log in</a>
Already have an account? <a href="{{ .RegisterOrLoginURL | absPath }}">Log in</a>
{{ else }}
{{ if enableRegister }}
Don't have an account yet? <a href="{{ .RegisterOrLoginURL }}">Register</a>
Don't have an account yet? <a href="{{ .RegisterOrLoginURL | absPath }}">Register</a>
{{ end }}
{{ end }}
</div>
Expand Down
6 changes: 3 additions & 3 deletions static/html/register.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h2 class="heading">Create Your Account</h2>
If you'd like to login with that account, click here:
</div>
<div>
<a href="{{ .Login }}" target="_self">
<a href="{{ .Login | absPath }}" target="_self">
<button class="btn btn-provider">
<span class="btn-text">Login</span>
</button>
Expand All @@ -22,7 +22,7 @@ <h2 class="heading">Create Your Account</h2>
If you would like to register with a different account, click here:
</div>
<div>
<a href="{{ .Register }}" target="_self">
<a href="{{ .Register | absPath }}" target="_self">
<button class="btn btn-provider">
<span class="btn-text">Register</span>
</button>
Expand All @@ -32,7 +32,7 @@ <h2 class="heading">Create Your Account</h2>

{{ else }}

<form id="registerForm" method="POST" action="/register">
<form id="registerForm" method="POST" action="{{ "/register" | absPath }}">

<div class="form-row">
<div class="input-desc">
Expand Down
2 changes: 1 addition & 1 deletion static/html/send-reset-password.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2 class="heading">Thank you, please check your email!</h2>
<h2 class="heading">Reset your password </h2>
<div class="explain">We will send you an email with a link to reset your password.</div>

<form id="sendResetPasswordForm" method="POST" action="/send-reset-password">
<form id="sendResetPasswordForm" method="POST" action="{{ "/send-reset-password" | absPath }}">

<div class="form-row">
<div class="input-desc">
Expand Down

0 comments on commit 216d269

Please sign in to comment.