0.2.5 • Published 4 months ago

tms-koa-captcha v0.2.5

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

提供tms-koa框架的验证码功能。

tms-koa 验证码方法

设置验证服务

在账号服务模块配置文件.config/captcha.js中设置

export default {
  disabled: false, // boolean 是否启用验证码
  storageType: 'lowdb', // 验证码存储方式  lowdb | redis
  masterCaptcha: 'aabb', // string 万能验证码
  codeSize: 4, //验证码长度  默认4
  alphabetType: 'number,upperCase,lowerCase', // 字母表生产类型 默认 数字+大写字母+小写字母
  alphabet: '1234567890', // 与alphabetType不可公用,优先级大于alphabetType
  expire: 300, // 过期时间 s 默认300
}
字段说明类型默认必填
disabled是否启用验证码booleanfalse
storageType验证码存储方式 支持 redis、lowdbstringlowdb
masterCaptcha万能验证码string
codeSize验证码长度int4
alphabetType验证码字母表类型 与 alphabetType 不可公用,优先级大于 alphabetTypestringnumber,upperCase,lowerCase
expire验证码有效期(s)int300

tms-koa 配置验证码服务

tms-koa框架配置文件./config/app.js中配置

export default {
  auth: {
    captcha: {
      disabled: false,
      path: '', // 验证码生成方法文件位置
      checkPath: '', // 验证码检查方法位置
      code: '', // 固定的验证码(用于开发测试)
      npm: {
        disabled: false,
        id: 'tms-koa-captcha',
        module: 'dist',
        checker: 'checkCaptcha',
        generator: 'createCaptcha',
      },
    },
  },
}
字段说明类型默认
captcha.npm.disabled是否使用false
captcha.npm.id使用的 npm 包名称,例如:tms-koa-captchastring
captcha.npm.modulenpm 包中的模块,例如:diststring
captcha.npm.checker验证码检查函数(……)string
captcha.npm.generator验证码生成函数(……)string
captcha.npm.node_modules_root指定 npm 包的位置(为了调试代码时方便。)string

API 调用示例

获取验证码

curl 'http://localhost:3001/auth/captcha?appid=demo&captchaid=demo01'
curl 'http://localhost:3001/auth/captcha?appid=demo&captchaid=demo01&returnType=text'

附加参数

参数说明默认值
storageType验证码存储方式lowdb / redislowdb
codeSize验证码长度4
alphabetType字母表类型 默认 数字+大写字母+小写字母"number,upperCase,lowerCase
alphabet与 alphabetType 不可公用,优先级大于 alphabetType"1234567890"
expire过期时间,单位秒300
returnType返回验证码类型text / imageimage

检验验证码

curl 'http://localhost:3001/auth/checkCaptcha?appid=demo&captchaid=demo01&code='

附加参数

参数说明默认值
strictMode检验大小写N / YN
0.2.5

4 months ago

0.2.3

6 months ago

0.2.2

6 months ago

0.2.4

6 months ago

0.2.1

8 months ago

0.2.0

8 months ago

0.1.7

1 year ago

0.1.2

2 years ago

0.1.3

1 year ago

0.1.6

1 year ago

0.1.1

2 years ago

0.1.0

2 years ago