Example #1
0
func (h *Handler) handleUserUpdate(w http.ResponseWriter, r *http.Request) {
	segments := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
	username := segments[2]

	s, err := session.Parse(r)
	if err != nil {
		http.Redirect(w, r, fmt.Sprintf("%s/u/%s",
			config.Get("baseurl"), username), http.StatusFound)
		return
	}

	if s.User.Username != username {
		http.Redirect(w, r, fmt.Sprintf("%s/u/%s",
			config.Get("baseurl"), username), http.StatusFound)
		return
	}

	msg, _ := flashdata.Get(w, r)

	m := map[string]interface{}{
		"baseurl": config.Get("baseurl"),
		"session": s,
		"message": msg,
		"form": map[string]string{
			"email":    s.User.Email,
			"fullname": s.User.Fullname,
		},
	}

	h.Templates.ExecuteTemplate(w, "user_update.html", m)
}
Example #2
0
func (h *Handler) handleMessage(w http.ResponseWriter, r *http.Request) {
	s, ok := flashdata.Get(w, r)
	if !ok {
		http.Redirect(w, r, config.Get("baseurl"), http.StatusFound)
		return
	}

	s = strings.Replace(s, "\n", "<br>\n", -1)
	logger.Info(w, s)

	m := map[string]interface{}{
		"baseurl": config.Get("baseurl"),
		"message": template.HTML(s),
	}

	h.Templates.ExecuteTemplate(w, "message.html", m)
}
Example #3
0
func (h *Handler) handleUser(w http.ResponseWriter, r *http.Request) {
	segments := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
	username := segments[2]

	s, err := session.Parse(r)
	if err != nil {
		logger.Error(w, err)
	} else {
		err = s.Save(w, true)
		if err != nil {
			logger.Error(w, err)
		}
	}

	var owner bool
	var u *user.User
	if s != nil && s.User.Username == username {
		owner = true
		u = s.User
	} else {
		owner = false
		u, err = user.LoadByUsername(username)
		if err != nil {
			logger.Error(w, err)
			h.serveNotFound(w, r)
			return
		}
	}

	msg, _ := flashdata.Get(w, r)

	m := map[string]interface{}{
		"baseurl": config.Get("baseurl"),
		"session": s,
		"message": msg,
		"user":    u,
		"owner":   owner,
	}

	h.Templates.ExecuteTemplate(w, "user.html", m)
}