diff --git a/cmd/owl/web/handler.go b/cmd/owl/web/handler.go index c835c4c..f7d6b2f 100644 --- a/cmd/owl/web/handler.go +++ b/cmd/owl/web/handler.go @@ -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) { return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { user, err := getUserFromRepo(repo, ps) diff --git a/cmd/owl/web/server.go b/cmd/owl/web/server.go index 81d3d3b..b5b542e 100644 --- a/cmd/owl/web/server.go +++ b/cmd/owl/web/server.go @@ -14,6 +14,7 @@ func Router(repo *owl.Repository) http.Handler { router.ServeFiles("/static/*filepath", http.Dir(repo.StaticDir())) router.GET("/", repoIndexHandler(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/index.xml", userRSSHandler(repo)) router.GET("/user/:user/posts/:post/", postHandler(repo)) @@ -27,6 +28,7 @@ func SingleUserRouter(repo *owl.Repository) http.Handler { router := httprouter.New() router.ServeFiles("/static/*filepath", http.Dir(repo.StaticDir())) router.GET("/", userIndexHandler(repo)) + router.GET("/auth/", userAuthHandler(repo)) router.GET("/media/*filepath", userMediaHandler(repo)) router.GET("/index.xml", userRSSHandler(repo)) router.GET("/posts/:post/", postHandler(repo)) diff --git a/embed/auth.html b/embed/auth.html new file mode 100644 index 0000000..65ba4bc --- /dev/null +++ b/embed/auth.html @@ -0,0 +1,5 @@ +
\ No newline at end of file diff --git a/embed/initial/base.html b/embed/initial/base.html index 2c2493b..003f0bb 100644 --- a/embed/initial/base.html +++ b/embed/initial/base.html @@ -27,6 +27,9 @@ + {{ if .User.AuthUrl }} + + {{ end }}