cmd,server,static/html: Configurable name, logo

fixes #47
This commit is contained in:
Bobby Rullo 2015-08-31 16:02:47 -07:00
parent ff71593cd7
commit f1820cda14
5 changed files with 26 additions and 7 deletions

View file

@ -28,7 +28,9 @@ func init() {
func main() { func main() {
fs := flag.NewFlagSet("dex-worker", flag.ExitOnError) fs := flag.NewFlagSet("dex-worker", flag.ExitOnError)
listen := fs.String("listen", "http://127.0.0.1:5556", "the address that the server will listen on") listen := fs.String("listen", "http://127.0.0.1:5556", "the address that the server will listen on")
issuer := fs.String("issuer", "http://127.0.0.1:5556", "the issuer's location") issuer := fs.String("issuer", "http://127.0.0.1:5556", "the issuer's location")
certFile := fs.String("tls-cert-file", "", "the server's certificate file for TLS connection") certFile := fs.String("tls-cert-file", "", "the server's certificate file for TLS connection")
keyFile := fs.String("tls-key-file", "", "the server's private key file for TLS connection") keyFile := fs.String("tls-key-file", "", "the server's private key file for TLS connection")
@ -42,6 +44,10 @@ func main() {
noDB := fs.Bool("no-db", false, "manage entities in-process w/o any encryption, used only for single-node testing") noDB := fs.Bool("no-db", false, "manage entities in-process w/o any encryption, used only for single-node testing")
// UI-related:
issuerName := fs.String("issuer-name", "dex", "The name of this dex installation; will appear on most pages.")
issuerLogoURL := fs.String("issuer-logo-url", "https://coreos.com/assets/images/brand/coreos-wordmark-135x40px.png", "URL of an image representing the issuer")
// ignored if --no-db is set // ignored if --no-db is set
dbURL := fs.String("db-url", "", "DSN-formatted database connection string") dbURL := fs.String("db-url", "", "DSN-formatted database connection string")
@ -110,6 +116,8 @@ func main() {
EmailTemplateDirs: emailTemplateDirs, EmailTemplateDirs: emailTemplateDirs,
EmailFromAddress: *emailFrom, EmailFromAddress: *emailFrom,
EmailerConfigFile: *emailConfig, EmailerConfigFile: *emailConfig,
IssuerName: *issuerName,
IssuerLogoURL: *issuerLogoURL,
} }
if *noDB { if *noDB {

View file

@ -26,6 +26,8 @@ import (
type ServerConfig struct { type ServerConfig struct {
IssuerURL string IssuerURL string
IssuerName string
IssuerLogoURL string
TemplateDir string TemplateDir string
EmailTemplateDirs []string EmailTemplateDirs []string
EmailFromAddress string EmailFromAddress string
@ -54,7 +56,7 @@ func (cfg *ServerConfig) Server() (*Server, error) {
return nil, err return nil, err
} }
tpl, err := getTemplates(cfg.TemplateDir) tpl, err := getTemplates(cfg.IssuerName, cfg.IssuerLogoURL, cfg.TemplateDir)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -181,8 +183,17 @@ func (cfg *MultiServerConfig) Configure(srv *Server) error {
return nil return nil
} }
func getTemplates(dir string) (*template.Template, error) { func getTemplates(issuerName, issuerLogoURL string, dir string) (*template.Template, error) {
return template.ParseGlob(dir + "/*.html") tpl := template.New("").Funcs(map[string]interface{}{
"issuerName": func() string {
return issuerName
},
"issuerLogoURL": func() string {
return issuerLogoURL
},
})
return tpl.ParseGlob(dir + "/*.html")
} }
func setTemplates(srv *Server, tpls *template.Template) error { func setTemplates(srv *Server, tpls *template.Template) error {

View file

@ -126,7 +126,7 @@ func makeTestFixtures() (*testFixtures, error) {
return nil, err return nil, err
} }
tpl, err := getTemplates(templatesLocation) tpl, err := getTemplates("dex", "https://coreos.com/assets/images/brand/coreos-mark-30px.png", templatesLocation)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -206,7 +206,7 @@
<body> <body>
<div id="navbar"> <div id="navbar">
<div id="navbar-logo-wrap"> <div id="navbar-logo-wrap">
[ Dex by CoreOS ] <img id="navbar-logo" src="{{ issuerLogoURL}}">
</div> </div>
</div> </div>

View file

@ -9,10 +9,10 @@
<h2 class="heading">{{ .Message }}</h2> <h2 class="heading">{{ .Message }}</h2>
{{ else }} {{ else }}
{{ if and .Register (eq .MsgCode "") }} {{ if and .Register (eq .MsgCode "") }}
<h2 class="heading">Create Your Account</h2> <h2 class="heading">Create Your {{ issuerName }} Account</h2>
<div class="explain">Verify using either option below</div> <div class="explain">Verify using either option below</div>
{{ else }} {{ else }}
<h2 class="heading">Log in to Your Account</h2> <h2 class="heading">Log in to {{ issuerName }} </h2>
{{ end}} {{ end}}
{{ end }} {{ end }}