// DeleteAvatar is the handler for DELETE /users/{username}/avatar/{label}
// Delete the avatar with the specified label
765141
func (api UsersAPI) DeleteAvatar(w http.ResponseWriter, r *http.Request) {
	username := mux.Vars(r)["username"]
	label := mux.Vars(r)["label"]

	// return a status conflict when trying to delete a protected label
	if isReservedAvatarLabel(label) {
		http.Error(w, http.StatusText(http.StatusConflict), http.StatusConflict)
		return
	}

	userMgr := user.NewManager(r)
	u, err := userMgr.GetByName(username)
	avatar, err := u.GetAvatarByLabel(label)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}

	// If the link points to itsyou.online, we also need to remove the file stored here.
	if strings.HasPrefix(strings.TrimPrefix(avatar.Source, "https://"), r.Host) {
		hash := getAvatarHashFromLink(avatar.Source)
		err = userMgr.RemoveAvatarFile(hash)
		if handleServerError(w, "removing avatar file", err) {
			return
		}
	}
	err = userMgr.RemoveAvatar(username, label)
	if handleServerError(w, "deleting avatar", err) {
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusNoContent)
}
1277033
func (api UsersAPI) DeleteAuthorization(w http.ResponseWriter, r *http.Request) {
	username := mux.Vars(r)["username"]
	grantedTo := mux.Vars(r)["grantedTo"]

	userMgr := user.NewManager(r)

	err := userMgr.DeleteAuthorization(username, grantedTo)
	if handleServerError(w, "Delete authorization", err) {
		return
	}
	w.WriteHeader(http.StatusNoContent)
}
776264
func (t *Trending) buildAvatarURL(avatar string, exists bool) *url.URL {
	if exists == false {
		return nil
	}

	avatarURL, err := url.Parse(avatar)
	if err != nil {
		return nil
	}

	// Remove s parameter
	// The "s" parameter controls the size of the avatar
	q := avatarURL.Query()
	q.Del("s")
	avatarURL.RawQuery = q.Encode()

	return avatarURL
}
288681
func (t *Trending) getUserIDBasedOnAvatarURL(avatarURL *url.URL) int {
	id := 0
	if avatarURL == nil {
		return id
	}

	re := regexp.MustCompile("u/([0-9]+)")
	if matches := re.FindStringSubmatch(avatarURL.Path); len(matches) >= 2 && len(matches[1]) > 0 {
		id, _ = strconv.Atoi(matches[1])
	}
	return id
}
680207
func (s *VPNService) NewRemoveVpnUserParams(username string) *RemoveVpnUserParams {
	p := &RemoveVpnUserParams{}
	p.p = make(map[string]interface{})
	p.p["username"] = username
	return p
}
171993
func (a *API) DeleteUser(user *User) error {
	url := a.BuildURL("/v2/user/%d", user.Id)
	return a.Delete(url, Params{})
}
488059
func (m *MetaClient) DeleteUser(ctx context.Context, name string) error {
	a := &UserAction{
		Action: "delete",
		User: &User{
			Name: name,
		},
	}

	return m.Post(ctx, "/user", a, nil)
}
249014
func (s *Session) UserAvatarDecode(u *User) (img image.Image, err error) {
	body, err := s.RequestWithBucketID("GET", EndpointUserAvatar(u.ID, u.Avatar), nil, EndpointUserAvatar("", ""))
	if err != nil {
		return
	}

	img, _, err = image.Decode(bytes.NewReader(body))
	return
}
25535
func (s *AuthorizationsService) DeleteImpersonation(ctx context.Context, username string) (*Response, error) {
	u := fmt.Sprintf("admin/users/%v/authorizations", username)
	req, err := s.client.NewRequest("DELETE", u, nil)
	if err != nil {
		return nil, err
	}

	return s.client.Do(ctx, req, nil)
}
1041948
func (n *nessusImpl) DeleteUser(userID int) error {
	if n.verbose {
		log.Println("Deleting user...")
	}

	_, err := n.doRequest("DELETE", fmt.Sprintf("/users/%d", userID), nil, []int{http.StatusOK})
	return err
}
319527
func (b *BigIP) DeleteVirtualServer(name string) error {
	return b.delete(uriLtm, uriVirtual, name)
}
1024290
func (api UsersAPI) CreateAvatarFromImage(w http.ResponseWriter, r *http.Request) {
	label := mux.Vars(r)["label"]
	username := mux.Vars(r)["username"]

	userMgr := user.NewManager(r)
	u, err := userMgr.GetByName(username)
	if handleServerError(w, "getting user from db", err) {
		return
	}

	if !validateNewAvatar(w, label, u) {
		return
	}

	link, errorOccured := saveMultiPartAvatarFile(w, r, userMgr)
	if errorOccured {
		// the error responses are already written so just abort
		return
	}

	// insert a link to the endpoint that will serve the file
	avatar := user.Avatar{
		Label:  label,
		Source: link,
	}

	// save the avatar link to the user
	err = userMgr.SaveAvatar(username, avatar)
	if handleServerError(w, "saving avatar link", err) {
		return
	}

	w.WriteHeader(http.StatusCreated)
	json.NewEncoder(w).Encode(&avatar)
}
386169
func validateNewAvatar(w http.ResponseWriter, label string, u *user.User) bool {
	if !user.IsValidLabel(label) {
		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return false
	}

	if isReservedAvatarLabel(label) {
		writeErrorResponse(w, http.StatusConflict, "reserved_label")
		return false
	}

	if _, err := u.GetAvatarByLabel(label); err == nil {
		writeErrorResponse(w, http.StatusConflict, "duplicate_label")
		return false
	}

	// count the amount of avatars we already have
	if !(getUserAvatarCount(u) < maxAvatarAmount) {
		log.Debug("User has reached the max amount of avatars to upload")
		writeErrorResponse(w, http.StatusConflict, "max_avatar_amount")
		return false
	}
	return true
}
859170
func GetGravatar(id string, size int, dtype AvatarType) string {
	h := md5.New()
	h.Write([]byte(id))
	sum := h.Sum(nil)
	return fmt.Sprintf("https://secure.gravatar.com/avatar/%x?s=%d&d=%s", sum, size, dtype)
}
1305011
func (m *Manager) RemoveAvatar(username, label string) error {
	return m.getUserCollection().Update(
		bson.M{"username": username},
		bson.M{"$pull": bson.M{"avatars": bson.M{"label": label}}})
}
1131298
func (s *Service) DeleteLabel(ctx context.Context, id influxdb.ID) error {
	label, err := s.FindLabelByID(ctx, id)
	if label == nil && err != nil {
		return &influxdb.Error{
			Code: influxdb.ENotFound,
			Op:   OpPrefix + influxdb.OpDeleteLabel,
			Msg:  influxdb.ErrLabelNotFound,
		}
	}

	s.labelKV.Delete(id.String())
	return nil
}
1192647
func (c *Client) DeleteImageStore(p *DeleteImageStoreParameter) (*Result, error) {
	obj, err := c.Request("deleteImageStore", convertParamToMap(p))
	if err != nil {
		return nil, err
	}
	return obj.(*Result), err
}