Ejemplo n.º 1
0
func CheckAuth(h jqeventrouter.Handler) jqeventrouter.Handler {
	return jqeventrouter.HandlerFunc(func(event *jquery.Event, ui *js.Object, p url.Values) bool {
		uri := util.JqmTargetUri(ui)
		if uri != "/login.html" && util.CurrentUser() == "" {
			// Nobody's logged in
			ui.Set("toPage", "login.html")
			event.StopImmediatePropagation()
			jquery.NewJQuery(":mobile-pagecontainer").Trigger("pagecontainerbeforechange", ui)
			return true
		}
		return h.HandleEvent(event, ui, p)
	})
}
Ejemplo n.º 2
0
func CleanFacebookURI(h jqeventrouter.Handler) jqeventrouter.Handler {
	// This handler cleans up the URL after a redirect from a Facebook login
	return jqeventrouter.HandlerFunc(func(event *jquery.Event, ui *js.Object, p url.Values) bool {
		uri := util.JqmTargetUri(ui)
		// Having '#_=_' in the URL can mess up our routing
		if strings.HasSuffix(uri, "#_=_") {
			uri = strings.TrimSuffix(uri, "#_=_")
			ui.Set("toPage", uri)
		}
		// TODO: Can we change the hash without refreshing the page?
		// It's also ugly, so remove it from the visible location bar
		// location := js.Global.Get("location")
		// href := location.Get("href").String()
		// if strings.HasSuffix(href, "#_=_") {
		//	location.Set("href", strings.TrimSuffix(href, "#_=_"))
		// }
		return h.HandleEvent(event, ui, p)
	})
}
Ejemplo n.º 3
0
func getJqmUri(_ *jquery.Event, ui *js.Object) string {
	return util.JqmTargetUri(ui)
}