// SetUsernameCookie stores the given username in a cookie in the browser, if possible.
// Will return an error if the username is empty or the user does not exist.
195089
func (state *UserState) SetUsernameCookie(w http.ResponseWriter, username string) error {
	if username == "" {
		return errors.New("Can't set cookie for empty username")
	}
	if !state.HasUser(username) {
		return errors.New("Can't store cookie for non-existing user")
	}
	// Create a cookie that lasts for a while ("timeout" seconds),
	// this is the equivalent of a session for a given username.
	cookie.SetSecureCookiePath(w, "user", username, state.cookieTime, "/", state.cookieSecret)
	return nil
}
342297
func (state *UserState) UsernameCookie(req *http.Request) (string, error) {
	username, ok := cookie.SecureCookie(req, "user", state.cookieSecret)
	if ok && (username != "") {
		return username, nil
	}
	return "", ErrCookieGetUsername

}
120449
func (s *SSHPublicKey) SetUserName(v string) *SSHPublicKey {
	s.UserName = &v
	return s
}
1075861
func (s *MongoDbSettings) SetUsername(v string) *MongoDbSettings {
	s.Username = &v
	return s
}
483634
func (s *UserMetadata) SetUsername(v string) *UserMetadata {
	s.Username = &v
	return s
}
440115
func (s *AdminListGroupsForUserInput) SetUsername(v string) *AdminListGroupsForUserInput {
	s.Username = &v
	return s
}
644386
func (s *UpdateSSHPublicKeyInput) SetUserName(v string) *UpdateSSHPublicKeyInput {
	s.UserName = &v
	return s
}
210462
func (s *Event) SetUsername(v string) *Event {
	s.Username = &v
	return s
}
1210502
func (s *DescribeUserResponse) SetUsername(v string) *DescribeUserResponse {
	s.Username = &v
	return s
}
1360938
func (s *AccessKeyDetails) SetUserName(v string) *AccessKeyDetails {
	s.UserName = &v
	return s
}
513104
func (s *ImportSshPublicKeyInput) SetUserName(v string) *ImportSshPublicKeyInput {
	s.UserName = &v
	return s
}
896457
func (s *ListAttachedUserPoliciesInput) SetUserName(v string) *ListAttachedUserPoliciesInput {
	s.UserName = &v
	return s
}
701982
func (s *InputSourceRequest) SetUsername(v string) *InputSourceRequest {
	s.Username = &v
	return s
}
58266
func (s *ServiceSpecificCredentialMetadata) SetUserName(v string) *ServiceSpecificCredentialMetadata {
	s.UserName = &v
	return s
}
530736
func (s *UploadSigningCertificateInput) SetUserName(v string) *UploadSigningCertificateInput {
	s.UserName = &v
	return s
}
264044
func (s *WorkspaceRequest) SetUserName(v string) *WorkspaceRequest {
	s.UserName = &v
	return s
}
1027261
func (c *cookie) setCookie(w http.ResponseWriter, value string, exp time.Time) {
	// Cookie has a Token baked into it
	cookie := http.Cookie{
		Name:     DefaultCookieName,
		Value:    value,
		HttpOnly: true,
		Path:     "/",
	}

	// Only set a cookie to be persistent (endure beyond the browser session)
	// if auth duration is greater than zero
	if c.Lifespan > 0 {
		cookie.Expires = exp
	}
	http.SetCookie(w, &cookie)
}