user

package
v0.0.0-...-ac733a0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2017 License: AGPL-3.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DatasetExists

func DatasetExists(db sqlutil.Queryable, datasetId string) (exists bool, err error)

check if dataset exists in a given dataset

func EmailTaken

func EmailTaken(db sqlutil.Queryable, email string) (taken bool, err error)

check if an email is taken

func PathTaken

func PathTaken(db sqlutil.Queryable, path string) (taken bool, err error)

check if a dataset path is taken

func UsernameTaken

func UsernameTaken(db sqlutil.Queryable, username string) (taken bool, err error)

check if a username is taken, also checking against organization namespace to avoid collisions TODO - refactor to only return an error if taken

func ValidUrlString

func ValidUrlString(rawurl string) (string, error)

ValidUrlString adds

func ValidUser

func ValidUser(db sqlutil.Queryable, u *User) (err error)

check if a user exists on a given database

Types

type Key

type Key struct {
	Type     string
	Sha256   [32]byte
	Created  int64
	LastSeen int64
	Name     string
	User     *User
	Public   []byte
	// contains filtered or unexported fields
}

func CreateKey

func CreateKey(db sqlutil.Execable, u *User, name string, publicKey []byte) (*Key, error)

func NewKey

func NewKey(name string, u *User) (*Key, error)

func (*Key) Delete

func (key *Key) Delete(db sqlutil.Execable) error

"delete" a user_key

func (*Key) MarshalJSON

func (key *Key) MarshalJSON() ([]byte, error)

func (*Key) Read

func (key *Key) Read(db sqlutil.Queryable) error

func (*Key) Save

func (k *Key) Save(db sqlutil.Execable) error

func (*Key) UnmarshalSQL

func (key *Key) UnmarshalSQL(row sqlutil.Scannable) error

turn an sql row from the user table into a user struct pointer

type User

type User struct {
	// version 4 uuid
	Id string `json:"id" sql:"id"`
	// Created timestamp rounded to seconds in UTC
	Created int64 `json:"created" sql:"created"`
	// Updated timestamp rounded to seconds in UTC
	Updated int64 `json:"updated" sql:"updated"`
	// handle for the user. min 1 character, max 80. composed of [_,-,a-z,A-Z,1-9]
	Username string `json:"username" sql:"username"`
	// specifies weather this is a user or an organization
	Type UserType `json:"type" sql:"type"`

	// user's email address
	Email string `json:"email,omitempty" sql:"email"`
	// user name field. could be first[space]last, but not strictly enforced
	Name string `json:"name" sql:"name"`
	// user-filled description of self
	Description string `json:"description" sql:"description"`
	// url this user wants the world to click
	HomeUrl string `json:"home_url" sql:"home_url"`
	// color this user likes to use as their theme color
	Color string `json:"color"`
	// url for their thumbnail
	ThumbUrl string `json:"thumbUrl"`
	// profile photo url
	ProfileUrl string `json:"profileUrl"`
	// header image url
	PosterUrl string `json:"posterUrl"`
	// sh256 multihash of public key that this user is currently using for signatures
	CurrentKey string `json:"currentKey"`

	// often users get auto-generated based on IP for rate lmiting & stuff
	// this flag tracks that.
	// TODO - for this to be useful it'll need to be Exported
	Anonymous bool `json:",omitempty"`
	// contains filtered or unexported fields
}

le user

func AuthenticateUser

func AuthenticateUser(db sqlutil.Queryable, username, password string) (u *User, err error)

attempt to authenticate a user, for now only returns either nil or errors.ErrAccessDenied TODO - should also return 500-type errors when service is down

func CommunityUsers

func CommunityUsers(db sqlutil.Queryable, community *User, order string, limit, offset int) ([]*User, error)

func CreateUser

func CreateUser(db sqlutil.Transactable, username, email, name, password string, t UserType) (u *User, err error)

create a new user from a given username, email, first, last, and password This is just a wrapper to turn args into a user & then call save, returning the user & error, But should be used to create users in case we want to inject analytics or whatever.

func NewAccessTokenUser

func NewAccessTokenUser(token string) *User

func NewUser

func NewUser(id string) *User

create a new user struct pointer from a provided id string

func NewUserFromString

func NewUserFromString(s string) *User

NewUserFromFromString attempts to place the provided string in the right field. id if it's a valid uuid, username if it's a valid username, or throwing away the string if none of the above apply

func ReadUsers

func ReadUsers(db sqlutil.Queryable, userType UserType, limit, offset int) (users []*User, err error)

ReadUsers reads a page of users

func UserCommunities

func UserCommunities(db sqlutil.Queryable, user *User, order string, limit, offset int) ([]*User, error)

func UserForPublicKey

func UserForPublicKey(db sqlutil.Queryable, pubKey ssh.PublicKey) (*User, error)

UserForPublicKey finds a user based on a provided public key

func UsersSearch

func UsersSearch(db sqlutil.Queryable, query string, limit, offset int) ([]*User, error)

func (*User) AcceptCommunityInvite

func (u *User) AcceptCommunityInvite(db *sql.DB, c *User) error

func (*User) AccessToken

func (u *User) AccessToken() string

func (*User) DeclineCommunityInvite

func (u *User) DeclineCommunityInvite(db *sql.DB, c *User) error

func (*User) Delete

func (u *User) Delete(db sqlutil.Transactable) error

"delete" a user TODO - deleting an account will require lots of cleanup:

  • Close any open change requests
  • Resolve any datasets that the user is the sole administrator of

func (*User) Keys

func (u *User) Keys(db *sql.DB) ([]*Key, error)

TODO

func (User) MarshalJSON

func (u User) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON implementation that delivers a uuid-string if the model is blank, or an object otherwise

func (*User) Path

func (u *User) Path() string

return url endpoint path to user. basically: /:username

func (*User) Read

func (u *User) Read(db sqlutil.Queryable) error

load the given user from the database based on id, username, or email

func (*User) ReadApiToken

func (u *User) ReadApiToken(db sqlutil.Queryable) error

func (*User) Save

func (u *User) Save(db sqlutil.Transactable) error

save a user model, creating it if it doesn't exist updating the user model if it doesn't

func (*User) SavePassword

func (u *User) SavePassword(db sqlutil.Execable, password string) error

SavePassword sets a user's password

func (*User) SetCurrentKey

func (u *User) SetCurrentKey(db sqlutil.Execable, key [32]byte) error

func (*User) Slug

func (u *User) Slug() string

just the username

func (*User) UnmarshalJSON

func (u *User) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom json implementation that supports a few different inputs if a string is provided, it first checks if the string is a valid uuid, if so it'll set the string to the id. If not it'll check to see if the passed-in string is a valid username and if so it'll set the user's username accordingly. if an object is passed in we skip straight to regular json unmarshalling

func (*User) UnmarshalSQL

func (u *User) UnmarshalSQL(row sqlutil.Scannable) error

turn an sql row from the user table into a user struct pointer

type UserRequests

type UserRequests struct {
	Store sqlutil.Transactable
}

Requests holds all types of requests for users

func (UserRequests) CommunityMembers

func (r UserRequests) CommunityMembers(p *UsersCommunityMembersParams, res *[]*User) error

func (UserRequests) Create

func (r UserRequests) Create(p *UsersCreateParams, res *User) error

func (UserRequests) Get

func (r UserRequests) Get(p *UsersGetParams, res *User) error

func (UserRequests) List

func (r UserRequests) List(p *UsersListParams, res *[]*User) error

func (UserRequests) Save

func (r UserRequests) Save(p *UsersSaveParams, res *User) error

func (UserRequests) Search

func (r UserRequests) Search(p *UsersSearchParams, res *[]*User) error

func (UserRequests) UserCommunities

func (r UserRequests) UserCommunities(p *UsersCommunitiesParams, res *[]*User) error

type UserType

type UserType int
const (
	UserTypeNone UserType = iota
	UserTypeUser
	UserTypeCommunity
)

func (UserType) MarshalJSON

func (ut UserType) MarshalJSON() ([]byte, error)

func (UserType) String

func (ut UserType) String() string

func (*UserType) UnmarshalJSON

func (ut *UserType) UnmarshalJSON(data []byte) error

type UsersCommunitiesParams

type UsersCommunitiesParams struct {
	User   *User
	Order  string
	Limit  int
	Offset int
}

type UsersCommunityMembersParams

type UsersCommunityMembersParams struct {
	User      *User
	Community *User
	Order     string
	Limit     int
	Offset    int
}

type UsersCreateParams

type UsersCreateParams struct {
	User     *User
	Password string
}

type UsersGetParams

type UsersGetParams struct {
	User    *User
	Subject *User
}

type UsersListParams

type UsersListParams struct {
	// the user performing the request
	User *User `required:"true"`
	Type UserType
	// users requests embeds pagination info
	Limit  int
	Offset int
}

UsersRequest defines a request for users, outlining all possible options for scoping & shaping the desired response

type UsersSaveParams

type UsersSaveParams struct {
	User    *User
	Subject *User
}

type UsersSearchParams

type UsersSearchParams struct {
	User   *User
	Query  string
	Limit  int
	Offset int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL