...
|
...
|
@@ -10,6 +10,7 @@ |
|
|
const helpers = require(global.library + '/helpers');
|
|
|
const RegService = require('../models/reg-service');
|
|
|
const BindService = require('../models/bind-service');
|
|
|
const AuthHelper = require('../models/auth-helper');
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
const Sources = {
|
...
|
...
|
@@ -90,14 +91,14 @@ const bind = { |
|
|
|
|
|
if (result.code === 200) {
|
|
|
let nextUrl = helpers.urlFormat('/passport/bind/code', {
|
|
|
isReg: res.data.is_register, // esline-disable-line
|
|
|
isReg: result.data.is_register, // esline-disable-line
|
|
|
openId: openId,
|
|
|
sourceType: sourceType,
|
|
|
areaCode: areaCode,
|
|
|
phoneNum: phoneNum
|
|
|
});
|
|
|
|
|
|
data.data.isReg = res.data.is_register;
|
|
|
data.data.isReg = result.data.is_register;
|
|
|
data.data.next = nextUrl;
|
|
|
} else {
|
|
|
data.data = result.data;
|
...
|
...
|
@@ -112,6 +113,142 @@ const bind = { |
|
|
data: ''
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
|
|
|
sendBindMsg: (req, res) => {
|
|
|
let phoneNum = req.body.phoneNum;
|
|
|
let areaCode = req.body.areaCode;
|
|
|
|
|
|
if (req.xhr && _.isNumber(parseInt(phoneNum, 0)) && areaCode) {
|
|
|
BindService.sendBindMsg(areaCode, phoneNum).then(result => {
|
|
|
if (result && result.code) {
|
|
|
res.json(result);
|
|
|
} else {
|
|
|
res.json({ code: 400, message: '', data: '' });
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
res.json({ code: 400, message: '', data: '' });
|
|
|
}
|
|
|
},
|
|
|
|
|
|
checkBindMsg: (req, res) => {
|
|
|
let phoneNum = req.body.phoneNum;
|
|
|
let code = req.body.code;
|
|
|
let areaCode = req.body.areaCode;
|
|
|
|
|
|
if (_.isNumber(parseInt(phoneNum, 0)) && code && areaCode) {
|
|
|
BindService.checkBindMsg(areaCode, phoneNum, code).then(result => {
|
|
|
if (result && result.code) {
|
|
|
res.json(result);
|
|
|
} else {
|
|
|
res.json({ code: 400, message: '', data: '' });
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
res.json({ code: 400, message: '', data: '' });
|
|
|
}
|
|
|
},
|
|
|
|
|
|
bindMobile: (req, res) => {
|
|
|
let phoneNum = req.body.phoneNum;
|
|
|
let openId = req.body.openId;
|
|
|
let areaCode = req.body.areaCode || '86';
|
|
|
let sourceType = req.body.sourceType;
|
|
|
let code = req.body.code;
|
|
|
let password = req.body.password || '';
|
|
|
|
|
|
if (_.isNumber(parseInt(phoneNum)) && openId && sourceType && areaCode && code) {
|
|
|
BindService.checkBindCode(areaCode, phoneNum, code).then(result => {
|
|
|
if (result && result.code && result.code === 200) {
|
|
|
return BindService.bindMobile(openId, sourceType, phoneNum, areaCode, password);
|
|
|
} else {
|
|
|
return { code: 400, message: '短信验证码错误', data: '' };
|
|
|
}
|
|
|
}).then(result => {
|
|
|
let refer = req.cookies.refer;
|
|
|
|
|
|
refer = refer ? decodeURI(refer) : helpers.urlFormat();
|
|
|
if (result && result.code && result.code === 200 && result.data.uid) {
|
|
|
AuthHelper.syncUserSession(result.data.uid, req, res);
|
|
|
result.data.refer = refer;
|
|
|
}
|
|
|
return result;
|
|
|
}).then(result => {
|
|
|
res.json(result);
|
|
|
});
|
|
|
} else {
|
|
|
res.json({ code: 400, message: '', data: '' });
|
|
|
}
|
|
|
},
|
|
|
|
|
|
relateMobile: (req, res) => {
|
|
|
let phoneNum = req.body.phoneNum;
|
|
|
let openId = req.body.openId;
|
|
|
let areaCode = req.body.areaCode || '86';
|
|
|
let sourceType = req.body.sourceType;
|
|
|
let code = req.body.code;
|
|
|
|
|
|
if (_.isNumber(parseInt(phoneNum, 0)) && openId && areaCode && sourceType && code) {
|
|
|
BindService.checkBindCode(areaCode, phoneNum, code).then(result => {
|
|
|
if (result && result.code && result.code === 200) {
|
|
|
return BindService.relateMobile(openId, sourceType, phoneNum, code);
|
|
|
} else {
|
|
|
return { code: 400, message: '短信验证码错误', data: '' };
|
|
|
}
|
|
|
}).then(result => {
|
|
|
let refer = helpers.urlFormat('/passport/bind/success', { sourceType: sourceType });
|
|
|
|
|
|
if (result && result.code && result.code === 200 && result.data.uid) {
|
|
|
AuthHelper.syncUserSession(result.data.uid, req, res);
|
|
|
result.data.refer = refer;
|
|
|
}
|
|
|
return result;
|
|
|
}).then(result => {
|
|
|
res.json(result);
|
|
|
});
|
|
|
} else {
|
|
|
res.json({ code: 400, message: '', data: '' });
|
|
|
}
|
|
|
},
|
|
|
|
|
|
successPage: (req, res) => {
|
|
|
res.render('bind/success', {
|
|
|
isPassportPage: true,
|
|
|
successTip: '恭喜您,第三方账号关联手机号码成功!',
|
|
|
goUrl: helpers.urlFormat(),
|
|
|
module: 'passport',
|
|
|
page: 'bind-success',
|
|
|
title: '绑定手机号'
|
|
|
});
|
|
|
},
|
|
|
|
|
|
changeCheck: (req, res) => {
|
|
|
let phoneNum = req.body.phoneNum;
|
|
|
let areaCode = req.body.areaCode;
|
|
|
|
|
|
if (_.isNumber(parseInt(phoneNum, 0)) && areaCode) {
|
|
|
BindService.changeCheck(phoneNum, areaCode).then(result => {
|
|
|
res.json(result);
|
|
|
});
|
|
|
} else {
|
|
|
res.json({ code: 400, message: '', data: '' });
|
|
|
}
|
|
|
},
|
|
|
|
|
|
changeMobile: (req, res) => {
|
|
|
let uid = req.user.uid;
|
|
|
let phoneNum = req.body.phoneNum;
|
|
|
let areaCode = req.body.areaCode;
|
|
|
let code = req.body.code;
|
|
|
|
|
|
if (_.isNumber(parseInt(phoneNum)) && uid && areaCode && code) {
|
|
|
BindService.changeMobile(uid, phoneNum, areaCode, code).then(result => {
|
|
|
res.json(result);
|
|
|
});
|
|
|
} else {
|
|
|
res.json({ code: 400, message: '', data: '' });
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
|