登录模块
图形验证码
采用的方式是svg-captcha这个库生成svg数据直接给前端渲染
- 安装
npm install --save svg-captcha
- 使用
后端
import svgCaptcha from 'svg-captcha'
class PublicController {
constructor () {}
async getCaptcha(ctx) {
const captcha = svgCaptcha.create({
ignoreChars: '0o1i', // 验证码字符中排除 0o1i
noise: 1, // 干扰线条的数量
color: true, // 验证码的字符是否有颜色,默认没有,如果设定了背景,则默认有
width: 150,
height: 35
})
ctx.body = {
code: 200,
data: captcha.data
}
}
}
export default new PublicController()
前端
// html
<div class="layui-form-mid layui-word-aux svg-code" v-html="svgCode" @click="getCaptchaCode">
// js
getCaptchaCode () {
GetCaptcha().then(res => {
console.log('res', res)
if (res.code === 200) {
this.svgCode = res.data
}
})
},
邮件配置服务
找回密码功能是通过邮件发送一封重置密码的邮件去实现的,这里使用的是NodeMailer和QQ邮箱
- 常用的邮件服务:
- 阿里云
- 亚马逊SES
- SendCloud
- NodeMailer和QQ邮箱使用
注册未满14天的无法使用,满的可以需开启POP3/SMTP服务
- 安装
npm i nodemailer -S
- 使用