From: Florian Forster Date: Tue, 30 Jan 2018 08:49:52 +0000 (+0100) Subject: Implement a /login handler. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=5d1b54cd5ed93ec0a8526dda23885b7b7fd6521e;p=kraftakt.git Implement a /login handler. --- diff --git a/kraftakt.go b/kraftakt.go index 976bbd4..95d7b46 100644 --- a/kraftakt.go +++ b/kraftakt.go @@ -25,6 +25,7 @@ var delayedHandleNotifications = delay.Func("handleNotifications", handleNotific var templates *template.Template func init() { + http.Handle("/login", AuthenticatedHandler(loginHandler)) http.Handle("/fitbit/connect", AuthenticatedHandler(fitbitConnectHandler)) http.Handle("/fitbit/grant", AuthenticatedHandler(fitbitGrantHandler)) http.Handle("/fitbit/disconnect", AuthenticatedHandler(fitbitDisconnectHandler)) @@ -125,6 +126,16 @@ func indexHandler(ctx context.Context, w http.ResponseWriter, _ *http.Request) e return templates.ExecuteTemplate(w, templateName, &templateData) } +func loginHandler(_ context.Context, w http.ResponseWriter, r *http.Request, _ *app.User) error { + // essentially a nop; all the heavy lifting (i.e. logging in) has been done by the AuthenticatedHandler wrapper. + redirectURL := r.URL + redirectURL.Path = "/" + redirectURL.RawQuery = "" + redirectURL.Fragment = "" + http.Redirect(w, r, redirectURL.String(), http.StatusTemporaryRedirect) + return nil +} + func fitbitConnectHandler(_ context.Context, w http.ResponseWriter, r *http.Request, _ *app.User) error { http.Redirect(w, r, fitbit.AuthURL(), http.StatusTemporaryRedirect) return nil