egg-captcha
v1.2.2
Published
captcha plugin for egg, based on c++ lib ccap
Downloads
7
Maintainers
Readme
egg-captcha
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.