npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tms-koa-captcha

v0.2.15

Published

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

Downloads

77

Readme

提供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 | 是否启用验证码 | boolean | false | 否 | | storageType | 验证码存储方式 支持 redis、lowdb | string | lowdb | 否 | | masterCaptcha | 万能验证码 | string | | 否 | | codeSize | 验证码长度 | int | 4 | 否 | | alphabetType | 验证码字母表类型 与 alphabetType 不可公用,优先级大于 alphabetType | string | number,upperCase,lowerCase | 否 | | expire | 验证码有效期(s) | int | 300 | 否 |

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-captcha | string | | | captcha.npm.module | npm 包中的模块,例如:dist | string | | | 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 / redis | lowdb | | codeSize | 验证码长度 | 4 | | alphabetType | 字母表类型 默认 数字+大写字母+小写字母 | "number,upperCase,lowerCase | | alphabet | 与 alphabetType 不可公用,优先级大于 alphabetType | "1234567890" | | expire | 过期时间,单位秒 | 300 | | returnType | 返回验证码类型text / image | image |

检验验证码

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

附加参数

| 参数 | 说明 | 默认值 | | ---------- | ----------------- | ------ | | strictMode | 检验大小写N / Y | N |