1.0.14 • Published 5 years ago
egg-verify-code v1.0.14
egg-verify-code
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.