// NewUserWhere returns the first user that matches the description
517099
func NewUserWhere(description *User) (user *User, e error) {
	user = new(User)
	if e = Db().Where(description).Scan(user); e != nil {
		return
	}

	if e = Db().First(&user.Profile, user.ID()); e != nil {
		return
	}

	return
}
471981
func (us *unionStatementImpl) AndWhere(expression BoolExpression) UnionStatement {
	if us.where == nil {
		return us.Where(expression)
	}
	us.where = And(us.where, expression)
	return us
}
1040825
func UserHomeDir() string {
	// user.Current() returns nil if cross-compiled e.g. on mac for linux
	if usr, _ := user.Current(); usr != nil {
		return usr.HomeDir
	}
	return os.Getenv("HOME")
}
887458
func NewContextWithUser(ctx context.Context, user *User) context.Context {
	return context.WithValue(ctx, userContextKey, user)
}
305030
func NewUserInfoByName(name string) (t *Tieba, err error) {
	resp, err := requester.DefaultClient.Req("GET", "http://tieba.baidu.com/home/get/panel?un="+name, nil, nil)
	if err != nil {
		return nil, err
	}

	defer resp.Body.Close()

	json, err := simplejson.NewFromReader(resp.Body)
	if err != nil {
		return nil, err
	}

	return NewUserInfoByUID(json.GetPath("data", "id").MustUint64())
}
591122
func NewUserPost(hpid uint64) (*UserPost, error) {
	return NewUserPostWhere(&UserPost{Post{Hpid: hpid}})
}
547783
func NewUserInfo(AccountId string, Email string, DisplayName string, SameTeam bool) *UserInfo {
	s := new(UserInfo)
	s.AccountId = AccountId
	s.Email = Email
	s.DisplayName = DisplayName
	s.SameTeam = SameTeam
	return s
}
1168214
func NewMembersSetProfileArg(User *UserSelectorArg) *MembersSetProfileArg {
	s := new(MembersSetProfileArg)
	s.User = User
	return s
}
623350
func WithUser(parent Context, user user.Info) Context {
	return WithValue(parent, userKey, user)
}
144134
func AuthorizedWhere(a Authorizer) func(DocumentIndex, DocumentDecorator) ([]ID, error) {
	switch t := a.(type) {
	case *Authorization:
		return TokenAuthorizedWhere(t)
	}

	var ids []ID
	return func(idx DocumentIndex, _ DocumentDecorator) ([]ID, error) {
		dids, err := idx.GetAccessorsDocuments("user", a.GetUserID())
		if err != nil {
			return nil, err
		}

		ids = append(ids, dids...)

		orgIDs, err := idx.UsersOrgs(a.GetUserID())
		if err != nil {
			return nil, err
		}

		for _, orgID := range orgIDs {
			dids, err := idx.GetAccessorsDocuments("org", orgID)
			if err != nil {
				return nil, err
			}

			ids = append(ids, dids...)
		}

		// TODO(desa): we should probably dedupe this list eventually.
		return ids, nil
	}
}
1059840
func (u Util) userLookup(name string) (*user.User, error) {
	res := &C.lookup_res_t{}

	if ret, err := C.user_lookup(C.CString(u.DestDir),
		C.CString(name), res); ret < 0 {
		return nil, fmt.Errorf("lookup failed: %v", err)
	}

	if res.name == nil {
		return nil, fmt.Errorf("user %q not found", name)
	}

	homedir, err := u.JoinPath(C.GoString(res.home))
	if err != nil {
		return nil, err
	}

	usr := &user.User{
		Name:    C.GoString(res.name),
		Uid:     fmt.Sprintf("%d", int(res.uid)),
		Gid:     fmt.Sprintf("%d", int(res.gid)),
		HomeDir: homedir,
	}

	C.user_lookup_res_free(res)

	return usr, nil
}
44488
func userHomeDir() string {
	if runtime.GOOS == "windows" {
		home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
		if home == "" {
			home = os.Getenv("USERPROFILE")
		}
		return home
	}
	return os.Getenv("HOME")
}
492937
func (s *UserService) CreateUser(ctx context.Context, User *platform.User) error {
	return s.CreateUserFn(ctx, User)
}
542902
func (row *Row) GetWhere(driver string, i int) string {
	wheres := make([]string, len(row.PK))
	j := i
	for _, c := range row.pkColumns {
		if driver == postgresDriver {
			wheres[i-j] = fmt.Sprintf("%s = $%d", c, i+1)
		} else {
			wheres[i-j] = fmt.Sprintf("%s = ?", c)
		}
		i++
	}
	return strings.Join(wheres, " AND ")
}
481389
func newLoginLoadUser(g *libkb.GlobalContext, username string) *loginLoadUser {
	return &loginLoadUser{
		Contextified: libkb.NewContextified(g),
		username:     strings.TrimSpace(username),
	}
}
492792
func NewListUsersOnPaperDocResponse(Invitees []*InviteeInfoWithPermissionLevel, Users []*UserInfoWithPermissionLevel, DocOwner *sharing.UserInfo, Cursor *Cursor, HasMore bool) *ListUsersOnPaperDocResponse {
	s := new(ListUsersOnPaperDocResponse)
	s.Invitees = Invitees
	s.Users = Users
	s.DocOwner = DocOwner
	s.Cursor = Cursor
	s.HasMore = HasMore
	return s
}
271130
func (a *API) CreateUser(user *User) (*User, error) {
	dst := new(User)
	url := a.BuildURL("/v2/user")
	err := a.Post(url, Params{}, user, dst)
	return dst, err
}