Documentation ¶
Index ¶
- Constants
- func Auth(ctx *context.Context) models.UserModel
- func Check(password string, username string, conn db.Connection) (user models.UserModel, ok bool)
- func CheckPermissions(user models.UserModel, path, method string, param url.Values) bool
- func DelCookie(ctx *context.Context, conn db.Connection) error
- func EncodePassword(pwd []byte) string
- func Filter(ctx *context.Context, conn db.Connection) (models.UserModel, bool, bool)
- func GetCurUser(sesKey string, conn db.Connection) (user models.UserModel, ok bool)
- func GetCurUserByID(id int64, conn db.Connection) (user models.UserModel, ok bool)
- func GetSessionByKey(sesKey, key string, conn db.Connection) (interface{}, error)
- func GetUserID(sesKey string, conn db.Connection) int64
- func InitCSRFTokenSrv(conn db.Connection) (string, service.Service)
- func Middleware(conn db.Connection) context.Handler
- func SetCookie(ctx *context.Context, user models.UserModel, conn db.Connection) error
- type CSRFToken
- type Config
- type DBDriver
- type Invoker
- type MiddlewareCallback
- type PersistenceDriver
- type Processor
- type Service
- type Session
- func (ses *Session) Add(key string, value interface{}) error
- func (ses *Session) Clear() error
- func (ses *Session) Get(key string) interface{}
- func (ses *Session) StartCtx(ctx *context.Context) (*Session, error)
- func (ses *Session) UpdateConfig(config Config)
- func (ses *Session) UseDriver(driver PersistenceDriver)
- type TokenService
Constants ¶
const ( TokenServiceKey = "token_csrf_helper" ServiceKey = "auth" )
const DefaultCookieKey = "go_admin_session"
Variables ¶
This section is empty.
Functions ¶
func CheckPermissions ¶
CheckPermissions check the permission of the user.
func DelCookie ¶
func DelCookie(ctx *context.Context, conn db.Connection) error
DelCookie delete the cookie from Context.
func Filter ¶
Filter retrieve the user model from Context and check the permission at the same time.
func GetCurUser ¶ added in v1.3.0
GetCurUser return the user model.
func GetCurUserByID ¶ added in v1.3.0
GetCurUserByID return the user model of given user id.
func GetSessionByKey ¶ added in v1.3.0
func GetSessionByKey(sesKey, key string, conn db.Connection) (interface{}, error)
GetSessionByKey get the session value by key.
func GetUserID ¶ added in v1.3.0
func GetUserID(sesKey string, conn db.Connection) int64
GetUserID return the user id from the session.
func InitCSRFTokenSrv ¶ added in v1.3.0
func InitCSRFTokenSrv(conn db.Connection) (string, service.Service)
func Middleware ¶ added in v1.3.0
func Middleware(conn db.Connection) context.Handler
Middleware is the default auth middleware of plugins.
Types ¶
type DBDriver ¶ added in v1.3.0
type DBDriver struct {
// contains filtered or unexported fields
}
DBDriver is a driver which uses database as a persistence tool.
type Invoker ¶
type Invoker struct {
// contains filtered or unexported fields
}
Invoker contains the callback functions which are used in the route middleware.
func DefaultInvoker ¶ added in v1.3.0
func DefaultInvoker(conn db.Connection) *Invoker
DefaultInvoker return a default Invoker.
func SetPrefix ¶
func SetPrefix(prefix string, conn db.Connection) *Invoker
SetPrefix return the default Invoker with the given prefix.
func (*Invoker) Middleware ¶
Middleware get the auth middleware from Invoker.
func (*Invoker) SetAuthFailCallback ¶
func (invoker *Invoker) SetAuthFailCallback(callback MiddlewareCallback) *Invoker
SetAuthFailCallback set the authFailCallback of Invoker.
func (*Invoker) SetPermissionDenyCallback ¶
func (invoker *Invoker) SetPermissionDenyCallback(callback MiddlewareCallback) *Invoker
SetPermissionDenyCallback set the permissionDenyCallback of Invoker.
type MiddlewareCallback ¶
MiddlewareCallback is type of callback function.
type PersistenceDriver ¶
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 Service ¶ added in v1.3.0
type Service struct {
P Processor
}
func GetService ¶ added in v1.3.0
func GetService(s interface{}) *Service
func NewService ¶ added in v1.3.0
type Session ¶
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 ¶
InitSession return the default Session.
func (*Session) UpdateConfig ¶
UpdateConfig update the Expires and Cookie of Session.
func (*Session) UseDriver ¶ added in v1.3.0
func (ses *Session) UseDriver(driver PersistenceDriver)
UseDriver set the driver of the Session.
type TokenService ¶ added in v1.3.0
type TokenService struct {
// contains filtered or unexported fields
}
func GetTokenService ¶ added in v1.3.0
func GetTokenService(s interface{}) *TokenService
func (*TokenService) AddToken ¶ added in v1.3.0
func (s *TokenService) AddToken() string
AddToken add the token to the CSRFToken.
func (*TokenService) CheckToken ¶ added in v1.3.0
func (s *TokenService) CheckToken(toCheckToken string) bool
CheckToken check the given token with tokens in the CSRFToken, if exist return true.
func (*TokenService) Name ¶ added in v1.3.0
func (s *TokenService) Name() string