X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=kraftakt.go;h=61a576edf720a6df71e700d4762eca6c6a2f069d;hb=ac25c9764310be649dc18d0a02a1c127f0d73565;hp=95d7b460f434ff464369ba326b162e59d46e4edc;hpb=5d1b54cd5ed93ec0a8526dda23885b7b7fd6521e;p=kraftakt.git diff --git a/kraftakt.go b/kraftakt.go index 95d7b46..61a576e 100644 --- a/kraftakt.go +++ b/kraftakt.go @@ -136,8 +136,8 @@ func loginHandler(_ context.Context, w http.ResponseWriter, r *http.Request, _ * return nil } -func fitbitConnectHandler(_ context.Context, w http.ResponseWriter, r *http.Request, _ *app.User) error { - http.Redirect(w, r, fitbit.AuthURL(), http.StatusTemporaryRedirect) +func fitbitConnectHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, u *app.User) error { + http.Redirect(w, r, fitbit.AuthURL(ctx, u), http.StatusTemporaryRedirect) return nil } @@ -171,16 +171,9 @@ func fitbitDisconnectHandler(ctx context.Context, w http.ResponseWriter, r *http return err } - var errs appengine.MultiError - if err := c.Unsubscribe(ctx); err != nil { - errs = append(errs, fmt.Errorf("Unsubscribe() = %v", err)) - } - - if err := c.DeleteToken(ctx); err != nil { - errs = append(errs, fmt.Errorf("DeleteToken() = %v", err)) - } - if len(errs) != 0 { - return errs + if err := c.UnsubscribeAll(ctx); err != nil { + log.Errorf(ctx, "UnsubscribeAll() = %v", err) + return fmt.Errorf("deleting all subscriptions failed") } redirectURL := r.URL @@ -191,8 +184,8 @@ func fitbitDisconnectHandler(ctx context.Context, w http.ResponseWriter, r *http return nil } -func googleConnectHandler(_ context.Context, w http.ResponseWriter, r *http.Request, _ *app.User) error { - http.Redirect(w, r, gfit.AuthURL(), http.StatusTemporaryRedirect) +func googleConnectHandler(ctx context.Context, w http.ResponseWriter, r *http.Request, u *app.User) error { + http.Redirect(w, r, gfit.AuthURL(ctx, u), http.StatusTemporaryRedirect) return nil } @@ -272,6 +265,8 @@ func fitbitNotifyHandler(ctx context.Context, w http.ResponseWriter, r *http.Req // handleNotifications parses fitbit notifications and requests the individual // activities from Fitbit. It is executed asynchronously via the delay package. func handleNotifications(ctx context.Context, payload []byte) error { + log.Debugf(ctx, "NOTIFY -> %s", payload) + if err := app.LoadConfig(ctx); err != nil { return err } @@ -297,7 +292,7 @@ func handleNotifications(ctx context.Context, payload []byte) error { } func handleNotification(ctx context.Context, s *fitbit.Subscription) error { - u, err := app.UserByID(ctx, s.SubscriptionID) + u, err := fitbit.UserFromSubscriberID(ctx, s.SubscriptionID) if err != nil { return err }