验证码发送
1.在这里创建utils的包并把下面两个文件复制进去
2.将下列代码放入该文件
/**
* 注册时候发送验证码
* 先把注册写在这里,这样写不规范,需要优化
*/
@ApiOperation(“发送验证码”)
@PostMapping("/sendCheckCode")
public void sendCheckCode(@RequestParam String email) throws FileNotFoundException {
System.out.println(“email:” + email);
//发送验证码
MailUtils mailUtils = new MailUtils();
//生成随机6位验证码,并且存入数组
String code = mailUtils.randomCode();
//TODO static 优化
mailUtils.sendMail(email, code, “一个价值千万项目的验证码”);
// 将验证码暂时存放 能走缓存尽量走缓存
File file = new File(“D:\SpringBoot\workSpace\DDD5\ems\src\main\java\com\mt\ams\utils”, “checkCode.txt”);
byte bt[] = new byte[1024];
//邮箱转换为字节流
byte btEmail[] = new byte[1024];
btEmail = email.getBytes();
// 邮箱与验证码形成唯一标识
StringBuffer uniqueFlag = new StringBuffer();
uniqueFlag.append(code);
uniqueFlag.append(",");
uniqueFlag.append(email);
byte[] btUnique = new byte[1024];
btUnique = (uniqueFlag.toString()).getBytes();
System.out.println(uniqueFlag);
bt = code.getBytes();
//写入文件
try {
FileOutputStream in = new FileOutputStream(file);
try {
// in.write(bt, 0, bt.length);
in.write(btUnique, 0, btEmail.length);
in.close();
System.out.println(“写入文件成功”);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(“发送成功”);
} finally {
System.out.println(“结束”);
}
}
3.将下面两个文件复制到此处(UI)
4.在此文件中添加以下代码
//学生注册时候发送验证码
static sendCheckCode (email) {
const query = {
email
}
return axios({
url: ‘/ams/studentEntity/StudentInfo/sendCheckCode’,
method: ‘POST’,
params: query,
});
}
//学生匹配验证码
static checkCode (code) {
const query = {
code
}
return axios({
url: ‘/ams/studentEntity/StudentInfo/checkCode’,
method: ‘POST’,
params: query,
});
}
5.在login.vue中添加下列代码
<a-button block size="large" type="primary" class="stuRegisterButton"> <router-link to="/stuRegister" style="line-height: 22px;">学生注册 </router-link> </a-button>
6.找到这个文件,并添加以下代码
{ path: '/stuRegister', component: () => import('@/views/login/stuRegister'), meta: {title: '学生注册'} },
7.找到下面的文件,作以下修改
8.找到下面的文件,添加白名单
/api/ams/studentEntity/StudentInfo/sendCheckCode,/api/ams/studentEntity/StudentInfo/checkCode,/api/ams/studentEntity/StudentInfo/saveStudentInfo,/api/ams/collegeEntity/College/findColleges,/api/sys/user/userRegister