2012-12-11 05:59:23 +04:00
package main
import (
"html/template"
"log"
2015-03-18 01:06:06 +03:00
"path"
2012-12-11 05:59:23 +04:00
)
2015-03-18 01:06:06 +03:00
func loadTemplates ( dir string ) * template . Template {
if dir == "" {
return getTemplates ( )
}
log . Printf ( "using custom template directory %q" , dir )
t , err := template . New ( "" ) . ParseFiles ( path . Join ( dir , "sign_in.html" ) , path . Join ( dir , "error.html" ) )
if err != nil {
log . Fatalf ( "failed parsing template %s" , err )
}
return t
}
2012-12-11 05:59:23 +04:00
func getTemplates ( ) * template . Template {
t , err := template . New ( "foo" ) . Parse ( ` { { define "sign_in.html" } }
2012-12-26 19:55:41 +04:00
< ! DOCTYPE html >
< html lang = "en" charset = "utf-8" >
2014-11-09 08:26:52 +03:00
< head >
< title > Sign In < / title >
< meta name = "viewport" content = "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" >
< style >
body {
font - family : "Helvetica Neue" , Helvetica , Arial , sans - serif ;
font - size : 14 px ;
line - height : 1.42857143 ;
color : # 333 ;
background : # f0f0f0 ;
}
. signin {
display : block ;
margin : 20 px auto ;
max - width : 400 px ;
background : # fff ;
border : 1 px solid # ccc ;
border - radius : 10 px ;
padding : 20 px ;
}
. center {
text - align : center ;
}
. btn {
color : # fff ;
background - color : # 428 bca ;
border : 1 px solid # 357 ebd ;
- webkit - border - radius : 4 ;
- moz - border - radius : 4 ;
border - radius : 4 px ;
font - size : 14 px ;
padding : 6 px 12 px ;
text - decoration : none ;
cursor : pointer ;
}
. btn : hover {
background - color : # 3071 a9 ;
border - color : # 285e8 e ;
ext - decoration : none ;
}
label {
display : inline - block ;
max - width : 100 % ;
margin - bottom : 5 px ;
font - weight : 700 ;
}
input {
display : block ;
width : 100 % ;
height : 34 px ;
padding : 6 px 12 px ;
font - size : 14 px ;
line - height : 1.42857143 ;
color : # 555 ;
background - color : # fff ;
background - image : none ;
border : 1 px solid # ccc ;
border - radius : 4 px ;
- webkit - box - shadow : inset 0 1 px 1 px rgba ( 0 , 0 , 0 , .075 ) ;
box - shadow : inset 0 1 px 1 px rgba ( 0 , 0 , 0 , .075 ) ;
- webkit - transition : border - color ease - in - out .15 s , - webkit - box - shadow ease - in - out .15 s ;
- o - transition : border - color ease - in - out .15 s , box - shadow ease - in - out .15 s ;
transition : border - color ease - in - out .15 s , box - shadow ease - in - out .15 s ;
margin : 0 ;
box - sizing : border - box ;
}
2014-11-10 06:01:50 +03:00
footer {
display : block ;
font - size : 10 px ;
color : # aaa ;
text - align : center ;
margin - bottom : 10 px ;
}
footer a {
display : inline - block ;
height : 25 px ;
line - height : 25 px ;
color : # aaa ;
text - decoration : underline ;
}
footer a : hover {
color : # aaa ;
}
2014-11-09 08:26:52 +03:00
< / style >
2014-07-22 07:59:13 +04:00
< / head >
2012-12-26 19:55:41 +04:00
< body >
2014-11-09 08:26:52 +03:00
< div class = "signin center" >
2015-05-30 01:47:40 +03:00
< form method = "GET" action = "{{.ProxyPrefix}}/start" >
2013-10-22 23:56:29 +04:00
< input type = "hidden" name = "rd" value = "{{.Redirect}}" >
2014-11-09 08:26:52 +03:00
{ { if . SignInMessage } }
< p > { { . SignInMessage } } < / p >
{ { end } }
2015-03-31 19:59:07 +03:00
< button type = "submit" class = "btn" > Sign in with a { { . ProviderName } } Account < / button > < br / >
2012-12-11 05:59:23 +04:00
< / form >
2014-11-09 08:26:52 +03:00
< / div >
2014-12-09 23:38:57 +03:00
{ { if . CustomLogin } }
2014-11-09 08:26:52 +03:00
< div class = "signin" >
2015-05-30 01:47:40 +03:00
< form method = "POST" action = "{{.ProxyPrefix}}/sign_in" >
2013-10-22 23:56:29 +04:00
< input type = "hidden" name = "rd" value = "{{.Redirect}}" >
2014-11-09 08:26:52 +03:00
< label for = "username" > Username : < / label > < input type = "text" name = "username" id = "username" size = "10" > < br / >
< label for = "password" > Password : < / label > < input type = "password" name = "password" id = "password" size = "10" > < br / >
< button type = "submit" class = "btn" > Sign In < / button >
< / form >
< / div >
2012-12-26 19:55:41 +04:00
{ { end } }
2014-11-10 06:01:50 +03:00
< footer >
2015-05-21 09:50:21 +03:00
Secured with < a href = "https://github.com/bitly/oauth2_proxy#oauth2_proxy" > OAuth2 Proxy < / a > version { { . Version } }
2014-11-10 06:01:50 +03:00
< / footer >
2012-12-26 19:55:41 +04:00
< / body >
< / html >
2012-12-11 05:59:23 +04:00
{ { end } } ` )
if err != nil {
2015-03-18 01:06:06 +03:00
log . Fatalf ( "failed parsing template %s" , err )
2012-12-11 05:59:23 +04:00
}
2012-12-17 22:38:33 +04:00
2012-12-11 05:59:23 +04:00
t , err = t . Parse ( ` { { define "error.html" } }
2012-12-26 19:55:41 +04:00
< ! DOCTYPE html >
< html lang = "en" charset = "utf-8" >
2014-11-09 08:26:52 +03:00
< head >
< title > { { . Title } } < / title >
< meta name = "viewport" content = "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" >
< / head >
2012-12-11 05:59:23 +04:00
< body >
< h2 > { { . Title } } < / h2 >
< p > { { . Message } } < / p >
< hr >
2015-05-30 01:47:40 +03:00
< p > < a href = "{{.ProxyPrefix}}/sign_in" > Sign In < / a > < / p >
2012-12-11 05:59:23 +04:00
< / body >
< / html > { { end } } ` )
if err != nil {
2015-03-18 01:06:06 +03:00
log . Fatalf ( "failed parsing template %s" , err )
2012-12-11 05:59:23 +04:00
}
return t
}