Skip to content

Raoul1996/egg-captcha

Repository files navigation

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

About

captcha plugin for egg, based on ccap

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •