You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.7 KiB
64 lines
1.7 KiB
2 years ago
|
'use strict';
|
||
|
async function varfiyCode(ctx) {
|
||
|
try {
|
||
|
const { models } = ctx.fs.dc;
|
||
|
const { pushBySms, pushByEmail } = ctx.app.fs.utils
|
||
|
const { phone, type ,email} = ctx.request.body
|
||
|
|
||
|
// 伪造的请求可能由相同的sig参数组成
|
||
|
// const checkSigUsed = await models.PhoneValidateCode.findOne({
|
||
|
// where: { sig: sig }
|
||
|
// });
|
||
|
// if (checkSigUsed) {
|
||
|
// throw '参数错误!'
|
||
|
// }
|
||
|
|
||
|
// // 验证sig正确性
|
||
|
// const checkSig = Hex.stringify(SHA1(phone + r));
|
||
|
// if (!r || !sig || sig != checkSig) {
|
||
|
// throw '参数错误!'
|
||
|
// }
|
||
|
|
||
|
let varifyCode = ''
|
||
|
for (let i = 0; i < 6; i++) {
|
||
|
varifyCode += Math.floor(Math.random() * 10)
|
||
|
}
|
||
|
|
||
|
if(type.includes(1)){
|
||
|
await pushBySms({
|
||
|
phone: phone,
|
||
|
templateCode: 'SMS_261950020',
|
||
|
templateParam: {
|
||
|
code: varifyCode
|
||
|
},
|
||
|
})
|
||
|
}
|
||
|
if(type.includes(2)){
|
||
|
await pushByEmail({
|
||
|
email: email,
|
||
|
title: '测试',
|
||
|
text:'你知道吗'
|
||
|
})
|
||
|
}
|
||
|
|
||
|
// await models.PhoneValidateCode.create({
|
||
|
// phone: phone,
|
||
|
// code: varifyCode,
|
||
|
// sig: sig,
|
||
|
// expired: moment().add(10, 'minutes').format('YYYY-MM-DD HH:mm:ss')
|
||
|
// })
|
||
|
|
||
|
ctx.status = 204;
|
||
|
} catch (error) {
|
||
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
||
|
ctx.status = 400;
|
||
|
ctx.body = {
|
||
|
message: typeof error == 'string' ? error : '获取验证码失败'
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
varfiyCode,
|
||
|
// pushByEmail
|
||
|
}
|