WIP Login Page
This commit is contained in:
parent
2acca40afe
commit
1072f48e9f
|
@ -59,6 +59,26 @@ func userIndexHandler(repo *owl.Repository) func(http.ResponseWriter, *http.Requ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func userAuthHandler(repo *owl.Repository) func(http.ResponseWriter, *http.Request, httprouter.Params) {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
|
user, err := getUserFromRepo(repo, ps)
|
||||||
|
if err != nil {
|
||||||
|
println("Error getting user: ", err.Error())
|
||||||
|
notFoundHandler(repo)(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
html, err := owl.RenderUserAuthPage(user)
|
||||||
|
if err != nil {
|
||||||
|
println("Error rendering auth page: ", err.Error())
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
w.Write([]byte("Internal server error"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
println("Rendering auth page for user", user.Name())
|
||||||
|
w.Write([]byte(html))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func userWebmentionHandler(repo *owl.Repository) func(http.ResponseWriter, *http.Request, httprouter.Params) {
|
func userWebmentionHandler(repo *owl.Repository) func(http.ResponseWriter, *http.Request, httprouter.Params) {
|
||||||
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
user, err := getUserFromRepo(repo, ps)
|
user, err := getUserFromRepo(repo, ps)
|
||||||
|
|
|
@ -14,6 +14,7 @@ func Router(repo *owl.Repository) http.Handler {
|
||||||
router.ServeFiles("/static/*filepath", http.Dir(repo.StaticDir()))
|
router.ServeFiles("/static/*filepath", http.Dir(repo.StaticDir()))
|
||||||
router.GET("/", repoIndexHandler(repo))
|
router.GET("/", repoIndexHandler(repo))
|
||||||
router.GET("/user/:user/", userIndexHandler(repo))
|
router.GET("/user/:user/", userIndexHandler(repo))
|
||||||
|
router.GET("/user/:user/auth/", userAuthHandler(repo))
|
||||||
router.GET("/user/:user/media/*filepath", userMediaHandler(repo))
|
router.GET("/user/:user/media/*filepath", userMediaHandler(repo))
|
||||||
router.GET("/user/:user/index.xml", userRSSHandler(repo))
|
router.GET("/user/:user/index.xml", userRSSHandler(repo))
|
||||||
router.GET("/user/:user/posts/:post/", postHandler(repo))
|
router.GET("/user/:user/posts/:post/", postHandler(repo))
|
||||||
|
@ -27,6 +28,7 @@ func SingleUserRouter(repo *owl.Repository) http.Handler {
|
||||||
router := httprouter.New()
|
router := httprouter.New()
|
||||||
router.ServeFiles("/static/*filepath", http.Dir(repo.StaticDir()))
|
router.ServeFiles("/static/*filepath", http.Dir(repo.StaticDir()))
|
||||||
router.GET("/", userIndexHandler(repo))
|
router.GET("/", userIndexHandler(repo))
|
||||||
|
router.GET("/auth/", userAuthHandler(repo))
|
||||||
router.GET("/media/*filepath", userMediaHandler(repo))
|
router.GET("/media/*filepath", userMediaHandler(repo))
|
||||||
router.GET("/index.xml", userRSSHandler(repo))
|
router.GET("/index.xml", userRSSHandler(repo))
|
||||||
router.GET("/posts/:post/", postHandler(repo))
|
router.GET("/posts/:post/", postHandler(repo))
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
<form action="" method="post">
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input type="password" name="password" placeholder="Password">
|
||||||
|
<input type="submit" value="Login">
|
||||||
|
</form>
|
|
@ -27,6 +27,9 @@
|
||||||
|
|
||||||
<link rel="stylesheet" href="/static/pico.min.css">
|
<link rel="stylesheet" href="/static/pico.min.css">
|
||||||
<link rel="webmention" href="{{ .User.WebmentionUrl }}">
|
<link rel="webmention" href="{{ .User.WebmentionUrl }}">
|
||||||
|
{{ if .User.AuthUrl }}
|
||||||
|
<link rel="authorization_endpoint" href="{{ .User.AuthUrl}}">
|
||||||
|
{{ end }}
|
||||||
<style>
|
<style>
|
||||||
header {
|
header {
|
||||||
background-color: {{.User.Config.HeaderColor}};
|
background-color: {{.User.Config.HeaderColor}};
|
||||||
|
|
11
renderer.go
11
renderer.go
|
@ -107,7 +107,18 @@ func RenderIndexPage(user User) (string, error) {
|
||||||
Title: "Index",
|
Title: "Index",
|
||||||
Content: template.HTML(postHtml),
|
Content: template.HTML(postHtml),
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func RenderUserAuthPage(user User) (string, error) {
|
||||||
|
authHtml, err := renderEmbedTemplate("embed/auth.html", user)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return renderIntoBaseTemplate(user, PageContent{
|
||||||
|
Title: "Auth",
|
||||||
|
Content: template.HTML(authHtml),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenderUserList(repo Repository) (string, error) {
|
func RenderUserList(repo Repository) (string, error) {
|
||||||
|
|
|
@ -285,3 +285,11 @@ func TestAddFaviconIfExist(t *testing.T) {
|
||||||
result, _ := owl.RenderIndexPage(user)
|
result, _ := owl.RenderIndexPage(user)
|
||||||
assertions.AssertContains(t, result, "favicon.png")
|
assertions.AssertContains(t, result, "favicon.png")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRenderUserAuth(t *testing.T) {
|
||||||
|
user := getTestUser()
|
||||||
|
user.ResetPassword("test")
|
||||||
|
result, err := owl.RenderUserAuthPage(user)
|
||||||
|
assertions.AssertNoError(t, err, "Error rendering user auth page")
|
||||||
|
assertions.AssertContains(t, result, "<form")
|
||||||
|
}
|
||||||
|
|
8
user.go
8
user.go
|
@ -44,6 +44,14 @@ func (user User) FullUrl() string {
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (user User) AuthUrl() string {
|
||||||
|
if user.Config().PassworHash == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
url, _ := url.JoinPath(user.FullUrl(), "auth/")
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
func (user User) WebmentionUrl() string {
|
func (user User) WebmentionUrl() string {
|
||||||
url, _ := url.JoinPath(user.FullUrl(), "webmention/")
|
url, _ := url.JoinPath(user.FullUrl(), "webmention/")
|
||||||
return url
|
return url
|
||||||
|
|
Loading…
Reference in New Issue