auth

package
v0.0.0-...-ed9fe1d Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const AuthKindLoggerKey = "ent.auth"

AuthKindLoggerKey is a logger key name for the ent

View Source
const AuthQueryLoggerKey = "ent.query.auth"

AuthQueryLoggerKey is a logger key name for the ent

Variables

View Source
var DefaultAuthKind = &AuthKind{}

DefaultAuthKind is a default value of *AuthKind

View Source
var ErrNoSession = fmt.Errorf("no session is available in the context")
View Source
var Guest = &Auth{
	ID:          "guest",
	FacebookID:  "guest",
	MessengerID: "guest",
	TwitterID:   "guest",
	Email:       "",
	AuthType:    AuthTypeNone,
	CreatedAt:   time.Time{},
	LastLoginAt: time.Time{},
	UpdatedAt:   time.Time{},
}

Guest is a unauthorized value.

Functions

func Delete

func Delete(s *session.Session) error

Delete is to delete the auth from the session

func DeleteCurrent

func DeleteCurrent(ctx context.Context) error

DeleteCurrent is to delete the auth fron the current session

func Set

func Set(s *session.Session, a *Auth) error

Set is to set the auth into the session.

func SetCurrent

func SetCurrent(ctx context.Context, a *Auth) error

SetCurrent it to set the auth into the current session

Types

type Auth

type Auth struct {
	ID          string    `json:"id" ent:"id"`
	FacebookID  string    `json:"facebook_id"`
	MessengerID string    `json:"messenger_id"`
	TwitterID   string    `json:"twitter_id"`
	Email       string    `json:"email"`
	AuthType    AuthType  `json:"auth_type"`
	IsAdmin     bool      `json:"is_admin"`
	CreatedAt   time.Time `json:"created_at"`
	LastLoginAt time.Time `json:"last_login_at"`
	UpdatedAt   time.Time `json:"updated_at" ent:"timestamp"`
}

Auth is a primary type to represent a user

func Facebook

func Facebook(ctx context.Context, client *http.Client, token string) (*Auth, error)

Facebook process authorization by the given access token

func Get

func Get(s *session.Session) (*Auth, error)

Get is to get the auth from the session

func GetCurrent

func GetCurrent(ctx context.Context) (*Auth, error)

GetCurrent is to get the auth fron the current session

func Messenger

func Messenger(ctx context.Context, messengerID string) (*Auth, error)

Messenger process authorization by the given access token

func NewAuth

func NewAuth() *Auth

NewAuth returns a new *Auth with default field values.

func (*Auth) IsGuest

func (a *Auth) IsGuest() bool

IsGuest returns a *Auth is guest auth or not.

func (*Auth) NewKey

func (a *Auth) NewKey(ctx context.Context) *datastore.Key

func (*Auth) UpdateByForm

func (a *Auth) UpdateByForm(form *keyvalue.GetProxy)

UpdateByForm updates the fields by form values. All values should be validated before calling this function.

type AuthKind

type AuthKind struct {
	// contains filtered or unexported fields
}

func (*AuthKind) Delete

func (k *AuthKind) Delete(ctx context.Context, key interface{}) (*datastore.Key, error)

Delete deletes the entity from datastore

func (*AuthKind) DeleteMatched

func (k *AuthKind) DeleteMatched(ctx context.Context, q *AuthQuery) (int, error)

DeleteMatched deletes the all ents that match with the query. This func modify Limit/StartKey condition in the query so that you should restore it if you want to reuse the query.

func (*AuthKind) DeleteMulti

func (k *AuthKind) DeleteMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, error)

DeleteMulti do Delete with multiple keys

func (*AuthKind) EnforceNamespace

func (k *AuthKind) EnforceNamespace(ns string, b bool) *AuthKind

EnforceNamespace enforces namespace for Get/Put/Delete or not.

func (*AuthKind) Get

func (k *AuthKind) Get(ctx context.Context, key interface{}) (*datastore.Key, *Auth, error)

Get gets the kind entity from datastore

func (*AuthKind) GetMulti

func (k *AuthKind) GetMulti(ctx context.Context, keys interface{}) ([]*datastore.Key, []*Auth, error)

GetMulti do Get with multiple keys. keys must be []string, []*datastore.Key, or []interface{}

func (*AuthKind) MustDelete

func (k *AuthKind) MustDelete(ctx context.Context, key interface{}) *datastore.Key

MustDelete is like Delete but panic if an error occurs

func (*AuthKind) MustDeleteMulti

func (k *AuthKind) MustDeleteMulti(ctx context.Context, keys interface{}) []*datastore.Key

MustDeleteMulti is like DeleteMulti but panic if an error occurs

func (*AuthKind) MustGet

func (k *AuthKind) MustGet(ctx context.Context, key interface{}) *Auth

MustGet is like Get but returns only values and panic if error happens.

func (*AuthKind) MustGetMulti

func (k *AuthKind) MustGetMulti(ctx context.Context, keys interface{}) []*Auth

MustGetMulti is like GetMulti but returns only values and panic if error happens.

func (*AuthKind) MustPut

func (k *AuthKind) MustPut(ctx context.Context, ent *Auth) *datastore.Key

MustPut is like Put and panic if an error occurrs.

func (*AuthKind) MustPutMulti

func (k *AuthKind) MustPutMulti(ctx context.Context, ents []*Auth) []*datastore.Key

MustPutMulti is like PutMulti but panic if an error occurs

func (*AuthKind) MustReplace

func (k *AuthKind) MustReplace(ctx context.Context, ent *Auth, replacer AuthKindReplacer) (*datastore.Key, *Auth)

func (*AuthKind) MustReplaceMulti

func (k *AuthKind) MustReplaceMulti(ctx context.Context, ents []*Auth, replacer AuthKindReplacer) ([]*datastore.Key, []*Auth)

func (*AuthKind) Put

func (k *AuthKind) Put(ctx context.Context, ent *Auth) (*datastore.Key, error)

Put puts the entity to datastore.

func (*AuthKind) PutMulti

func (k *AuthKind) PutMulti(ctx context.Context, ents []*Auth) ([]*datastore.Key, error)

PutMulti do Put with multiple keys

func (*AuthKind) Replace

func (k *AuthKind) Replace(ctx context.Context, ent *Auth, replacer AuthKindReplacer) (*datastore.Key, *Auth, error)

func (*AuthKind) ReplaceMulti

func (k *AuthKind) ReplaceMulti(ctx context.Context, ents []*Auth, replacer AuthKindReplacer) ([]*datastore.Key, []*Auth, error)

func (*AuthKind) UseDefaultIfNil

func (k *AuthKind) UseDefaultIfNil(b bool) *AuthKind

type AuthKindReplacer

type AuthKindReplacer interface {
	Replace(*Auth, *Auth) *Auth
}

type AuthKindReplacerFunc

type AuthKindReplacerFunc func(*Auth, *Auth) *Auth

func (AuthKindReplacerFunc) Replace

func (f AuthKindReplacerFunc) Replace(ent1 *Auth, ent2 *Auth) *Auth

type AuthPagination

type AuthPagination struct {
	Start string           `json:"start"`
	End   string           `json:"end"`
	Count int              `json:"count,omitempty"`
	Data  []*Auth          `json:"data"`
	Keys  []*datastore.Key `json:"-"`
}

type AuthQuery

type AuthQuery struct {
	// contains filtered or unexported fields
}

AuthQuery helps to build and execute a query

func NewAuthQuery

func NewAuthQuery() *AuthQuery

func (*AuthQuery) Ancestor

func (q *AuthQuery) Ancestor(a lazy.Value) *AuthQuery

Ancestor sets the ancestor filter

func (*AuthQuery) Asc

func (q *AuthQuery) Asc(name string) *AuthQuery

Asc specifies ascending order on the given filed.

func (*AuthQuery) Count

func (q *AuthQuery) Count(ctx context.Context) (int, error)

Count returns the count of entities

func (*AuthQuery) Desc

func (q *AuthQuery) Desc(name string) *AuthQuery

Desc specifies descending order on the given filed.

func (*AuthQuery) End

func (q *AuthQuery) End(value lazy.Value) *AuthQuery

Limit specifies the numbe of limit returend by this query.

func (*AuthQuery) Eq

func (q *AuthQuery) Eq(name string, value lazy.Value) *AuthQuery

Eq sets the "=" filter on the name field.

func (*AuthQuery) Ge

func (q *AuthQuery) Ge(name string, value lazy.Value) *AuthQuery

Ge sets the ">=" filter on the "name" field.

func (*AuthQuery) GetAll

func (q *AuthQuery) GetAll(ctx context.Context) ([]*datastore.Key, []*Auth, error)

GetAll returns all key and value of the query.

func (*AuthQuery) GetAllValues

func (q *AuthQuery) GetAllValues(ctx context.Context) ([]*Auth, error)

GetAllValues is like GetAll but returns only values

func (*AuthQuery) Gt

func (q *AuthQuery) Gt(name string, value lazy.Value) *AuthQuery

Gt sets the ">" filter on the "name" field.

func (*AuthQuery) Le

func (q *AuthQuery) Le(name string, value lazy.Value) *AuthQuery

Le sets the "<=" filter on the "name" field.

func (*AuthQuery) Limit

func (q *AuthQuery) Limit(n lazy.Value) *AuthQuery

Limit specifies the numbe of limit returend by this query.

func (*AuthQuery) Lt

func (q *AuthQuery) Lt(name string, value lazy.Value) *AuthQuery

Lt sets the "<" filter on the "name" field.

func (*AuthQuery) MustCount

func (q *AuthQuery) MustCount(ctx context.Context) int

MustCount returns the count of entities

func (*AuthQuery) MustGetAll

func (q *AuthQuery) MustGetAll(ctx context.Context) ([]*datastore.Key, []*Auth)

MustGetAll is like GetAll but panic if an error occurrs.

func (*AuthQuery) MustGetAllValues

func (q *AuthQuery) MustGetAllValues(ctx context.Context) []*Auth

MustGetAllValues is like GetAllValues but panic if an error occurrs

func (*AuthQuery) MustRun

func (q *AuthQuery) MustRun(ctx context.Context) *AuthPagination

MustRun is like Run but panic if an error occurrs

func (*AuthQuery) Ne

func (q *AuthQuery) Ne(name string, value lazy.Value) *AuthQuery

Ne sets the "!=" filter on the "name" field.

func (*AuthQuery) Run

func (q *AuthQuery) Run(ctx context.Context) (*AuthPagination, error)

Run returns the a result as *AuthPagination object

func (*AuthQuery) Start

func (q *AuthQuery) Start(value lazy.Value) *AuthQuery

Limit specifies the numbe of limit returend by this query.

func (*AuthQuery) ViaKeys

func (q *AuthQuery) ViaKeys(k *AuthKind) *AuthQuery

ViaKeys optimize to execute keys-only query then call k.GetMulti() to fetch values. This would reduce the datastore query and maximize the memcache usage if the query called many times in a short time window.

type AuthType

type AuthType int

AuthType is an enum for authentication types.

const (
	AuthTypeNone AuthType = iota
	AuthTypeEmail
	AuthTypeFacebook
	AuthTypeTwitter
	AuthTypeMessenger
	AuthTypeGoogle
)

AuthType values

func MustParseAuthType

func MustParseAuthType(s string) AuthType

func ParseAuthType

func ParseAuthType(s string) (AuthType, error)

func ParseAuthTypeOr

func ParseAuthTypeOr(s string, or AuthType) AuthType

func (AuthType) MarshalJSON

func (i AuthType) MarshalJSON() ([]byte, error)

func (AuthType) String

func (i AuthType) String() string

func (*AuthType) UnmarshalJSON

func (i *AuthType) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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