Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fritx/koa-captcha-2
Captcha utils for koa 2
https://github.com/fritx/koa-captcha-2
captcha koa
Last synced: 4 months ago
JSON representation
Captcha utils for koa 2
- Host: GitHub
- URL: https://github.com/fritx/koa-captcha-2
- Owner: fritx
- Created: 2017-08-01T15:43:46.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-08T10:51:16.000Z (almost 5 years ago)
- Last Synced: 2024-10-01T10:21:22.241Z (4 months ago)
- Topics: captcha, koa
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/koa-captcha-2
- Size: 26.4 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# koa-captcha-2
> Captcha utils for koa 2
*Based on [gd-bmp](https://github.com/zengming00/node-gd-bmp)*
### Install via npm
```plain
npm i -S koa-captcha-2
```### Draw the image
```js
let { drawCaptcha } = require('koa-captcha-2')
// ...
router.get('/api/captcha', drawCaptcha)
```### Verify the code
```js
let { verifyCaptcha } = require('koa-captcha-2')
// ...
router.post('/api/login', ctx => {
if (!verifyCaptcha(ctx)) {
ctx.throw(400, 'Captcha not correct')
}
// ...
})
```### Form markups
```vue
export default {
data () {
return {
captchaKey: Date.now(),
model: {
account: 'admin',
password: 'admin',
captcha: ''
}
}
},
computed: {
captchaSrc () {
return `/api/captcha?key=${this.captchaKey}`
}
},
methods: {
reloadCaptcha () {
this.captchaKey = Date.now()
this.model.captcha = ''
},
submitForm () {
let { captchaKey } = this
postApi('/api/login', {
...this.model, captchaKey
})
.then(() => {
// ...
})
.catch(err => {
// ...
this.reloadCaptcha()
})
}
}
}```