Esempio n. 1
0
func RouterInit() {
	// beforechange -- Just check auth
	beforeChange := jqeventrouter.NullHandler()
	jqeventrouter.Listen("pagecontainerbeforechange", general.JQMRouteOnce(general.CleanFacebookURI(auth.CheckAuth(beforeChange))))

	// beforetransition
	beforeTransition := jqeventrouter.NewEventMux()
	beforeTransition.SetUriFunc(func(_ *jquery.Event, ui *js.Object) string {
		return util.JqmTargetUri(ui)
	})
	beforeTransition.HandleFunc("/login.html", login.BeforeTransition)
	beforeTransition.HandleFunc("/logout.html", logout.BeforeTransition)
	beforeTransition.HandleFunc("/sync.html", sync_handler.BeforeTransition)
	jqeventrouter.Listen("pagecontainerbeforetransition", beforeTransition)
}
Esempio n. 2
0
func CheckAuth(h jqeventrouter.Handler) jqeventrouter.Handler {
	return jqeventrouter.HandlerFunc(func(event *jquery.Event, ui *js.Object) bool {
		console.Log("CheckAuth")
		uri := util.JqmTargetUri(ui)
		console.Log("Auth URI = %s", uri)
		if uri != "/login.html" && util.CurrentUser() == "" {
			console.Log("nobody's logged in")
			// Nobody's logged in
			ui.Set("toPage", "login.html")
			event.StopImmediatePropagation()
			console.Log("Attempting to re-trigger the event")
			jquery.NewJQuery(":mobile-pagecontainer").Trigger("pagecontainerbeforechange", ui)
			return true
		}
		console.Log("Auth allowing to proceed")
		return h.HandleEvent(event, ui)
	})
}
Esempio n. 3
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) 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)
		}
		// 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)
	})
}