// OnlineUserNum 获取在线人数
// 如果流不是在线状态，返回0
// -------------------------------------------------------------------------------
430996
func (s *Stream) OnlineUserNum() (num int64) {
	resp := OnlineInfoResponse{}
	s.live.StreamOnlineUserNum(s.StreamName, &resp)
	num = resp.TotalUserNumber
	return
}
1312932
func (u UserResource) findUser(request *restful.Request, response *restful.Response) {
	id := request.PathParameter("user-id")
	usr := u.users[id]
	if len(usr.Id) == 0 {
		response.AddHeader("Content-Type", "text/plain")
		response.WriteErrorString(http.StatusNotFound, "User could not be found.")
	} else {
		response.WriteEntity(usr)
	}
}
47617
func (api OrganizationsAPI) UserIsMember(w http.ResponseWriter, r *http.Request) {
	globalID := mux.Vars(r)["globalid"]
	username := mux.Vars(r)["username"]

	var isMember bool

	user, err := SearchUser(r, username)
	if db.IsNotFound(err) {
		user = nil
	} else if handleServerError(w, "getting user from database", err) {
		return
	}

	if user != nil {
		orgMgr := organization.NewManager(r)
		inOrgs, err := orgMgr.IsInOrgs(username, globalID)
		if handleServerError(w, "checking if user is in organization", err) {
			return
		}
		isMember = len(inOrgs) > 0 && inOrgs[0] == globalID
	}

	response := struct {
		IsMember bool
	}{
		IsMember: isMember,
	}
	w.WriteHeader(http.StatusOK)
	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(&response)
}
135321
func User(userID string, c echo.Context) (*nerdz.User, error) {
	var id uint64
	var e error
	if id, e = strconv.ParseUint(c.Param(userID), 10, 64); e != nil {
		c.JSON(http.StatusBadRequest, &Response{
			HumanMessage: "Invalid user identifier specified",
			Message:      e.Error(),
			Status:       http.StatusBadRequest,
			Success:      false,
		})
		return nil, e
	}

	var user *nerdz.User
	if user, e = nerdz.NewUser(id); e != nil {
		c.JSON(http.StatusBadRequest, &Response{
			HumanMessage: "User does not exists",
			Message:      e.Error(),
			Status:       http.StatusBadRequest,
			Success:      false,
		})
		return nil, e
	}

	me := c.Get("me").(*nerdz.User)
	if !me.CanSee(user) {
		message := "You can't see the required profile"
		c.JSON(http.StatusUnauthorized, &Response{
			HumanMessage: message,
			Message:      message,
			Status:       http.StatusUnauthorized,
			Success:      false,
		})
		return nil, errors.New(message)
	}
	return user, nil
}
127459
func (conn *Conn) User(ident, name string) {
	conn.Raw(USER + " " + ident + " 12 * :" + name)
}
742927
func (api *Client) GetUserInfo(user string) (*User, error) {
	return api.GetUserInfoContext(context.Background(), user)
}
1202145
func (app *App) UserData() string {
	return UserDataDir(app.Name, app.Author, app.Version, app.Roaming)
}
80620
func (api *API) UserDetails() (User, error) {
	var r UserResponse
	res, err := api.makeRequest("GET", "/user", nil)
	if err != nil {
		return User{}, errors.Wrap(err, errMakeRequestError)
	}

	err = json.Unmarshal(res, &r)
	if err != nil {
		return User{}, errors.Wrap(err, errUnmarshalError)
	}

	return r.Result, nil
}
1057147
func (api UsersAPI) GetUserPhoneNumbers(w http.ResponseWriter, r *http.Request) {
	username := mux.Vars(r)["username"]
	validated := strings.Contains(r.URL.RawQuery, "validated")
	userMgr := user.NewManager(r)

	userobj, err := userMgr.GetByName(username)
	if err != nil {
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
		return
	}
	var phonenumbers []user.Phonenumber
	if validated {
		phonenumbers = make([]user.Phonenumber, 0)
		valMngr := validationdb.NewManager(r)
		validatednumbers, err := valMngr.GetByUsernameValidatedPhonenumbers(username)
		if err != nil {
			log.Error(err)
			http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
			return
		}
		for _, number := range userobj.Phonenumbers {
			for _, validatednumber := range validatednumbers {
				if number.Phonenumber == validatednumber.Phonenumber {
					phonenumbers = append(phonenumbers, number)
					break
				}
			}
		}
	} else {
		phonenumbers = userobj.Phonenumbers
	}

	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(phonenumbers)
}
447051
func (c oauthClient) User() (wl.User, error) {
	url := fmt.Sprintf(
		"%s/user",
		c.apiURL,
	)

	req, err := c.newGetRequest(url)
	if err != nil {
		return wl.User{}, err
	}

	resp, err := c.do(req)
	if err != nil {
		return wl.User{}, err
	}

	if resp.StatusCode != http.StatusOK {
		return wl.User{}, fmt.Errorf("Unexpected response code %d - expected %d", resp.StatusCode, http.StatusOK)
	}

	if resp.Body == nil {
		return wl.User{}, errors.New("Nil body returned")
	}

	user := wl.User{}
	err = json.NewDecoder(resp.Body).Decode(&user)
	if err != nil {
		return wl.User{}, err
	}

	return user, nil
}
851972
func (s *UserService) GetUserByID(id string, opts ...OptionFunc) (*User, int, error) {
	p := &ListUsersParams{}
	p.p = make(map[string]interface{})

	p.p["id"] = id

	for _, fn := range append(s.cs.options, opts...) {
		if err := fn(s.cs, p); err != nil {
			return nil, -1, err
		}
	}

	l, err := s.ListUsers(p)
	if err != nil {
		if strings.Contains(err.Error(), fmt.Sprintf(
			"Invalid parameter id value=%s due to incorrect long value format, "+
				"or entity does not exist", id)) {
			return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
		}
		return nil, -1, err
	}

	if l.Count == 0 {
		return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
	}

	if l.Count == 1 {
		return l.Users[0], l.Count, nil
	}
	return nil, l.Count, fmt.Errorf("There is more then one result for User UUID: %s!", id)
}
1241220
func (w *WebHookAuthor) GetUsername() string {
	if w == nil || w.Username == nil {
		return ""
	}
	return *w.Username
}
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
}
619444
func (f *JSONConfigFile) GetUserConfigForUsername(nu NormalizedUsername) (*UserConfig, error) {
	if uc := f.copyUserConfigIfForUsername(nu); uc != nil {
		return uc, nil
	}
	return ImportUserConfigFromJSONWrapper(f.jw.AtKey("users").AtKey(nu.String()))
}
1307850
func CheckUsername(s string) bool {
	return len(s) >= 2 && len(s) <= 16 && usernameRE.MatchString(s)
}
553153
func (api *API) GetUser(user_id string) (*User, error) {
	result := new(User)
	url := createUrl(api, userPathSegment, user_id)
	err := api.Client.Get(url, &result, http.StatusOK)
	if err != nil {
		return nil, err
	}
	result.api = api
	return result, nil
}
1036487
func (l *Live) DescribeLiveStreamHistoryUserNum(streamName string, startTime, endTime time.Time, resp interface{}) (err error) {
	req := l.cloneRequest(DescribeLiveStreamHistoryUserNumAction)
	req.SetArgs("StreamName", streamName)
	req.SetArgs("StartTime", util.GetISO8601TimeStamp(startTime))
	req.SetArgs("EndTime", util.GetISO8601TimeStamp(endTime))
	err = l.rpc.Query(req, resp)
	return
}