django

package
v0.0.0-...-18d19a3 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2018 License: BSD-3-Clause Imports: 4 Imported by: 0

README

django

We will eventually open source this repo on github.com/acko/go-django.

This library provides interoperability with django's sessions and user authentication system.

The library is organised as django package that gives high level interface, and django/backend/db, django/backend/redis etc.

User and Session stores can be used with different backends within same project.

Documentation

Index

Constants

View Source
const (
	KeyUserID    = "_auth_user_id"
	KeyCSRFToken = "_csrf_token"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthStore

type AuthStore interface {
	UserStore
	GroupStore
	PermissionStore
}

type Group

type Group interface {
	ID() int64
	Name() string
	Permissions(context.Context) ([]Permission, error)
}

type GroupStore

type GroupStore interface {
	Groups(context.Context) ([]Group, error)
	GroupByID(context.Context, int64) (Group, error)
	GroupByName(context.Context, string) (Group, error)
}

type Permission

type Permission interface {
	ID() int64
	Code() string
	Name() string
}

type PermissionStore

type PermissionStore interface {
	Permissions(context.Context) ([]Permission, error)
	PermissionByID(context.Context, int64) (Permission, error)
	PermissionByCode(context.Context, string) (Permission, error)
}

type Session

type Session interface {
	// ID() returns the unique opaque if for the session. This id should be stored
	// in cookie etc.
	SessionKey() string
	// SetValue() stores a value in the session against the passed key. This will
	// be in store till the session is destroyed or till DeleteValue() is called.
	// Can return an error in case persistence fails. If this method is called
	// multiple times with same key, value keeps overwriting the old value.
	SetValue(ctx context.Context, key string, value interface{}) error
	// DeleteValue() removes the key from the session. If key is not present no
	// error is returned, only when there is an error during saving the session an
	// error is returned.
	//DeleteValue(key string) error
	// GetValue() returns a value, or ErrNotFound if there is no such value in the
	// session.
	GetValue(string) ([]byte, error)
	// GetInt() returns the value as Int, it will return ErrNotInt in case the
	// value stored is not an int.
	GetInt64(string) (int64, error)
	// GetString() returns the value as string, it will return ErrNotInt in case
	// the value stored is not a string.
	GetString(string) (string, error)
	GetUser(context.Context) (User, error)
	// Destroy() destroys the session from session store. Any calls to any method
	// session object after that may lead to error or crash.
	Destroy(context.Context) error

	Store() SessionStore

	String() string
}

type SessionStore

type SessionStore interface {
	// If GetSession on store is called with id of a destroyed session, a fresh
	// session is created and returned.
	GetSessionBySessionKey(ctx context.Context, key string) (Session, error)
	CreateSession(context.Context) (Session, error)
	DestroySession(ctx context.Context, id string) error
}

func NewFakeSessionStore

func NewFakeSessionStore() SessionStore

NewSessionStore creates a session store. It varifies that the session related table exists (but not if the table schema is correct).

type User

type User interface {
	ID() int64
	Field(string) (interface{}, bool)
	Email() string
	CheckPassword(string) bool

	Roles() ([]string, error)
	Permissions() ([]Permission, error)
	HasRole(context.Context, int64) (bool, error)
	HasPermission(string) (bool, error)

	SetName(string, bool) error
	SetEmail(string, bool) error
	SetPassword(string, bool) error
	Save(context.Context) error
	RefreshFromDB(context.Context) error
	Deactivate(reason string) error

	IsSuperUser() bool
}

type UserStore

type UserStore interface {
	GetOrCreateUser(context.Context, map[string]interface{}) (User, error)
	UserByID(context.Context, int64) (User, error)
	UserByAPIKey(context.Context, string) (User, error)
	UserByPhone(context.Context, string) (User, error)
	UserByEmail(context.Context, string) (User, error)
	Authenticate(context.Context, string, string) (User, error)
}

Directories

Path Synopsis
backends
db

Jump to

Keyboard shortcuts

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