func handleUpdate(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) var ( d int day time.Weekday err error ) // Check if there is a signed in user. u := currentUser(r) if u == nil { aelog.Errorf(c, "No signed in user for updating") goto out } // Validate XSRF token first. if !xsrftoken.Valid(r.PostFormValue(xsrfTokenName), xsrfKey, u.ID, updateURL) { aelog.Errorf(c, "XSRF token validation failed") goto out } // Extract the new favorite weekday. d, err = strconv.Atoi(r.PostFormValue(favoriteName)) if err != nil { aelog.Errorf(c, "Failed to extract new favoriate weekday: %s", err) goto out } day = time.Weekday(d) if day < time.Sunday || day > time.Saturday { aelog.Errorf(c, "Got wrong value for favorite weekday: %d", d) } // Update the favorite weekday. updateWeekdayForUser(r, u, day) out: // Redirect to home page to show the update result. http.Redirect(w, r, homeURL, http.StatusFound) }
func handleDeleteAccount(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) // Check if there is a signed in user. u := currentUser(r) if u == nil { aelog.Errorf(c, "No signed in user for updating") goto out } // Validate XSRF token first. if !xsrftoken.Valid(r.PostFormValue(xsrfTokenName), xsrfKey, u.ID, deleteAccountURL) { aelog.Errorf(c, "XSRF token validation failed") goto out } // Delete account. if err := gitkitClient.DeleteUser(c, &gitkit.User{LocalID: u.ID}); err != nil { aelog.Errorf(c, "Failed to delete user %+v: %s", *u, err) goto out } // Account deletion succeeded. Call sign out to clear session and identity // toolkit token. handleSignOut(w, r) return out: http.Redirect(w, r, homeURL, http.StatusFound) }
func handleUpdate(w http.ResponseWriter, r *http.Request) { operationResult := "failure" outFunc := func() { http.Redirect(w, r, successLandingURL+"?update="+operationResult, http.StatusFound) } var ( d int day time.Weekday err error ) // Generic c := appengine.NewContext(r) // Check if there is a signed in user. u := CurrentUser(r) if u == nil { aelog.Errorf(c, "No signed in user for updating") outFunc() goto out } // Validate XSRF token first. if !xsrftoken.Valid(r.PostFormValue(xsrfTokenName), xsrfKey, u.ID, updateURL) { aelog.Errorf(c, "XSRF token validation failed") outFunc() goto out } // // Specific // Extract the new favorite weekday. d, err = strconv.Atoi(r.PostFormValue(fieldNameFavWeekDay)) if err != nil { aelog.Errorf(c, "Failed to extract new favoriate weekday: %s", err) outFunc() goto out } day = time.Weekday(d) if day < time.Sunday || day > time.Saturday { aelog.Errorf(c, "Got wrong value for favorite weekday: %d", d) outFunc() goto out } // Update the favorite weekday. updateWeekdayForUser(r, u, day) operationResult = "success" out: outFunc() }
/* Failed to delete user {ID:14423325142879445183 Email:[email protected] Name:Peter Buchmann EmailVerified:true}: googleapi: Error 400: INVALID_LOCAL_ID, invalid Failed to delete 00880189686365773816 Failed to delete user {ID: }: googleapi: Error 400: INVALID_LOCAL_ID, invalid */ func handleDeleteAccount(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) var ( client *gitkit.Client err error ) // Check if there is a signed in user. u := CurrentUser(r) if u == nil { aelog.Errorf(c, "No signed in user for updating") goto out } // Validate XSRF token first. if !xsrftoken.Valid(r.PostFormValue(xsrfTokenName), xsrfKey, u.ID, deleteAccountURL) { aelog.Errorf(c, "XSRF token validation failed") goto out } // Create an identity toolkit client associated with the GAE context. client, err = gitkit.NewWithContext(c, gitkitClient) if err != nil { aelog.Errorf(c, "Failed to create a gitkit.Client with a context: %s", err) goto out } // Delete account. err = client.DeleteUser(&gitkit.User{LocalID: u.ID}) if err != nil { aelog.Errorf(c, "Failed to delete user %v %v: %s", u.ID, u.Email, err) goto out } // Account deletion succeeded. // Call sign out to clear session and identity toolkit token. aelog.Infof(c, "Account deletion succeeded") handleSignOut(w, r) return out: http.Redirect(w, r, successLandingURL, http.StatusFound) }