Exemple #1
0
func userViewHandler(
	cdb *db.ContactDB, userdb *db.UserDB, stationdb *db.StationDB,
	w http.ResponseWriter, r *http.Request, user userView) {

	if len(r.URL.Path) < len(userURLPrefix) {
		http.Error(w, "Invalid path", http.StatusBadRequest)
		return
	}
	id := r.URL.Path[len(userURLPrefix):]

	u, err := userdb.Lookup(id)
	if err != nil {
		log.Printf("Error looking up user: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}
	if u == nil {
		http.NotFound(w, r)
		return
	}

	if r.Method == "POST" && !changeUserProfile(userdb, w, r, user, u) {
		return
	}
	renderUserProfile(cdb, stationdb, w, r, user, u)
}
Exemple #2
0
func LookupUserView(userdb *db.UserDB, userid string) (v userView) {
	v.Id = userid

	u, _ := userdb.Lookup(userid)
	if u == nil {
		return v
	}

	if u.DisplayName != nil {
		v.Name = *u.DisplayName
		if u.Callsign != nil {
			v.Name += " " + *u.Callsign
		}
	}
	if u.PhotoUrl != nil {
		v.PhotoUrl = *u.PhotoUrl
	}

	return v
}