jwtauth

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidVerificationCode = errors.New("invalid verification code")

Functions

func Authenticator

func Authenticator(c *gin.Context) (interface{}, error)

Authenticator 获取token @Summary 登陆 @Description 获取token @Description LoginHandler can be used by clients to get a jwt token. @Description Payload needs to be json in the form of {"username": "USERNAME", "password": "PASSWORD"}. @Description Reply will be of the form {"token": "TOKEN"}. @Description dev mode:It should be noted that all fields cannot be empty, and a value of 0 can be passed in addition to the account password @Description 注意:开发模式:需要注意全部字段不能为空,账号密码外可以传入0值 @Tags 登陆 @Accept application/json @Product application/json @Param account body Login true "account" @Success 200 {string} string "{"code": 200, "expire": "2019-08-07T12:45:48+08:00", "token": ".eyJleHAiOjE1NjUxNTMxNDgsImlkIjoiYWRtaW4iLCJvcmlnX2lhdCI6MTU2NTE0OTU0OH0.-zvzHvbg0A" }" @Router /api/v1/login [post]

func Authorizator

func Authorizator(data interface{}, c *gin.Context) bool

Authorizator See AuthCheckRole handler

func LoginLogToDB

func LoginLogToDB(c *gin.Context, status string, msg string, username string)

LoginLogToDB Write log to database

func LogoutResponse

func LogoutResponse(c *gin.Context, code int)

func PayloadFunc

func PayloadFunc(data interface{}) jwt.MapClaims

func Unauthorized

func Unauthorized(c *gin.Context, code int, message string)

Types

type Login

type Login struct {
	Username string `form:"UserName" json:"username" binding:"required"`
	Password string `form:"Password" json:"password" binding:"required"`
	Code     string `form:"Code" json:"code" binding:"required"`
	UUID     string `form:"UUID" json:"uuid" binding:"required"`
}

func (*Login) GetUser

func (u *Login) GetUser(tx *gorm.DB) (user SysUser, role SysRole, err error)

type SysRole

type SysRole struct {
	RoleId    int    `json:"roleId" gorm:"primaryKey;autoIncrement"` // 角色编码
	RoleName  string `json:"roleName" gorm:"size:128;"`              // 角色名称
	Status    string `json:"status" gorm:"size:4;"`                  //
	RoleKey   string `json:"roleKey" gorm:"size:128;"`               //角色代码
	RoleSort  int    `json:"roleSort" gorm:""`                       //角色排序
	Flag      string `json:"flag" gorm:"size:128;"`                  //
	Remark    string `json:"remark" gorm:"size:255;"`                //备注
	DataScope string `json:"dataScope" gorm:"size:8;"`
	Params    string `json:"params" gorm:"-"`
	MenuIds   []int  `json:"menuIds" gorm:"-"`
	DeptIds   []int  `json:"deptIds" gorm:"-"`
	models.ControlBy
	models.ModelTime
}

type SysUser

type SysUser struct {
	UserId   int    `gorm:"primaryKey;autoIncrement;comment:编码"  json:"userId"`
	Username string `json:"username" gorm:"size:64;comment:用户名"`
	Password string `json:"-" gorm:"size:128;comment:密码"`
	NickName string `json:"nickName" gorm:"size:128;comment:昵称"`
	Phone    string `json:"phone" gorm:"size:11;comment:手机号"`
	RoleId   int    `json:"roleId" gorm:"size:20;comment:角色ID"`
	Salt     string `json:"-" gorm:"size:255;comment:加盐"`
	Avatar   string `json:"avatar" gorm:"size:255;comment:头像"`
	Sex      string `json:"sex" gorm:"size:255;comment:性别"`
	Email    string `json:"email" gorm:"size:128;comment:邮箱"`
	DeptId   int    `json:"deptId" gorm:"size:20;comment:部门"`
	PostId   int    `json:"postId" gorm:"size:20;comment:岗位"`
	Remark   string `json:"remark" gorm:"size:255;comment:备注"`
	Status   string `json:"status" gorm:"size:4;comment:状态"`
	DeptIds  []int  `json:"deptIds" gorm:"-"`
	PostIds  []int  `json:"postIds" gorm:"-"`
	RoleIds  []int  `json:"roleIds" gorm:"-"`
	//Dept     *SysDept `json:"dept"`
	models.ControlBy
	models.ModelTime
}

func (*SysUser) AfterFind

func (e *SysUser) AfterFind(_ *gorm.DB) error

Jump to

Keyboard shortcuts

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