コード例 #1
0
ファイル: user.go プロジェクト: mmanjoura/utm
// 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
ファイル: auth.go プロジェクト: mmanjoura/utm
/// 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
ファイル: user.go プロジェクト: mmanjoura/utm
/// 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)
	}
}