Beispiel #1
0
// Delete handles DELETE
func (ctl *ProfileController) Delete(c *models.Context) {
	// Right now no-one can delete as it would break attribution
	// of things like Comments
	c.RespondWithNotImplemented()
	return

	/*
		_, itemTypeID, itemID, status, err := c.GetItemTypeAndItemID()
		if err != nil {
			c.RespondWithErrorDetail(err, status)
		}

		m := models.ProfileType{}
		m.Id = itemID

		status, err := m.Delete()
		if err != nil {
			c.RespondWithErrorDetail(err, status)
			return
		}

		audit.Replace(
			c.Site.ID,
			h.ItemTypes[h.ItemTypeProfile],
			m.Id,
			c.Auth.ProfileID,
			time.Now(),
			c.IP,
		)

		c.RespondWithOK()
	*/
}
Beispiel #2
0
func (wc *WhoAmIController) Read(c *models.Context) {

	if c.Request.Method != "GET" {
		c.RespondWithNotImplemented()
		return
	}

	if c.Auth.UserID < 0 {
		c.RespondWithErrorMessage(
			"Bad access token supplied",
			http.StatusForbidden,
		)
		return
	}

	if c.Auth.UserID == 0 {
		c.RespondWithErrorMessage(
			"You must be authenticated to ask 'who am I?'",
			http.StatusForbidden,
		)
		return
	}

	m, status, err := models.GetProfileSummary(c.Site.ID, c.Auth.ProfileID)
	if err != nil {
		if status == http.StatusNotFound {
			c.RespondWithErrorMessage(
				"You must create a user profile for this site at api/v1/profiles/",
				http.StatusNotFound,
			)
			return
		}

		c.RespondWithErrorMessage(
			fmt.Sprintf("Could not retrieve profile: %v", err.Error()),
			http.StatusInternalServerError,
		)
		return
	}

	location := fmt.Sprintf(
		"%s/%d",
		h.APITypeProfile,
		m.ID,
	)

	if c.Auth.ProfileID > 0 && c.Auth.Method == "query" {
		u, _ := url.Parse(location)
		qs := u.Query()
		qs.Del("access_token")
		qs.Add("access_token", c.Auth.AccessToken.TokenValue)
		u.RawQuery = qs.Encode()
		location = u.String()
	}

	c.ResponseWriter.Header().Set("Location", location)
	c.RespondWithStatus(307)
}