egg-verify-code

egg验证码

Usage no npm install needed!

<script type="module">
  import eggVerifyCode from 'https://cdn.skypack.dev/egg-verify-code';
</script>

README

egg-verify-code

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-verify-code --save

Usage

// {app_root}/config/plugin.js
exports.verifyCode = {
  enable: true,
  package: 'egg-verify-code',
};

Configuration

// {app_root}/config/config.default.js
exports.verifyCode = {
  canvas: {
    width: 100,
    height: 30
  },
  font: '24px "微软雅黑"'
};

see config/config.default.js for more detail.

Example

// {app_root}/service/verify.js

async generate() {
  const { app, ctx } = this;
  const verify = app.verifyCode.generate();
  ctx.session.code = verify.code;
  return verify.image
}
// {app_root}/controller/verify.js

async verifyCode() {
  const { ctx, service } = this
  const image = await service.user.generate()
  ctx.body = {
    image: image
  }
}

// {app_root}/router.js

module.exports = app => {
  const { controller, router } = app;
  router.get('/v1/api/verify', app.controller.verify.verifyCode);
}

Questions & Suggestions

Please open an issue here.

License

MIT