Пример #1
0
// TODO
func (u *User) Profile(response http.ResponseWriter, request *http.Request) {
	user_id, _ := utilities.GetUserId(request)
	db := utilities.GetDB(request)
	user := new(models.User)
	user.Get(db, user_id)
	user.Password = ""
	out, _ := json.Marshal(user)
	response.Write(out)
}
Пример #2
0
/// Method for the authentication struct that takes
// an HTTP request and returns an HTTP response containing
// the user's details.
func (a *Auth) User(request http.ResponseWriter, response *http.Request) {
	db := utilities.GetDB(response)
	session := sessions.GetSession(response)
	user_id := session.Get("user_id")
	fmt.Println(user_id)
	if user_id == nil {
		request.WriteHeader(403)
	} else {
		user := new(models.User)
		user.Get(db, user_id.(string))
		fmt.Println(user)
		outData, _ := json.Marshal(user)
		request.Write(outData)
	}
}
Пример #3
0
/// Method for the user struct that takes an HTTP request and
// returns an HTTP response containing the user's details for
// their ID.
func (u *User) Get(response http.ResponseWriter, request *http.Request) {
	vars := mux.Vars(request)
	id := vars["id"]

	db := utilities.GetDB(request)
	user := new(models.User)
	err := user.Get(db, id)
	if err != nil {
		response.WriteHeader(404)
	} else {
		user.Password = ""
		out, _ := json.Marshal(user)
		response.Write(out)
	}
}