Commit bf62b6fa authored by 任国军's avatar 任国军

fix login

parent 5c22fbdd
Pipeline #21862 passed with stage
in 12 seconds
......@@ -14,15 +14,15 @@ class UserService extends Service {
const APP_ID = '1C1wN39F4s61w62';
const APP_KEY = '6643BBA3-2663-4A69-BA4E-2711D6B0AED5';
if (!ctx.helper.isPhoneNumber(phone)) {
ctx.failed('手机号不正确');
}
const redisCode = await ctx.app.memcache.get(`course_verify_code_${phone}`);
if (!ctx.isEmpty(redisCode)) {
ctx.failed('请勿频繁操作');
}
if (!ctx.helper.isPhoneNumber(phone)) {
ctx.failed('手机号不正确');
}
const code = await this.getRandomNumber(5);
const now = String(new Date().getTime() - 1000);
......@@ -32,7 +32,7 @@ class UserService extends Service {
sign: ctx.helper.md5(`${now}&${APP_KEY}`),
params: {
phone,
content: `您的验证码是:${code},您正在登录趣选课,验证码5分内有效,请勿泄露给他人。`,
content: `【趣选课】您的验证码是:${code},您正在登录趣选课,验证码5分内有效,请勿泄露给他人。`,
},
}, {
method: 'POST',
......@@ -41,7 +41,7 @@ class UserService extends Service {
timeout: [ 5000, 60000 ],
});
if (ret.status === 200) {
if (ret.status === 201 || ret.status === 200) {
await ctx.app.memcache.set(`course_verify_code_${phone}`, code, 300);
} else {
ctx.logger.info('course_send_verify_code_error: ' + JSON.stringify(ret.data));
......@@ -67,6 +67,10 @@ class UserService extends Service {
const phone = input.phone;
const code = input.code;
if (!ctx.helper.isPhoneNumber(phone)) {
ctx.failed('手机号不正确');
}
// 判断用户是否存在
let userInfo = await ctx.classModel.V5.CourseUser.findOne({ where: { phone, is_deleted: 0 } });
if (ctx.isEmpty(userInfo)) {
......@@ -76,7 +80,8 @@ class UserService extends Service {
}
// 校验验证码
if (code !== 'fuck') {
const redisCode = await ctx.app.memcache.get(`course_verify_code_${phone}`);
if (ctx.isEmpty(redisCode) || code !== redisCode) {
ctx.failed('验证码错误');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment