Exemple #1
0
// LoginHandler logs a user in
func LoginHandler(w http.ResponseWriter, r *http.Request) {
	if r.Method == "POST" {
		email := strings.TrimSpace(r.FormValue("email"))
		password := r.FormValue("password")
		u, err := Authenticate(email, password, w, r)
		if err != nil {
			u = &User{Email: email}
			render.RenderTemplate(w, "auth_register", map[string]interface{}{
				"request": r,
				"user":    u,
			})
			return
		}
		render.Redirect(w, r, "/")
		return
	}

	render.RenderTemplate(w, "auth_login", nil)
}
Exemple #2
0
// LogoutHandler signs a user out
func LogoutHandler(w http.ResponseWriter, r *http.Request) {
	Deauthenticate(w, r)
	render.RenderTemplate(w, "auth_logout", nil)
}