Permalink
Browse files

Various useful features for m.goread.io

  • Loading branch information...
mjibson committed Sep 23, 2016
1 parent 08a3af6 commit 7e8468fd05cf9bbef6c805716f85015ca9d59d30
Showing with 14 additions and 3 deletions.
  1. +4 −2 main.go
  2. +1 −1 types.go
  3. +9 −0 user.go
@@ -59,6 +59,7 @@ func RegisterHandlers(r *mux.Router) {
router = r
router.Handle("/", mpg.NewHandler(Main)).Name("main")
router.Handle("/login/google", mpg.NewHandler(LoginGoogle)).Name("login-google")
router.Handle("/login/redirect", mpg.NewHandler(LoginRedirect))
router.Handle("/logout", mpg.NewHandler(Logout)).Name("logout")
router.Handle("/push", mpg.NewHandler(SubscribeCallback)).Name("subscribe-callback")
router.Handle("/tasks/import-opml", mpg.NewHandler(ImportOpmlTask)).Name("import-opml-task")
@@ -121,8 +122,9 @@ func RegisterHandlers(r *mux.Router) {
func wrap(f func(mpg.Context, http.ResponseWriter, *http.Request)) http.Handler {
handler := mpg.NewHandler(f)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if isDevServer {
w.Header().Add("Access-Control-Allow-Origin", r.Header.Get("Origin"))
o := r.Header.Get("Origin")
if isDevServer || o == "https://m.goread.io" || o == "http://localhost:3000" {
w.Header().Add("Access-Control-Allow-Origin", o)
w.Header().Add("Access-Control-Allow-Credentials", "true")
}
handler.ServeHTTP(w, r)
@@ -129,7 +129,7 @@ type Feed struct {
Date time.Time `datastore:"d,noindex" json:"-"`
Checked time.Time `datastore:"c,noindex"`
NextUpdate time.Time `datastore:"n"`
Link string `datastore:"l,noindex" json:"-"`
Link string `datastore:"l,noindex"`
Hub string `datastore:"h,noindex" json:"-"`
Errors int `datastore:"e,noindex"`
Image string `datastore:"i,noindex"`
@@ -60,6 +60,15 @@ func LoginGoogle(c mpg.Context, w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, routeUrl("main"), http.StatusFound)
}
func LoginRedirect(c mpg.Context, w http.ResponseWriter, r *http.Request) {
url, err := user.LoginURL(c, r.FormValue("redirect"))
if err != nil {
serveError(w, err)
return
}
http.Redirect(w, r, url, http.StatusFound)
}
func Logout(c mpg.Context, w http.ResponseWriter, r *http.Request) {
if appengine.IsDevAppServer() {
if u, err := user.LogoutURL(c, routeUrl("main")); err == nil {

0 comments on commit 7e8468f

Please sign in to comment.