...
|
...
|
@@ -12,10 +12,13 @@ const _ = require('lodash'); |
|
|
|
|
|
const crypto = global.yoho.crypto;
|
|
|
const AccountApi = require('./account-api');
|
|
|
const CaptchaImgService = require('../../passport/models/captcha-img-service');
|
|
|
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
|
|
|
this.captchaService = new CaptchaImgService(ctx);
|
|
|
}
|
|
|
|
|
|
// 时间转换为时间戳
|
...
|
...
|
@@ -220,7 +223,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
auditCheckStatus(uid, checkType, step) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let accountDataModel = new AccountApi(that.ctx);
|
|
|
let res = yield accountDataModel.getVerifyInfo(uid),
|
|
|
ret = {status: false};
|
...
|
...
|
@@ -236,7 +239,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
|
|
|
if (ischeckMobile && ischeckEmail) {
|
|
|
firstCheck = (that.datetimeToUnix(data.mobileVerifyTime) <=
|
|
|
that.datetimeToUnix(data.emailVerifyTime)) ? 'mobile' : 'email';
|
|
|
that.datetimeToUnix(data.emailVerifyTime)) ? 'mobile' : 'email';
|
|
|
}
|
|
|
|
|
|
let verifyType = 1,
|
...
|
...
|
@@ -313,7 +316,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
getAccountInfo(uid) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
|
|
|
let accountDataModel = new AccountApi(that.ctx);
|
|
|
let resq = [{
|
...
|
...
|
@@ -361,7 +364,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
userPwd(params) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let step = params.step ? parseInt(params.step, 10) : 1,
|
|
|
ckCode = params.checkCode || '',
|
|
|
success = params.success || false,
|
...
|
...
|
@@ -447,7 +450,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
userEmail(params) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
|
|
|
let step = params.step ? parseInt(params.step, 10) : 1,
|
|
|
ckCode = params.checkCode || '',
|
...
|
...
|
@@ -534,7 +537,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
userMobile(params) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let step = params.step ? parseInt(params.step, 10) : 1,
|
|
|
ckCode = params.checkCode || '',
|
|
|
success = params.success || false,
|
...
|
...
|
@@ -621,7 +624,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
sendEmailSuccess(params) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let checkType = params.checkType || 'userpwd',
|
|
|
uid = params.uid,
|
|
|
email = params.email || '',
|
...
|
...
|
@@ -637,7 +640,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
};
|
|
|
}
|
|
|
emailDomain = 'http://' + ((email.split[1] === 'gmail.com') ?
|
|
|
'mail.google.com' : 'mail.' + email.split('@')[1]);
|
|
|
'mail.google.com' : 'mail.' + email.split('@')[1]);
|
|
|
let data = {
|
|
|
subTitle: verifyInfo.subTitle,
|
|
|
enTitle: verifyInfo.enTitle,
|
...
|
...
|
@@ -680,7 +683,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
mailResult(params) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let code = params.code;
|
|
|
let accountDataModel = new AccountApi(that.ctx);
|
|
|
let check = yield accountDataModel.checkEmailCode(code);
|
...
|
...
|
@@ -715,7 +718,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
verifyPassword(req) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let password = _.trim(req.body.password || ''),
|
|
|
uid = req.user.uid,
|
|
|
accountDataModel = new AccountApi(that.ctx);
|
...
|
...
|
@@ -738,7 +741,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
checkPassword(req) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let password = _.trim(req.body.password || ''),
|
|
|
uid = req.user.uid,
|
|
|
resqData = {code: 400},
|
...
|
...
|
@@ -774,7 +777,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
identityMobile(req) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let mobile = req.body.mobile || '',
|
|
|
resqData = {code: 400},
|
|
|
uid = req.user.uid,
|
...
|
...
|
@@ -811,37 +814,40 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
/**
|
|
|
* 向验证手机号发送短信-ajax
|
|
|
*/
|
|
|
sendMobileMsg(req, uid) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
let mobile = req.body.mobile || '',
|
|
|
_code = req.body.checkCode,
|
|
|
resqData = {code: 400};
|
|
|
async sendMobileMsg(req, uid) {
|
|
|
let mobile = req.body.mobile || '',
|
|
|
_code = req.body.checkCode,
|
|
|
resqData = {code: 400};
|
|
|
|
|
|
let accountDataModel = new AccountApi(that.ctx);
|
|
|
let accountDataModel = new AccountApi(this.ctx);
|
|
|
let id = req.session.id;
|
|
|
let captcha = req.body.verifyCode;
|
|
|
|
|
|
// 发送验证码前置数据校验
|
|
|
if (!_code) {
|
|
|
let verifyInfo = yield accountDataModel.getVerifyInfo(uid);
|
|
|
// 发送验证码前置数据校验
|
|
|
if (!_code) {
|
|
|
let verifyInfo = await accountDataModel.getVerifyInfo(uid);
|
|
|
|
|
|
mobile = _.get(verifyInfo, 'data.mobile', '');
|
|
|
if (!mobile) {
|
|
|
return Object.assign(resqData, {
|
|
|
message: '数据验证错误'
|
|
|
});
|
|
|
}
|
|
|
} else if (!that.checkCode(_code, uid)) {
|
|
|
mobile = _.get(verifyInfo, 'data.mobile', '');
|
|
|
if (!mobile) {
|
|
|
return Object.assign(resqData, {
|
|
|
message: '数据验证错误'
|
|
|
});
|
|
|
}
|
|
|
} else if (!this.checkCode(_code, uid)) {
|
|
|
return Object.assign(resqData, {
|
|
|
message: '数据验证错误'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
let mobileInfo = that.handleMobile(mobile);
|
|
|
let mobileInfo = this.handleMobile(mobile);
|
|
|
|
|
|
resqData = yield accountDataModel.sendMobileMsg(uid, mobileInfo.mobile, mobileInfo.area);
|
|
|
return resqData;
|
|
|
})();
|
|
|
resqData = await accountDataModel.sendMobileMsg(uid, mobileInfo.mobile, mobileInfo.area, id, captcha);
|
|
|
|
|
|
let captchaNeeded = await this.captchaService.try();
|
|
|
|
|
|
_.set(resqData, 'data.needCaptcha', captchaNeeded);
|
|
|
|
|
|
return resqData;
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -850,7 +856,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
checkMobileMsg(req, uid) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let mobile = req.body.mobile || '',
|
|
|
code = req.body.code || '',
|
|
|
_code = req.body.checkCode,
|
...
|
...
|
@@ -911,7 +917,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
sendEmail(req) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let uid = req.user.uid,
|
|
|
checkType = req.body.checkType || 'userpwd',
|
|
|
email = req.body.email || '',
|
...
|
...
|
@@ -944,7 +950,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
checkEmail(req) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let uid = req.user.uid,
|
|
|
email = req.body.email || '',
|
|
|
resqData = {code: 400};
|
...
|
...
|
@@ -962,7 +968,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
modifyPwd(req, params) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let uid = params.uid,
|
|
|
newPwd = params.newPwd || '',
|
|
|
_code = params.checkCode;
|
...
|
...
|
@@ -989,7 +995,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
modifyMobile(req, uid) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let mobile = req.body.mobile || '',
|
|
|
code = req.body.code || '',
|
|
|
_code = req.body.checkCode,
|
...
|
...
|
@@ -1044,7 +1050,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
checkMobile(params, uid) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let mobile = params.mobile || '',
|
|
|
resqData = {code: 400};
|
|
|
|
...
|
...
|
@@ -1063,7 +1069,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
modifyEmail(req) {
|
|
|
let that = this;
|
|
|
|
|
|
return co(function*() {
|
|
|
return co(function* () {
|
|
|
let uid = req.user.uid,
|
|
|
email = req.body.email || '',
|
|
|
_code = req.body.checkCode,
|
...
|
...
|
|