Merge pull request #520 from squat/add-absolute-path-to-templates

backend: add absolute path to template links
This commit is contained in:
Eric Chiang 2016-07-22 15:51:25 -07:00 committed by GitHub
commit 216d26913f
7 changed files with 25 additions and 15 deletions

View file

@ -8,6 +8,7 @@ import (
"io" "io"
"net/url" "net/url"
"os" "os"
"path"
"path/filepath" "path/filepath"
texttemplate "text/template" texttemplate "text/template"
"time" "time"
@ -63,7 +64,7 @@ func (cfg *ServerConfig) Server() (*Server, error) {
return nil, err 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 { if err != nil {
return nil, err return nil, err
} }
@ -281,8 +282,14 @@ func (cfg *MultiServerConfig) Configure(srv *Server) error {
return nil return nil
} }
func getTemplates(issuerName, issuerLogoURL string, func getTemplates(issuerName, issuerURL, issuerLogoURL string,
enableRegister bool, dir string) (*template.Template, error) { 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{}{ tpl := template.New("").Funcs(map[string]interface{}{
"issuerName": func() string { "issuerName": func() string {
return issuerName return issuerName
@ -293,6 +300,9 @@ func getTemplates(issuerName, issuerLogoURL string,
"enableRegister": func() bool { "enableRegister": func() bool {
return enableRegister return enableRegister
}, },
"absPath": func(p string) string {
return path.Join(issuerPath, p)
},
}) })
return tpl.ParseGlob(dir + "/*.html") return tpl.ParseGlob(dir + "/*.html")

View file

@ -230,7 +230,7 @@ func makeTestFixturesWithOptions(options testFixtureOptions) (*testFixtures, err
return nil, 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", "https://coreos.com/assets/images/brand/coreos-mark-30px.png",
true, templatesLocation) true, templatesLocation)
if err != nil { if err != nil {

View file

@ -2,7 +2,7 @@
<div class="panel"> <div class="panel">
<h2 class="heading">Log in to Your Account</h2> <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="form-row">
LDAP LDAP
<div class="input-desc"> <div class="input-desc">
@ -13,7 +13,7 @@
<div class="form-row"> <div class="form-row">
<div class="input-desc"> <div class="input-desc">
<label for="password">Password</label> <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> </div>
<input tabindex="2" required id="password" name="password" type="password" class="input-box" placeholder="password"/> <input tabindex="2" required id="password" name="password" type="password" class="input-box" placeholder="password"/>
</div> </div>

View file

@ -2,7 +2,7 @@
<div class="panel"> <div class="panel">
<h2 class="heading">Log in to Your Account</h2> <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="form-row">
<div class="input-desc"> <div class="input-desc">
<label for="userid">Email Address</label> <label for="userid">Email Address</label>
@ -12,7 +12,7 @@
<div class="form-row"> <div class="form-row">
<div class="input-desc"> <div class="input-desc">
<label for="password">Password</label> <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> </div>
<input tabindex="2" required id="password" name="password" type="password" class="input-box" placeholder="password"/> <input tabindex="2" required id="password" name="password" type="password" class="input-box" placeholder="password"/>
</div> </div>

View file

@ -40,7 +40,7 @@
{{ if .Register }} {{ if .Register }}
{{ range $c := .Links }} {{ range $c := .Links }}
<div class="form-row"> <div class="form-row">
<a href="{{ $c.URL }}" target="_self"> <a href="{{ $c.URL | absPath }}" target="_self">
<button class="btn btn-provider"> <button class="btn btn-provider">
<span class="btn-icon btn-icon-{{ $c.ID }}"></span> <span class="btn-icon btn-icon-{{ $c.ID }}"></span>
<span class="btn-text">Use {{ $c.DisplayName }}</span> <span class="btn-text">Use {{ $c.DisplayName }}</span>
@ -51,7 +51,7 @@
{{ else }} {{ else }}
{{ range $c := .Links }} {{ range $c := .Links }}
<div class="form-row"> <div class="form-row">
<a href="{{ $c.URL }}" target="_self"> <a href="{{ $c.URL | absPath }}" target="_self">
<button class="btn btn-provider"> <button class="btn btn-provider">
<span class="btn-icon btn-icon-{{ $c.ID }}"></span> <span class="btn-icon btn-icon-{{ $c.ID }}"></span>
<span class="btn-text">Log in with {{ $c.DisplayName }}</span> <span class="btn-text">Log in with {{ $c.DisplayName }}</span>
@ -68,10 +68,10 @@
{{ if not .Error }} {{ if not .Error }}
<div class="footer subtle-text"> <div class="footer subtle-text">
{{ if .Register }} {{ if .Register }}
Already have an account? <a href="{{ .RegisterOrLoginURL }}">Log in</a> Already have an account? <a href="{{ .RegisterOrLoginURL | absPath }}">Log in</a>
{{ else }} {{ else }}
{{ if enableRegister }} {{ 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 }}
{{ end }} {{ end }}
</div> </div>

View file

@ -12,7 +12,7 @@
If you'd like to login with that account, click here: If you'd like to login with that account, click here:
</div> </div>
<div> <div>
<a href="{{ .Login }}" target="_self"> <a href="{{ .Login | absPath }}" target="_self">
<button class="btn btn-provider"> <button class="btn btn-provider">
<span class="btn-text">Login</span> <span class="btn-text">Login</span>
</button> </button>
@ -22,7 +22,7 @@
If you would like to register with a different account, click here: If you would like to register with a different account, click here:
</div> </div>
<div> <div>
<a href="{{ .Register }}" target="_self"> <a href="{{ .Register | absPath }}" target="_self">
<button class="btn btn-provider"> <button class="btn btn-provider">
<span class="btn-text">Register</span> <span class="btn-text">Register</span>
</button> </button>
@ -32,7 +32,7 @@
{{ else }} {{ else }}
<form id="registerForm" method="POST" action="/register"> <form id="registerForm" method="POST" action="{{ "/register" | absPath }}">
<div class="form-row"> <div class="form-row">
<div class="input-desc"> <div class="input-desc">

View file

@ -13,7 +13,7 @@
<h2 class="heading">Reset your password </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> <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="form-row">
<div class="input-desc"> <div class="input-desc">