user

package
v0.0.0-...-0e3259e Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2020 License: MIT Imports: 10 Imported by: 7

Documentation

Overview

Package user has user struct type and datastore query functions.

Index

Constants

This section is empty.

Variables

View Source
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

func Delete(ctx context.Context, ek string) error

Delete sets user's status to "deleted" and removes user's roles and tags in a transaction. Also, returns an error.

func GetKeyViaEmail

func GetKeyViaEmail(s *session.Session) (k *datastore.Key, err error)

GetKeyViaEmail returns user key via email only.

func GetKeysByParent

func GetKeysByParent(ctx context.Context, pk *datastore.Key) ([]*datastore.Key, error)

GetKeysByParent returns an error and users keys as a slice via account key.

func GetKeysByParentOrdered

func GetKeysByParentOrdered(ctx context.Context, pk *datastore.Key) ([]*datastore.Key, error)

GetKeysByParentOrdered returns users keys as a slice via account key as descended order of the "Created" property and an error.

func UpdateStatus

func UpdateStatus(ctx context.Context, ek, v string) error

UpdateStatus set's user status to given value "v" by given encoded user key "ek" and returns an error.

Types

type Entity

type Entity interface {
}

Entity interface to implement all structs i guess.

type Name

type Name struct {
	First string `json:"first"`
	Last  string `json:"last"`
}

Name is user name struct with "First" and "Last" fields.

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 Get

func Get(ctx context.Context, k *datastore.Key) (*User, error)

Get returns the entity and an error via entity's key.

func GetViaEmail

func GetViaEmail(s *session.Session) (*User, *datastore.Key, error)

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 Put

func Put(s *session.Session, u *User, pk *datastore.Key) (*datastore.Key, *User, error)

Put adds to or modifies an entity in the kind according to existance.

func (*User) IsAdmin

func (u *User) IsAdmin(ctx context.Context) (bool, error)

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

func (u *User) IsContextEditor(ctx context.Context) (bool, error)

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.

type Users

type Users map[string]*User

Users is a users map with encoded user key as map key.

func GetProjected

func GetProjected(ctx context.Context, pk *datastore.Key) (Users, error)

GetProjected returns thumbnail enough properties via account key and an error.

Jump to

Keyboard shortcuts

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