登录:绑定、服务器列表
This commit is contained in:
@@ -28,6 +28,7 @@ export default class Auth extends Service {
|
||||
const ctx = this.ctx;
|
||||
|
||||
let user = await UserModel.findUserByToken(token);
|
||||
let loginType = 1;
|
||||
|
||||
if (!user) {
|
||||
if(isGuest) {
|
||||
@@ -35,8 +36,13 @@ export default class Auth extends Service {
|
||||
const token = ctx.service.utils.generateStr(256);
|
||||
user = await UserModel.createUser(isGuest, tel, token, platform, pkgName, serverType, deviceId);
|
||||
let param = this.getReturnParam(user);
|
||||
// TODO 判断同一设备号15天内是否重复使用游客模式
|
||||
if(param.isGuest && param.guestTime > 60*60*1000) {
|
||||
loginType = 2;
|
||||
}
|
||||
return this.ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
canLogin: true,
|
||||
loginType,
|
||||
...param
|
||||
});
|
||||
} else {
|
||||
@@ -49,8 +55,13 @@ export default class Auth extends Service {
|
||||
const token = ctx.service.utils.generateStr(256);
|
||||
user = await UserModel.updateToken(user.tel, token, deviceId);
|
||||
let param = this.getReturnParam(user);
|
||||
|
||||
if(param.isGuest && param.guestTime > 60*60*1000) {
|
||||
loginType = 2;
|
||||
}
|
||||
return this.ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
canLogin: true,
|
||||
loginType,
|
||||
...param
|
||||
});
|
||||
}
|
||||
@@ -135,7 +146,11 @@ export default class Auth extends Service {
|
||||
const smsResult = await this.sendSmsCodeByGuodu(tel, code);
|
||||
console.log(smsResult);
|
||||
await smsModel.updateByTel(tel, code, false, new Date(), sms?.hasSendToday() ? sms.countToday + 1 : 1);
|
||||
return this.ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
|
||||
let user = await UserModel.findUserByTel(tel);
|
||||
return this.ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
hasAccount: !!user
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,6 +204,7 @@ export default class Auth extends Service {
|
||||
public async setPassword(password: string) {
|
||||
const { ctx } = this;
|
||||
const { uid } = ctx;
|
||||
if(!password) return ctx.service.utils.resResult(STATUS.PASSWORD_ILLEGEL);
|
||||
|
||||
let user = await UserModel.setPass(uid, password);
|
||||
if (user) {
|
||||
@@ -290,4 +306,66 @@ export default class Auth extends Service {
|
||||
}
|
||||
return ctx.service.utils.resResult(STATUS.ROLE_NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定账号
|
||||
* @param password 密码
|
||||
*/
|
||||
public async bind(tel: string, code: string, password: string) {
|
||||
const ctx = this.ctx;
|
||||
// 参数检查
|
||||
const telVerify = this.checkTelNo(tel);
|
||||
if (telVerify.status !== 0) {
|
||||
return telVerify;
|
||||
}
|
||||
|
||||
if (!isString(code) || code.length !== 6 || !password) {
|
||||
return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
// 手机验证码核验
|
||||
const smsValid: boolean = await smsModel.validateSms(tel, code);
|
||||
if (!smsValid) {
|
||||
const sms = await smsModel.findByTel(tel);
|
||||
if (sms && sms.isFixed) { // 固定手机号登录
|
||||
if (sms.code !== code) {
|
||||
return ctx.service.utils.resResult(STATUS.SMS_INVALID);
|
||||
}
|
||||
} else {
|
||||
return ctx.service.utils.resResult(STATUS.SMS_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
let telUser = await UserModel.findUserByTel(tel);
|
||||
if(telUser && telUser.uid != ctx.uid) {
|
||||
return ctx.service.utils.resResult(STATUS.TEL_HAS_USED);
|
||||
}
|
||||
|
||||
let user = await UserModel.bindTel(ctx.uid, tel, password);
|
||||
if(!user) return ctx.service.utils.resResult(STATUS.ACCOUNT_NOT_GUEST);
|
||||
let param = this.getReturnParam(user);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, param);
|
||||
}
|
||||
|
||||
/**
|
||||
* 实名认证
|
||||
* @param password 密码
|
||||
*/
|
||||
public async authentication(name: string, idNum: string) {
|
||||
const ctx = this.ctx;
|
||||
// TODO 接SDK
|
||||
console.log(name, idNum);
|
||||
|
||||
let birthday = this.getBirthdayByIdCard(idNum);
|
||||
let user = await UserModel.authentication(ctx.uid, birthday, '');
|
||||
let param = this.getReturnParam(user);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, param);
|
||||
}
|
||||
|
||||
private getBirthdayByIdCard(idNum: string) {
|
||||
let year = idNum.slice(6,10);
|
||||
let month = idNum.slice(10,12);
|
||||
let date = idNum.slice(12,14);
|
||||
return `${year}-${month}-${date}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user