controller

package
v0.1.25 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: MIT Imports: 23 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CasbinMemCache = cache.NewMemCache("casbin", 60, 10)
View Source
var MemCache = cache.NewMemCache("sessionUser", 60, 10)

Functions

func Check

func Check(ctx iris.Context, currentUser *entity.User) error

func CreateToken

func CreateToken(user *entity.User) ([]byte, error)

func CreateTokenPair

func CreateTokenPair(user *entity.User) (jwt.TokenPair, error)

func CurrentUser

func CurrentUser(ctx iris.Context) *entity.User

* 从会话中取当前用户,必须启动会话功能

func GenerateToken

func GenerateToken(ctx iris.Context, user *entity.User) []byte

* 产生新token,并设置cooki

func GenerateTokenPair

func GenerateTokenPair(ctx iris.Context, user *entity.User) *jwt.TokenPair

func Protected

func Protected(ctx iris.Context)

func RefreshToken

func RefreshToken(ctx iris.Context, user *entity.User) *jwt.TokenPair

There are various methods of refresh token, depending on the application requirements. In this example we will accept a refresh token only, we will verify only a refresh token and we re-generate a whole new pair. An alternative would be to accept a token pair of both access and refresh tokens, verify the refresh, verify the access with a Leeway time and check if its going to expire soon, then generate a single access token.

func ServeHTTP

func ServeHTTP(ctx iris.Context)

func Set

func Set(app *iris.Application)

* 设置casbin拦截器控制权限

func VerifyToken

func VerifyToken(token []byte, currentUser *entity.User) (string, string, time.Duration, error)

Types

type UserClaims

type UserClaims struct {
	UserName string `json:"userName"`
}

type UserController

type UserController struct {
	controller.BaseController
}

* 控制层代码需要做数据转换,调用服务层的代码,由于数据转换的结构不一致,因此每个实体(外部rest方式访问)的控制层都需要写一遍

func GetUserController

func GetUserController() *UserController

func (*UserController) CurrentUser

func (this *UserController) CurrentUser(ctx iris.Context) *entity.User

func (*UserController) GetCurrentUser

func (this *UserController) GetCurrentUser(ctx iris.Context)

func (*UserController) GetCurrentUserName

func (this *UserController) GetCurrentUserName(ctx iris.Context) string

func (*UserController) Login

func (this *UserController) Login(ctx iris.Context)

func (*UserController) Logout

func (this *UserController) Logout(ctx iris.Context)

func (*UserController) ParseJSON

func (this *UserController) ParseJSON(json []byte) (interface{}, error)

func (*UserController) Regist

func (this *UserController) Regist(ctx iris.Context)

Jump to

Keyboard shortcuts

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