// UserPostUserLock: implementing Lock interface
// Sender returns the User that casted the lock
973340
func (lock *UserPostUserLock) Sender() (user *User) {
	user, _ = NewUser(lock.From)
	return
}
1017871
func (v *CredentialAuthority) makeUser(uid keybase1.UID) *user {
	uw := v.users[uid]
	if uw == nil {
		u := newUser(uid, v)
		uw = &userWrapper{u: u}
		v.users[uid] = uw
	}
	uw.atime = v.eng.Now()
	return uw.u
}
970416
func (lurk *ProjectPostLurk) Sender() (user *User) {
	user, _ = NewUser(lurk.From)
	return
}
590456
func (r *usersResource) updateUser(request *restful.Request, response *restful.Response, user schema.User) (error, interface{}) {
	var req userReq
	if err := request.ReadEntity(&req); err != nil {
		return err, nil
	}
	u, err := r.users.UpdateUserByEmail(req.Email, req.Fullname)
	if err == nil {
		msg := events.Message{
			// piggy back on addeduser since the client will figure out
			// duplicates and updates.
			Event: "addeduser",
			Data:  u,
		}
		r.hub.Broadcast(msg)
	}
	return err, u
}
324327
func (u *UserService) updateUser(request *restful.Request, response *restful.Response) {
	c := appengine.NewContext(request.Request)
	usr := new(User)
	err := request.ReadEntity(&usr)
	if err == nil {
		item := &memcache.Item{
			Key:    usr.Id,
			Object: &usr,
		}
		err = memcache.Gob.Set(c, item)
		if err != nil {
			response.WriteError(http.StatusInternalServerError, err)
			return
		}
		response.WriteEntity(usr)
	} else {
		response.WriteError(http.StatusInternalServerError, err)
	}
}
822513
func CheckUser(username, sid string, ss, pk []byte) (res bool, err error) {
	var (
		buf  *bytes.Buffer
		resp *http.Response
	)

	buf = bytes.NewBufferString(sid)
	buf.Write(ss)
	buf.Write(pk)

	var url = fmt.Sprintf(BaseUrl, username, AuthDigest(buf.Bytes()))
	resp, err = http.Get(url)
	if err != nil {
		return false, fmt.Errorf("GET: %v", err)
	}

	if resp.StatusCode != 200 {
		return false, fmt.Errorf("Bad responde code '%d'.", resp.StatusCode)
	}

	// Copy response body to empty buffer
	buf.Reset()
	_, err = io.Copy(buf, resp.Body)
	if err != nil {
		return false, fmt.Errorf("Couldn't read response body: %v", err)
	}
	resp.Body.Close()

	return string(buf.Bytes()) == "YES", nil
}
363509
func (u *User) Send(message string) {
	textMessage := TextMessage{
		Users:   []*User{u},
		Message: message,
	}
	u.client.Send(&textMessage)
}
476498
func (e *TermsRequiredError) UserErr() error {
	terms := strings.Join(e.Terms, " ")
	return errors.Wrap(e,
		errors.Errorf(`Declined: some terms require agreement. Try: "juju agree %s"`, terms))
}
714631
func (c *githubConnector) user(ctx context.Context, client *http.Client) (user, error) {
	// https://developer.github.com/v3/users/#get-the-authenticated-user
	var u user
	if _, err := get(ctx, client, c.apiURL+"/user", &u); err != nil {
		return u, err
	}

	// Only public user emails are returned by 'GET /user'. u.Email will be empty
	// if a users' email is private. We must retrieve private emails explicitly.
	if u.Email == "" {
		var err error
		if u.Email, err = c.userEmail(ctx, client); err != nil {
			return u, err
		}
	}
	return u, nil
}
1353799
func (comment *ProjectPostComment) Sender() *User {
	user, _ := NewUser(comment.NumericSender())
	return user
}
1308675
func (post *ProjectPost) Locks() *[]Lock {
	ret := []ProjectPostLock{}
	Db().Model(ProjectPostLock{}).Where(&ProjectPostLock{Hpid: post.ID()}).Scan(&ret)
	var retLockers []Lock
	for _, l := range ret {
		locker := l
		retLockers = append(retLockers, Lock(&locker))
	}

	return &retLockers
}
20691
func (peer *respPeer) sender() {
	for {
		m := <-peer.q
		if m == nil {
			break
		}
		if peer.ep.SendMsg(m) != nil {
			m.Free()
			break
		}
	}
}
773416
func User(
	scanner reddit.Scanner,
	kill <-chan bool,
	errs chan<- error,
	user string,
) (
	<-chan *reddit.Post,
	<-chan *reddit.Comment,
	error,
) {
	path := "/u/" + user
	posts, comments, _, err := streamFromPath(scanner, kill, errs, path)
	return posts, comments, err
}
242879
func NewPostLock() echo.HandlerFunc {

	// swagger:route POST /me/posts/{pid}/locks me post vote NewMePostLock
	//
	// Adds a new lock on the current post
	//
	// Consumes:
	// - application/json
	//
	//	Produces:
	//	- application/json
	//
	//	Security:
	//		oauth: profile_messages:write
	//
	//	Responses:
	//		default: MePostsPidLocks

	return func(c echo.Context) error {
		return user.NewPostLock()(c)
	}
}
933524
func (e *Editor) User(username string, password string) *Editor {
	e.config.Username = username
	e.config.Password = password
	return e
}
915486
func (s *UserService) CreateUser(ctx context.Context, u *platform.User) error {
	url, err := newURL(s.Addr, usersPath)
	if err != nil {
		return err
	}

	octets, err := json.Marshal(u)
	if err != nil {
		return err
	}

	req, err := http.NewRequest("POST", url.String(), bytes.NewReader(octets))
	if err != nil {
		return err
	}

	req.Header.Set("Content-Type", "application/json")
	SetToken(s.Token, req)

	hc := newClient(url.Scheme, s.InsecureSkipVerify)

	resp, err := hc.Do(req)
	if err != nil {
		return err
	}

	// TODO(jsternberg): Should this check for a 201 explicitly?
	if err := CheckError(resp, true); err != nil {
		return err
	}

	if err := json.NewDecoder(resp.Body).Decode(u); err != nil {
		return err
	}

	return nil
}
451019
func NewUserHandler() *UserHandler {
	h := &UserHandler{
		Router: NewRouter(),
	}

	h.HandlerFunc("POST", usersPath, h.handlePostUser)
	h.HandlerFunc("GET", usersPath, h.handleGetUsers)
	h.HandlerFunc("GET", usersIDPath, h.handleGetUser)
	h.HandlerFunc("GET", usersLogPath, h.handleGetUserLog)
	h.HandlerFunc("PATCH", usersIDPath, h.handlePatchUser)
	h.HandlerFunc("DELETE", usersIDPath, h.handleDeleteUser)
	h.HandlerFunc("PUT", usersPasswordPath, h.handlePutUserPassword)

	h.HandlerFunc("GET", mePath, h.handleGetMe)
	h.HandlerFunc("PUT", mePasswordPath, h.handlePutUserPassword)

	return h
}