go-admin: github.com/GoAdminGroup/go-admin/modules/auth Index | Files

package auth

import "github.com/GoAdminGroup/go-admin/modules/auth"


Package Files

auth.go middleware.go session.go


const (
    TokenServiceKey = "token_csrf_helper"
    ServiceKey      = "auth"
const DefaultCookieKey = "go_admin_session"

func Auth Uses

func Auth(ctx *context.Context) models.UserModel

Auth get the user model from Context.

func Check Uses

func Check(password string, username string, conn db.Connection) (user models.UserModel, ok bool)

Check check the password and username and return the user model.

func CheckPermissions Uses

func CheckPermissions(user models.UserModel, path, method string, param url.Values) bool

CheckPermissions check the permission of the user.

func DelCookie Uses

func DelCookie(ctx *context.Context, conn db.Connection) error

DelCookie delete the cookie from Context.

func EncodePassword Uses

func EncodePassword(pwd []byte) string

EncodePassword encode the password.

func Filter Uses

func Filter(ctx *context.Context, conn db.Connection) (models.UserModel, bool, bool)

Filter retrieve the user model from Context and check the permission at the same time.

func GetCurUser Uses

func GetCurUser(sesKey string, conn db.Connection) (user models.UserModel, ok bool)

GetCurUser return the user model.

func GetCurUserByID Uses

func GetCurUserByID(id int64, conn db.Connection) (user models.UserModel, ok bool)

GetCurUserByID return the user model of given user id.

func GetSessionByKey Uses

func GetSessionByKey(sesKey, key string, conn db.Connection) (interface{}, error)

GetSessionByKey get the session value by key.

func GetUserID Uses

func GetUserID(sesKey string, conn db.Connection) int64

GetUserID return the user id from the session.

func Middleware Uses

func Middleware(conn db.Connection) context.Handler

Middleware is the default auth middleware of plugins.

func SetCookie Uses

func SetCookie(ctx *context.Context, user models.UserModel, conn db.Connection) error

SetCookie set the cookie.

type CSRFToken Uses

type CSRFToken []string

CSRFToken is type of a csrf token list.

type Config Uses

type Config struct {
    Expires time.Duration
    Cookie  string

Config wraps the Session info.

type DBDriver Uses

type DBDriver struct {
    // contains filtered or unexported fields

DBDriver is a driver which uses database as a persistence tool.

func (*DBDriver) Load Uses

func (driver *DBDriver) Load(sid string) (map[string]interface{}, error)

Load implements the PersistenceDriver.Load.

func (*DBDriver) Update Uses

func (driver *DBDriver) Update(sid string, values map[string]interface{}) error

Update implements the PersistenceDriver.Update.

type Invoker Uses

type Invoker struct {
    // contains filtered or unexported fields

Invoker contains the callback functions which are used in the route middleware.

func DefaultInvoker Uses

func DefaultInvoker(conn db.Connection) *Invoker

DefaultInvoker return a default Invoker.

func SetPrefix Uses

func SetPrefix(prefix string, conn db.Connection) *Invoker

SetPrefix return the default Invoker with the given prefix.

func (*Invoker) Middleware Uses

func (invoker *Invoker) Middleware() context.Handler

Middleware get the auth middleware from Invoker.

func (*Invoker) SetAuthFailCallback Uses

func (invoker *Invoker) SetAuthFailCallback(callback MiddlewareCallback) *Invoker

SetAuthFailCallback set the authFailCallback of Invoker.

func (*Invoker) SetPermissionDenyCallback Uses

func (invoker *Invoker) SetPermissionDenyCallback(callback MiddlewareCallback) *Invoker

SetPermissionDenyCallback set the permissionDenyCallback of Invoker.

type MiddlewareCallback Uses

type MiddlewareCallback func(ctx *context.Context)

MiddlewareCallback is type of callback function.

type PersistenceDriver Uses

type PersistenceDriver interface {
    Load(string) (map[string]interface{}, error)
    Update(sid string, values map[string]interface{}) error

PersistenceDriver is a driver of storing and getting the session info.

type Processor Uses

type Processor func(ctx *context.Context) (model models.UserModel, exist bool, msg string)

type Service Uses

type Service struct {
    P Processor

func GetService Uses

func GetService(s interface{}) *Service

func NewService Uses

func NewService(processor Processor) *Service

func (*Service) Name Uses

func (s *Service) Name() string

type Session Uses

type Session struct {
    Expires time.Duration
    Cookie  string
    Values  map[string]interface{}
    Driver  PersistenceDriver
    Sid     string
    Context *context.Context

Session contains info of session.

func InitSession Uses

func InitSession(ctx *context.Context, conn db.Connection) (*Session, error)

InitSession return the default Session.

func (*Session) Add Uses

func (ses *Session) Add(key string, value interface{}) error

Add add the session value of key.

func (*Session) Clear Uses

func (ses *Session) Clear() error

Clear clear a Session.

func (*Session) Get Uses

func (ses *Session) Get(key string) interface{}

Get get the session value.

func (*Session) StartCtx Uses

func (ses *Session) StartCtx(ctx *context.Context) (*Session, error)

StartCtx return a Session from the given Context.

func (*Session) UpdateConfig Uses

func (ses *Session) UpdateConfig(config Config)

UpdateConfig update the Expires and Cookie of Session.

func (*Session) UseDriver Uses

func (ses *Session) UseDriver(driver PersistenceDriver)

UseDriver set the driver of the Session.

type TokenService Uses

type TokenService struct {
    // contains filtered or unexported fields

func GetTokenService Uses

func GetTokenService(s interface{}) *TokenService

func (*TokenService) AddToken Uses

func (s *TokenService) AddToken() string

AddToken add the token to the CSRFToken.

func (*TokenService) CheckToken Uses

func (s *TokenService) CheckToken(toCheckToken string) bool

CheckToken check the given token with tokens in the CSRFToken, if exist return true.

func (*TokenService) Name Uses

func (s *TokenService) Name() string

Package auth imports 21 packages (graph) and is imported by 24 packages. Updated 2020-08-05. Refresh now. Tools for package owners.