koa框架(三)

登录模块

图形验证码

在这里插入图片描述

采用的方式是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
  • 使用
    在这里插入图片描述
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值