GGCaptcha

package module
v0.0.0-...-4a0e227 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 25 Imported by: 1

README

GGCaptcha

使用gg图像库和Redis以及本地缓存封装的验证码组件,包含简单数式计算验证、图片字符验证、图片数式计算验证和滑动图片验证。 支持使用自定义图片或使用本组件默认图片参数

	driver := GGCaptcha.NewDriverString()
	localStore := GGCaptcha.NewLocalStore()
	redisOption := GGCaptcha.RedisOptions{
		Host:     "192.168.245.22",
		Port:     "6379",
		Db:       4,
		PoolSize: 10,
		MaxRetry: 5,
	}
use default captcha for example(使用默认参数示例)
	redisStore := GGCaptcha.NewRediStore(redisOption)
	ggcaptcha := GGCaptcha.NewGGCaptcha(driver, redisStore)
	id, content, err := ggcaptcha.GenerateGGCaptcha()

use img as background(使用自定义背景图片)
	img := GGCaptcha.LoadLocalImg("../utils/dark.png")
	content, answer, err := GGCaptcha.GenerateDriverString()

use string verify(使用算数验证,直接返回字符类型算术式)
	ggcaptcha := GGCaptcha.NewGGCaptcha(driver, localstore, time.Minute)
	id, content, err := ggcaptcha.GenerateGGCaptcha()

use  string math(使用算术式图片验证,返回图片)
	ggcaptcha := GGCaptcha.NewGGCaptcha(driver, localstore, time.Minute)
	id, content, err := ggcaptcha.GenerateDriverMathString()

use puzzle verify(使用滑动验证码验证)
	ggcaptcha := GGCaptcha.NewGGCaptcha(driver, localstore, time.Minute)
	id, bgImage, puzzleImage, err := ggcaptcha.GenerateDriverPuzzle()

use verify_function verify code(验证密钥是否正确,是否清除)
	ggcaptcha.VerifyGGCaptcha(id,answer,true)


使用代码生成器
	table := Table{
		Name: "account",
		Fields: []Field{
			{Name: ToCamelCase("phone"), Type: "int", Nullable: false, GormTag: "comment:'phone'", Validate: "required", JsonTag: "phone,omitempty"},
			{Name: ToCamelCase("name"), Type: "varchar", Nullable: false, GormTag: "comment:'用户名'", Validate: "required", JsonTag: "name,omitempty"},
			{Name: ToCamelCase("email"), Type: "varchar", Nullable: true, GormTag: "comment:'邮箱'", Validate: "email", JsonTag: "email,omitempty"},
			{Name: ToCamelCase("password"), Type: "varchar", Nullable: false, GormTag: "comment:'hash密码'", JsonTag: "password"},
			{Name: ToCamelCase("salt"), Type: "varchar", Nullable: false, GormTag: "comment:'加密盐'", JsonTag: "salt"},
		},
	}
	err := GenerateCode.Generate(table)
	if err != nil {
		t.Fatalf("生成文件错误%s", err)
	}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadLocalImg

func LoadLocalImg(imgPath string) img.Img

func NewDriverString

func NewDriverString(imgOptions ...img.Img) *img.Img

func NewLocalStore

func NewLocalStore() *store.LocalStore

func NewRediStore

func NewRediStore(option RedisOptions) *store.RediStore

Types

type GGCaptcha

type GGCaptcha struct {
	// contains filtered or unexported fields
}

func NewGGCaptcha

func NewGGCaptcha(driver inter.Driver, store inter.Store, t time.Duration, windowTime time.Duration, limit int) *GGCaptcha

func (*GGCaptcha) GenerateDriverMath

func (g *GGCaptcha) GenerateDriverMath() (id, content string, err error)

func (*GGCaptcha) GenerateDriverMathString

func (g *GGCaptcha) GenerateDriverMathString() (id, content string, err error)

func (*GGCaptcha) GenerateDriverPuzzle

func (g *GGCaptcha) GenerateDriverPuzzle() (id, bgImage, puzzleImage string, err error)

func (*GGCaptcha) GenerateGGCaptcha

func (g *GGCaptcha) GenerateGGCaptcha() (id, content string, err error)

func (*GGCaptcha) RefreshCaptcha

func (g *GGCaptcha) RefreshCaptcha(ctype inter.CaptchaType) (id, content string, err error)

func (*GGCaptcha) VerifyGGCaptcha

func (g *GGCaptcha) VerifyGGCaptcha(id, answer string, clear bool) bool

type ImgOptions

type ImgOptions struct {
	Height       int         //图片高度
	Width        int         //图片宽度
	NoiseCount   int         //干扰线
	Count        int         //验证码数量
	Source       string      //数据源
	SourceLength int         //数据源长度
	SizePoint    float64     //字体大小
	Bgcolor      color.NRGBA //背景颜色
	FontStyle    font.Face   //字体
	UploadImg    image.Image

	MathNum      int //算术验证码数量
	PuzzleX      int // 滑动拼图的X位置
	PuzzleY      int // 滑动拼图的Y位置
	PuzzleWidth  int // 拼图块的宽度
	PuzzleHeight int // 拼图块的高度
}

type OAuthClient

type OAuthClient struct {
	Provider     OAuthProvider
	ClientID     string
	ClientSecret string
	RedirectURI  string
}

func NewOAuthClient

func NewOAuthClient(provider OAuthProvider, clientID, clientSecret, redirectURI string) *OAuthClient

NewOAuthClient 初始化 OAuth 客户端

func (*OAuthClient) ExchangeCode

func (client *OAuthClient) ExchangeCode(code string) (string, error)

ExchangeCode 交换授权码获取访问令牌

func (*OAuthClient) GetAuthURL

func (client *OAuthClient) GetAuthURL(state string) string

GetAuthURL 获取 OAuth 授权 URL

type OAuthProvider

type OAuthProvider string
const (
	Google OAuthProvider = "google"
	GitHub OAuthProvider = "github"
)

type RedisOptions

type RedisOptions struct {
	Host     string
	Port     string
	Db       int
	PoolSize int
	MaxRetry int
}

type SMSClient

type SMSClient struct {
	Provider  SMSProvider
	APIKey    string
	APISecret string
	SMSUrl    string
}

SMSClient 短信客户端结构体

func NewSMSClient

func NewSMSClient(provider SMSProvider, apiKey, apiSecret, smsUrl string) *SMSClient

NewSMSClient 初始化 SMS 客户端

func (*SMSClient) SendSMS

func (client *SMSClient) SendSMS(to, code string) (string, error)

SendSMS 发送短信验证码

type SMSProvider

type SMSProvider string
const (
	ALI     SMSProvider = "Ali"
	TENCENT SMSProvider = "Tencent"
	BAIDU   SMSProvider = "Baidu"
	HUAXIN  SMSProvider = "HuaXin"
	GETUI   SMSProvider = "GeTui"
)

type SMTPClient

type SMTPClient struct {
	Dialer *gomail.Dialer
	From   string
}

func NewSMTPClient

func NewSMTPClient(smtpHost string, smtpPort int, username, password string, from string) *SMTPClient

NewSMTPClient 初始化 SMTP 客户端

func (*SMTPClient) SendVerificationEmail

func (client *SMTPClient) SendVerificationEmail(to, token, subject, content string) error

SendVerificationEmail 发送验证邮件

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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