egg-captcha

1.2.2 • Public • Published

egg-captcha

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

captcha plugin for egg framework, based on ccap

Install

$ npm i egg-captcha --save

Usage

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

Configuration

// {app_root}/config/config.default.js
 
exports.captcha = {
  width: 256, // set width,default is 256
  height: 60, // set height,default is 60
  offset: 40, // set text spacing,default is 40
  quality: 100, // set pic quality,default is 50
  fontsize: 57 // set font size,default is 57
}

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

Example

// {app_root}/controller/user.js
 
async captcha() {
  const {ctx, service} = this
  const {captcha, txt} = await service.user.captcha()
  ctx.body = captcha
  ctx.type = 'image/png'
  // need open the egg-session plugin
  ctx.session.captcha = txt
}
// {app_root}/service/user.js
 
async captcha() {
  const {app} = this
  const ary = app.captcha.generate()
  return {captcha: ary[1], txt: ary[0]}
}

Questions & Suggestions

Please open an issue here.

License

MIT

Package Sidebar

Install

npm i egg-captcha

Weekly Downloads

10

Version

1.2.2

License

MIT

Unpacked Size

7.83 kB

Total Files

7

Last publish

Collaborators

  • raoul1996