Documentation
¶
Overview ¶
Package verifycode 提供独立的验证码插件。
这是从 admin 插件中拆分出的独立验证码插件,可单独注册使用, 也可与 admin 插件一起使用(admin 插件会自动识别并使用本插件)。
功能:
- 生成验证码(绑定角色/权限)
- 验证码验证(支持一次性和多次使用)
- 有效期控制
- 验证码吊销
使用示例:
pm.Register(verifycode.New())
vcSvc := ctx.Service[*verifycode.Plugin]("verifycode")
code, _ := vc.Generate(verifycode.Config{Role: "vip", TTL: 24*time.Hour, MaxUses: 1})
role, err := vc.Verify(userID, codeStr)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CodeConfig ¶
type CodeConfig struct {
// Role 验证成功后授予的角色
Role string
// TTL 有效期(0 表示永不过期)
TTL time.Duration
// MaxUses 最大使用次数(0=一次性,<0=无限次)
MaxUses int
}
CodeConfig 验证码配置
type CodeEntry ¶
type CodeEntry struct {
Code string `json:"code"`
Role string `json:"role"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
MaxUses int `json:"max_uses"`
UsedCount int `json:"used_count"`
UsedBy []string `json:"used_by,omitempty"`
}
CodeEntry 验证码记录
type OnVerifyHook ¶
OnVerifyHook 验证成功后的回调(用于授予角色/权限)
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin 验证码插件
func NewPlugin ¶
func NewPlugin(onVerify OnVerifyHook, opts ...Option) *Plugin
NewPlugin 创建 Plugin 实例
func (*Plugin) Descriptor ¶
func (p *Plugin) Descriptor() *plugin.Descriptor
Descriptor 从已有 Plugin 创建描述符
Click to show internal directories.
Click to hide internal directories.