base

package
v0.0.0-...-2f69930 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseCfg

type BaseCfg struct {
	DefaultRole                      string                     `json:"default_role"`
	DefaultTag                       string                     `json:"default_tag"`
	DefaultLevel                     int                        `json:"default_level"`
	CheckLogin                       bool                       `json:"check_login"`
	TokenByUrlQuery                  bool                       `json:"token_by_url_query"`
	TokenByUrlQueryName              string                     `json:"token_by_url_query_name"`
	IgnoreCheckLoginPath             map[string][]string        `json:"ignore_check_login_path"`
	TokenExpireDuration              config.Duration            `json:"token_expire_duration"`
	SpecifyUserIDTokenExpireDuration map[string]config.Duration `json:"specify_user_id_token_expire_duration"` //特别指定user_id的token过期时间
	OnlySingleLogin                  bool                       `json:"only_single_login"`                     //设置后,allow_multi_login,allow_multi_login_num不起作用
	OnlySingleLoginUserID            []string                   `json:"only_single_login_user_id"`             //不受only_single_login控制,设置后的user_id将使allow_multi_login,allow_multi_login_num不起作用
	OnlySingleLoginUserIDUnlimited   []string                   `json:"only_single_login_user_id_unlimited"`   //不受only_single_login控制,设置后的user_id受allow_multi_login,allow_multi_login_num影响
	AllowMultiLogin                  bool                       `json:"allow_multi_login"`
	AllowMultiLoginNum               int64                      `json:"allow_multi_login_num"`
	AllowMultiLoginUserIDUnlimited   []string                   `json:"allow_multi_login_user_id_unlimited"` //在允许allow_multi_login的情况下,设置后的user_id不受allow_multi_login_num限制
}

type CacheCfg

type CacheCfg struct {
	CacheDefaultExpiration config.Duration `json:"cache_default_expiration"`
	CacheCleanupInterval   config.Duration `json:"cache_cleanup_interval"`
}

type Config

type Config struct {
	MongodbCfg
	CacheCfg
	BaseCfg
}

type MongodbCfg

type MongodbCfg struct {
	MongoDNS          string `json:"mongo_dns"`
	MongoDatabaseName string `json:"mongo_database_name"`
}

type Service

type Service struct {
	*Config
	*cache.Cache
	M mongodb.Mongoer
}

func NewService

func NewService(c *Config, cc *cache.Cache, m mongodb.Mongoer) *Service

func (*Service) BearerAuth

func (self *Service) BearerAuth(r *http.Request) (string, bool)

func (*Service) CheckUser

func (self *Service) CheckUser(ctx context.Context, username string) (int64, error)

func (*Service) CreateToken

func (self *Service) CreateToken(ctx context.Context, u model.User, ip, userAgent string, coordinates geometry.PointCoordinates, expiredTime time.Time) (m help.M, err error)

func (*Service) CreateUser

func (self *Service) CreateUser(ctx context.Context, id primitive.ObjectID, username, password string, longitude, latitude float64, enableProfile bool, extensionID int, guest bool) (primitive.ObjectID, error)

func (*Service) DeleteTokenByToken

func (self *Service) DeleteTokenByToken(tokenID primitive.ObjectID, r *http.Request) (err error)

func (*Service) DeleteTokenByUsernameAndPassword

func (self *Service) DeleteTokenByUsernameAndPassword(ctx context.Context, tokenID primitive.ObjectID, username, password string) error

func (*Service) GetClaims

func (self *Service) GetClaims(r *http.Request) (claims *predefined.JWTTokenClaims)

func (*Service) GetTokensByToken

func (self *Service) GetTokensByToken(r *http.Request) (ts []help.M, err error)

func (*Service) GetTokensByUsernameAndPassword

func (self *Service) GetTokensByUsernameAndPassword(ctx context.Context, username, password string) (ts []help.M, err error)

func (*Service) GetUserInfo

func (self *Service) GetUserInfo(r *http.Request) (u model.User, found bool)

func (*Service) GetValidClaims

func (self *Service) GetValidClaims(r *http.Request) (claims *predefined.JWTTokenClaims, u model.User)

func (*Service) Login

func (self *Service) Login(ctx context.Context, username, password, ip, userAgent string, coordinates geometry.PointCoordinates, expiredTime time.Time) (m help.M, err error)

func (*Service) LoginByUserID

func (self *Service) LoginByUserID(ctx context.Context, userID primitive.ObjectID, ip, userAgent string, coordinates geometry.PointCoordinates, expiredTime time.Time) (m help.M, err error)

func (*Service) Logout

func (self *Service) Logout(r *http.Request)

Jump to

Keyboard shortcuts

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