func CheckAuth(prefix string, repo *model.Repo) func(jqeventrouter.Handler) jqeventrouter.Handler {
	return func(h jqeventrouter.Handler) jqeventrouter.Handler {
		return jqeventrouter.HandlerFunc(func(event *jquery.Event, ui *js.Object, params url.Values) bool {
			reqURL, _ := url.Parse(ui.Get("toPage").String())
			if reqURL.Path == prefix+"/callback.html" {
				// Allow unauthenticated callback, needed by dev logins
				return true
			}
			_, err := repo.CurrentUser()
			if err != nil && err != model.ErrNotLoggedIn {
				log.Printf("Unknown error: %s", err)
			}
			if err == model.ErrNotLoggedIn {
				redir := "login.html"
				log.Debug("TODO: use params instead of re-parsing URL?")
				parsed, _ := url.Parse(js.Global.Get("location").String())
				fmt.Printf("params = %v\nparsed = %v\n", params, parsed.Query())
				if p := parsed.Query().Get("provider"); p != "" {
					redir = "callback.html"
				}
				log.Printf("Redirecting unauthenticated user to %s\n", redir)
				log.Debug("TODO: Do I need ui.Set *and* trigger before change here?")
				ui.Set("toPage", redir)
				event.StopImmediatePropagation()
				jquery.NewJQuery(":mobile-pagecontainer").Trigger("pagecontainerbeforechange", ui)
				return true
			}
			return h.HandleEvent(event, ui, url.Values{})
		})
	}
}
// CheckAuth checks if a user has authenticated.
CheckAuth checks if a user has authenticated.
// CheckAuth checks if a user has authenticated .
func CheckAuth(prefix string, repo *model.Repo) func(jqeventrouter.Handler) jqeventrouter.Handler {
	return func(h jqeventrouter.Handler) jqeventrouter.Handler {
		return jqeventrouter.HandlerFunc(func(event *jquery.Event, ui *js.Object, params url.Values) bool {
			reqURL, _ := url.Parse(ui.Get("toPage").String())
			if reqURL.Path == prefix+"/callback.html" {
				return true
			}
			_, err := repo.CurrentUser()
			if err != nil && err != model.ErrNotLoggedIn {
				log.Printf("Unknown error: %s", err)
			}
			if err == model.ErrNotLoggedIn {
				redir := "login.html"
				log.Debug("TODO: use params instead of re-parsing URL?")
				parsed, _ := url.Parse(js.Global.Get("location").String())
				fmt.Printf("params = %v\nparsed = %v\n", params, parsed.Query())
				if p := parsed.Query().Get("provider"); p != "" {
					redir = "callback.html"
				}
				log.Printf("Redirecting unauthenticated user to %s\n", redir)
				log.Debug("TODO: Do I need ui.Set *and* trigger before change here?")
				ui.Set("toPage", redir)
				event.StopImmediatePropagation()
				jquery.NewJQuery(":mobile-pagecontainer").Trigger("pagecontainerbeforechange", ui)
				return true
			}
			return h.HandleEvent(event, ui, url.Values{})
		})
	}
}
func CheckAuth ( prefix string , repo * model . Repo ) func ( jqeventrouter . Handler ) jqeventrouter . Handler { return func ( h jqeventrouter . Handler ) jqeventrouter . Handler { return jqeventrouter . HandlerFunc ( func ( event * jquery . Event , ui * js . Object , params url . Values ) bool { reqURL , _ := url . Parse ( ui . Get ( " " ) . String ( ) ) if reqURL . Path == prefix + " " { return true } _ , err := repo . CurrentUser ( ) if err != nil && err != model . ErrNotLoggedIn { log . Printf ( " " , err ) } if err == model . ErrNotLoggedIn { redir := " " log . Debug ( " " ) parsed , _ := url . Parse ( js . Global . Get ( " " ) . String ( ) ) fmt . Printf ( " \n \n " , params , parsed . Query ( ) ) if p := parsed . Query ( ) . Get ( " " ) ; p != " " { redir = " " } log . Printf ( " \n " , redir ) log . Debug ( " " ) ui . Set ( " " , redir ) event . StopImmediatePropagation ( ) jquery . NewJQuery ( " " ) . Trigger ( " " , ui ) return true } return h . HandleEvent ( event , ui , url . Values { } ) } ) } }
CheckAuth checks if a user has authenticated.
CheckAuth checks if a user has authenticated .
// Allow unauthenticated callback, needed by dev logins