Esempio n. 1
0
// Handler for unknown urls
func unknownHandler(response http.ResponseWriter, request *http.Request) {
	// If the user is logged in, redirect to homepage, otherwise redirect to landing page
	redirect_target := "/index"
	user_id := account.GetSessionUserId(request)
	if user_id != 0 {
		redirect_target = "/config"
	}
	http.Redirect(response, request, redirect_target, http.StatusFound)
}
Esempio n. 2
0
// Default handler AJAX calls
func makeAjaxHandler(fn func(http.ResponseWriter, *http.Request, int) string) http.HandlerFunc {
	return func(response http.ResponseWriter, request *http.Request) {
		// If the user is not logged in, redirect to landing page
		user_id := account.GetSessionUserId(request)
		if user_id == 0 {
			fmt.Fprint(response, "golanding")
		} else {
			// Function is executed and is results are returned to the client
			fmt.Fprint(response, fn(response, request, user_id))
		}
	}
}
Esempio n. 3
0
// Default handler logic for urls that require the user to be logged in
func makeHandler(fn func(http.ResponseWriter, *http.Request, int) []map[string]string) http.HandlerFunc {
	return func(response http.ResponseWriter, request *http.Request) {
		// If the user is not logged in, redirect to landing page
		user_id := account.GetSessionUserId(request)
		if user_id == 0 {
			http.Redirect(response, request, "/index", http.StatusFound)
		} else {
			handler_name := request.URL.Path[1:]
			view_data := View_data{template.JS(handler_name), fn(response, request, user_id)}
			temp := template.Must(template.New("layout").ParseFiles("views/layout.html", "views/"+handler_name+".html"))
			temp.Execute(response, view_data)
		}
	}
}