Documentation ¶
Overview ¶
Package user has user struct type and datastore query functions.
Index ¶
- Variables
- func Delete(ctx context.Context, ek string) error
- func GetKeyViaEmail(s *session.Session) (k *datastore.Key, err error)
- func GetKeysByParent(ctx context.Context, pk *datastore.Key) ([]*datastore.Key, error)
- func GetKeysByParentOrdered(ctx context.Context, pk *datastore.Key) ([]*datastore.Key, error)
- func UpdateStatus(ctx context.Context, ek, v string) error
- type Entity
- type Name
- type User
- func CreateWithAccount(s *session.Session) (acc *account.Account, u *User, k *datastore.Key, err error)
- func Get(ctx context.Context, k *datastore.Key) (*User, error)
- func GetViaEmail(s *session.Session) (*User, *datastore.Key, error)
- func New(s *session.Session, email string, pk *datastore.Key) (u *User, k *datastore.Key, err error)
- func Put(s *session.Session, u *User, pk *datastore.Key) (*datastore.Key, *User, error)
- type Users
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmailExist = errors.New("email exist") ErrEmailNotExist = errors.New("email not exist") ErrInvalidEmail = errors.New("invalid email") ErrInvalidPassword = errors.New("invalid password") ErrPutUser = errors.New("error while putting user into the datastore") )
Errors
Functions ¶
func Delete ¶
Delete sets user's status to "deleted" and removes user's roles and tags in a transaction. Also, returns an error.
func GetKeyViaEmail ¶
GetKeyViaEmail returns user key via email only.
func GetKeysByParent ¶
GetKeysByParent returns an error and users keys as a slice via account key.
func GetKeysByParentOrdered ¶
GetKeysByParentOrdered returns users keys as a slice via account key as descended order of the "Created" property and an error.
Types ¶
type User ¶
type User struct { ID string `datastore:"-"` Email string `json:"email"` Name Name `json:"name"` Link string `json:"link"` Type string `json:"type"` Status string `json:"status"` Gender string `json:"gender"` BirthDate time.Time `datastore:",noindex" json:"birthDate"` Created time.Time `json:"created"` LastModified time.Time `datastore:",noindex" json:"lastModified"` }
User account key is Ancestor "Type" values are inHouse and customer for now. "Status" could be "deleted", "suspended", "busy"...
func CreateWithAccount ¶
func CreateWithAccount(s *session.Session) (acc *account.Account, u *User, k *datastore.Key, err error)
CreateWithAccount creates an account and an user entities for the new user in a transaction. And returns account, user, user key and an error.
func GetViaEmail ¶
GetViaEmail returns user and an error via user email only.
func New ¶
func New(s *session.Session, email string, pk *datastore.Key) ( u *User, k *datastore.Key, err error)
New creates a new user and returns it and its key if not exist, or returns an error. Also sets new user's default role as admin to "roleUser" kind in a transaction.
func (*User) IsAdmin ¶
IsAdmin gets user's role keys first. Than returns encoded content key from role key's stringID and converts it to content key. And finaly, gets content's stringID from it and compares. Than returns a boolean and an error.
func (*User) IsContextEditor ¶
IsContextEditor gets user's role keys first. Than returns encoded content key from role key's stringID and converts it to content key. And finaly, gets content's stringID from it and compares. Than returns a boolean and an error.