// UserAvatar is deprecated. Please use UserAvatarDecode
// userID    : A user ID or "@me" which is a shortcut of current user ID
774916
func (s *Session) UserAvatar(userID string) (img image.Image, err error) {
	u, err := s.User(userID)
	if err != nil {
		return
	}
	img, err = s.UserAvatarDecode(u)
	return
}
1059569
func (b LeveldbAuthBackend) User(username string) (user UserData, e error) {
	if user, ok := b.users[username]; ok {
		return user, nil
	}
	return user, ErrMissingUser
}
650873
func (api UsersAPI) UpdateAvatarLink(w http.ResponseWriter, r *http.Request) {
	username := mux.Vars(r)["username"]
	oldLabel := mux.Vars(r)["label"]

	body := user.Avatar{}
	err := json.NewDecoder(r.Body).Decode(&body)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return
	}

	newLabel := body.Label

	userMgr := user.NewManager(r)
	oldAvatar, errorOccurred := validateAvatarUpdateLabels(oldLabel, newLabel, username, userMgr, w)
	if errorOccurred {
		return
	}

	newAvatar := &user.Avatar{
		Label:  newLabel,
		Source: body.Source,
	}

	replaceAvatar(w, r, oldAvatar, newAvatar, username, userMgr)

}
630413
func (b SqlAuthBackend) User(username string) (user UserData, e error) {
	row := b.userStmt.QueryRow(username)
	err := row.Scan(&user.Email, &user.Hash, &user.Role)
	if err != nil {
		if err == sql.ErrNoRows {
			return user, ErrMissingUser
		}
		return user, mksqlerror(err.Error())
	}
	user.Username = username
	return user, nil
}
1044023
func (self *OpenIdProvider) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request) (User, Token, error) {

	// Parse the url parameters
	params := r.URL.Query()

	// Check to see if the user successfully authenticated
	if params.Get("openid.mode") == "cancel" {
		return nil, nil, ErrAuthDeclined
	}

	// Get the user details from the URL parameters
	lastName := params.Get("openid.ext1.value.lastname")
	firstName := params.Get("openid.ext1.value.firstname")
	fullName := fmt.Sprintf("%s %s", firstName, lastName)
	email := params.Get("openid.ext1.value.email")

	// Return the User data
	// TODO for now we are re-using the Google User
	user := user{id: email, email: email, name: fullName, provider: self.endpoint }
	return &user, nil, nil
}
40238
func (o *Enterprise) CreateAvatar(child *Avatar) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
174009
func (t *Store) UserToken() string {
	t.l.RLock()
	defer t.l.RUnlock()

	return t.userToken
}
1311319
func (repo *Repository) UploadAvatar(data []byte) error {
	img, _, err := image.Decode(bytes.NewReader(data))
	if err != nil {
		return fmt.Errorf("decode image: %v", err)
	}

	os.MkdirAll(setting.RepositoryAvatarUploadPath, os.ModePerm)
	fw, err := os.Create(repo.CustomAvatarPath())
	if err != nil {
		return fmt.Errorf("create custom avatar directory: %v", err)
	}
	defer fw.Close()

	m := resize.Resize(avatar.AVATAR_SIZE, avatar.AVATAR_SIZE, img, resize.NearestNeighbor)
	if err = png.Encode(fw, m); err != nil {
		return fmt.Errorf("encode image: %v", err)
	}

	return nil
}
485910
func (p *Provider) UserInfo(ctx context.Context, tokenSource oauth2.TokenSource) (*UserInfo, error) {
	if p.userInfoURL == "" {
		return nil, errors.New("oidc: user info endpoint is not supported by this provider")
	}

	req, err := http.NewRequest("GET", p.userInfoURL, nil)
	if err != nil {
		return nil, fmt.Errorf("oidc: create GET request: %v", err)
	}

	token, err := tokenSource.Token()
	if err != nil {
		return nil, fmt.Errorf("oidc: get access token: %v", err)
	}
	token.SetAuthHeader(req)

	resp, err := doRequest(ctx, req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("%s: %s", resp.Status, body)
	}

	var userInfo UserInfo
	if err := json.Unmarshal(body, &userInfo); err != nil {
		return nil, fmt.Errorf("oidc: failed to decode userinfo: %v", err)
	}
	userInfo.claims = body
	return &userInfo, nil
}
185
func (cli *Client) GetAvatarURL() (url string, err error) {
	urlPath := cli.BuildURL("profile", cli.UserID, "avatar_url")
	s := struct {
		AvatarURL string `json:"avatar_url"`
	}{}

	_, err = cli.MakeRequest("GET", urlPath, nil, &s)
	if err != nil {
		return "", err
	}

	return s.AvatarURL, nil
}
776000
func (sl *Slack) UsersInfo(userId string) (*User, error) {
	uv := sl.urlValues()
	uv.Add("user", userId)

	body, err := sl.GetRequest(usersInfoApiEndpoint, uv)
	if err != nil {
		return nil, err
	}
	res := new(UsersInfoAPIResponse)
	err = json.Unmarshal(body, res)
	if err != nil {
		return nil, err
	}
	if !res.Ok {
		return nil, errors.New(res.Error)
	}
	return res.User, nil
}
140679
func (c *client) UserList() ([]*User, error) {
	var out []*User
	uri := fmt.Sprintf(pathUsers, c.addr)
	err := c.get(uri, &out)
	return out, err
}
683294
func (authy *Authy) UserStatus(id string, params url.Values) (*UserStatus, error) {
	Logger.Println("Finding Authy user with id", id)

	path := fmt.Sprintf("/protected/json/users/%s/status", id)

	response, err := authy.DoRequest("GET", path, params)
	if err != nil {
		return nil, err
	}

	statusResponse, err := NewUserStatus(response)
	return statusResponse, err
}
1199736
func replaceAvatar(w http.ResponseWriter, r *http.Request, oldAvatar *user.Avatar,
	newAvatar *user.Avatar, username string, userMgr *user.Manager) {
	var err error
	// If the old avatar points to a file on itsyou.online, we need to remove the file stored here.
	if strings.HasPrefix(strings.TrimPrefix(oldAvatar.Source, "https://"), r.Host) {
		hash := getAvatarHashFromLink(oldAvatar.Source)
		err = userMgr.RemoveAvatarFile(hash)
		if handleServerError(w, "removing avatar file", err) {
			return
		}
	}

	// now remove the old avatar
	err = userMgr.RemoveAvatar(username, oldAvatar.Label)
	if handleServerError(w, "removing old avatar", err) {
		return
	}

	// insert the new avatar
	err = userMgr.SaveAvatar(username, *newAvatar)
	if handleServerError(w, "saving new avatar", err) {
		return
	}

	w.WriteHeader(http.StatusOK)
	json.NewEncoder(w).Encode(newAvatar)
}
1097743
func InvalidUserIDError(err error) *influxdb.Error {
	return &influxdb.Error{
		Code: influxdb.EInvalid,
		Msg:  "user id provided is invalid",
		Err:  err,
	}
}
970957
func (p *provisioningIdentityMapper) UserFor(info authapi.UserIdentityInfo) (kuser.Info, error) {
	// Retrying up to three times lets us handle race conditions with up to two conflicting identity providers without returning an error
	// * A single race is possible on user creation for every conflicting identity provider
	// * A single race is possible on user creation between two instances of the same provider
	// * A single race is possible on identity creation between two instances of the same provider
	//
	// A race condition between three conflicting identity providers *and* multiple instances of the same identity provider
	// seems like a reasonable situation to return an error (you would get an AlreadyExists error on either the user or the identity)
	return p.userForWithRetries(info, 3)
}
531306
func (api UsersAPI) GetAvatarImage(w http.ResponseWriter, r *http.Request) {
	hash := mux.Vars(r)["hash"]
	userMgr := user.NewManager(r)
	file, err := userMgr.GetAvatarFile(hash)
	if handleServerError(w, "getting avatar file", err) {
		return
	}
	if file == nil {
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}
	w.WriteHeader(http.StatusOK)
	w.Write(file)
}