func handleHome(w http.ResponseWriter, r *http.Request) {
	u := currentUser(r)
	var d time.Weekday
	if u != nil {
		d = weekdayForUser(r, u)
	}
	saveCurrentUser(r, w, u)
	var xf, xd string
	if u != nil {
		xf = xsrftoken.Generate(xsrfKey, u.ID, updateURL)
		xd = xsrftoken.Generate(xsrfKey, u.ID, deleteAccountURL)
	}
	homeTemplate.Execute(
		w,
		struct {
			WidgetURL              string
			SignOutURL             string
			User                   *User
			WeekdayIndex           int
			Weekdays               []time.Weekday
			UpdateWeekdayURL       string
			UpdateWeekdayXSRFToken string
			DeleteAccountURL       string
			DeleteAccountXSRFToken string
		}{widgetURL, signOutURL, u, int(d), weekdays, updateURL, xf, deleteAccountURL, xd})
}
示例#2
0
func UNUSEDhandleHome(w http.ResponseWriter, r *http.Request) {

	u := CurrentUser(r)
	var d time.Weekday
	if u != nil {
		d = weekdayForUser(r, u)
	}
	saveCurrentUser(r, w, u)
	var xf, xd string
	if u != nil {
		xf = xsrftoken.Generate(xsrfKey, u.ID, updateURL)
		xd = xsrftoken.Generate(xsrfKey, u.ID, deleteAccountURL)
	}

	homeTemplate := getHomeTpl(w, r)
	homeTemplate.Execute(w, map[string]interface{}{
		"CookieDump":             template.HTML(htmlfrag.CookieDump(r)),
		"WidgetURL":              widgetSigninAuthorizedRedirectURL,
		"SignOutURL":             signOutURL,
		"User":                   u,
		"WeekdayIndex":           d,
		"Weekdays":               weekdays,
		"UpdateWeekdayURL":       updateURL,
		"UpdateWeekdayXSRFToken": xf,
		"DeleteAccountURL":       deleteAccountURL,
		"DeleteAccountXSRFToken": xd,
	})
}
示例#3
0
文件: gitkit.go 项目: aarzilli/tools
func HandleSuccess(w http.ResponseWriter, r *http.Request) {

	u := CurrentUser(r)

	if ok := IsSignedIn(r); !ok {
		u = nil
	}

	if u == nil {
		http.Redirect(w, r, widgetSigninAuthorizedRedirectURL+"?mode=select&user=wasNil", http.StatusFound)
	}

	saveCurrentUser(r, w, u)
	var xf string
	if u != nil {
		xf = xsrftoken.Generate(xsrfKey, u.ID, updateURL)
	}

	//
	var d time.Weekday
	if u != nil {
		d = weekdayForUser(r, u)
	}

	homeTemplate := getHomeTpl(w, r)
	homeTemplate.Execute(w, map[string]interface{}{
		"WidgetURL":              widgetSigninAuthorizedRedirectURL,
		"SignOutURL":             signOutURL,
		"User":                   u,
		"WeekdayIndex":           d,
		"Weekdays":               weekdays,
		"UpdateWeekdayURL":       updateURL,
		"UpdateWeekdayXSRFToken": xf,
		// "CookieDump": template.HTML(htmlfrag.CookieDump(r)),
	})
}