...
|
...
|
@@ -5,6 +5,7 @@ const uuid = require('uuid'); |
|
|
const passport = require('passport');
|
|
|
const TaobaoStrategy = require('./passport-taobao');
|
|
|
const authcode = require('../../utils/authcode');
|
|
|
const redis = require('../../utils/redis');
|
|
|
const aes = require('./aes');
|
|
|
|
|
|
const log = global.yoho.logger;
|
...
|
...
|
@@ -15,6 +16,7 @@ const loginPage = '//m.yohobuy.com/signin.html'; |
|
|
const homePage = `${config.siteUrl}/xianyu/channel`;
|
|
|
|
|
|
const URL_BIND_KEY = 'bind_code';
|
|
|
const MAX_MSG_SEND_TIMES = 20;
|
|
|
|
|
|
// taobao 登录
|
|
|
passport.use('taobao', new TaobaoStrategy({
|
...
|
...
|
@@ -43,7 +45,7 @@ class passportModel extends global.yoho.BaseModel { |
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
signinByOpenID({ nickname, openId, sourceType, businessLine}) {
|
|
|
signinByOpenID({ nickname, openId, sourceType, sourceTypeSecond, businessLine}) {
|
|
|
let param = {
|
|
|
nickname: nickname || '',
|
|
|
openId: openId,
|
...
|
...
|
@@ -55,6 +57,10 @@ class passportModel extends global.yoho.BaseModel { |
|
|
param.business_line = businessLine;
|
|
|
}
|
|
|
|
|
|
if (sourceTypeSecond) {
|
|
|
param.source_type_second = sourceTypeSecond;
|
|
|
}
|
|
|
|
|
|
return this.get({ data: param });
|
|
|
}
|
|
|
syncUserSession({uid, sessionKey, req, res}) {
|
...
|
...
|
@@ -119,25 +125,33 @@ class passportModel extends global.yoho.BaseModel { |
|
|
log.info(`[sync profile error] uid: ${uid} | err: ${JSON.stringify(e)}`);
|
|
|
});
|
|
|
}
|
|
|
sendTaobaoBindCode(mobile) {
|
|
|
return this.post({
|
|
|
data: {
|
|
|
method: 'app.bind.sendCodeByTB',
|
|
|
source_type: 'taobao',
|
|
|
mobile
|
|
|
}
|
|
|
});
|
|
|
sendTaobaoBindCode(mobile, sourceTypeSecond) {
|
|
|
let data = {
|
|
|
method: 'app.bind.sendCodeByTB',
|
|
|
source_type: 'taobao',
|
|
|
mobile
|
|
|
};
|
|
|
|
|
|
if (sourceTypeSecond) {
|
|
|
data.source_type_second = sourceTypeSecond;
|
|
|
}
|
|
|
|
|
|
return this.post({ data });
|
|
|
}
|
|
|
bindTaobaoAccountByCode({ mobile, code, openId }) {
|
|
|
return this.post({
|
|
|
data: {
|
|
|
method: 'app.bind.bindTBByCode',
|
|
|
source_type: 'taobao',
|
|
|
mobile,
|
|
|
code,
|
|
|
open_id: openId
|
|
|
}
|
|
|
});
|
|
|
bindTaobaoAccountByCode({ mobile, code, openId, sourceTypeSecond }) {
|
|
|
let data = {
|
|
|
method: 'app.bind.bindTBByCode',
|
|
|
source_type: 'taobao',
|
|
|
mobile,
|
|
|
code,
|
|
|
open_id: openId
|
|
|
};
|
|
|
|
|
|
if (sourceTypeSecond) {
|
|
|
data.source_type_second = sourceTypeSecond;
|
|
|
}
|
|
|
|
|
|
return this.post({ data });
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -161,7 +175,8 @@ const login = { |
|
|
|
|
|
return model.signinByOpenID({
|
|
|
openId: user.open_uid,
|
|
|
sourceType: 'taobao'
|
|
|
sourceType: 'taobao',
|
|
|
sourceTypeSecond: req.yoho.isAliApp ? 'xianyu' : ''
|
|
|
}).then(result => {
|
|
|
let redirectUrl = loginPage;
|
|
|
|
...
|
...
|
@@ -213,12 +228,27 @@ const bind = { |
|
|
|
|
|
return bindInfo;
|
|
|
},
|
|
|
sendSms(req, res, next) {
|
|
|
async sendSms(req, res, next) {
|
|
|
let { mobile, bindCode } = req.body || {};
|
|
|
let info = bind.getBindThirdInfo(bindCode);
|
|
|
|
|
|
if (info.type === 'taobao') {
|
|
|
req.ctx(passportModel).sendTaobaoBindCode(mobile).then(res.json).catch(next);
|
|
|
const timeKey = `${config.app}:bindsms:taobao:${info.openId}`;
|
|
|
let sendTimes = await redis.getAsync(timeKey);
|
|
|
|
|
|
sendTimes = (sendTimes || 0) + 1;
|
|
|
|
|
|
if (sendTimes > MAX_MSG_SEND_TIMES) {
|
|
|
log.info(`[SMS delivery times exceeded] type: taobao | openId: ${info.openId} | mobile: ${mobile} | ua: ${req.get('user-agent')}`);
|
|
|
|
|
|
return res.json({
|
|
|
code: 403,
|
|
|
message: '操作频繁,请稍后重试'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
redis.setex(timeKey, 60 * 60 * 2, sendTimes);
|
|
|
req.ctx(passportModel).sendTaobaoBindCode(mobile, req.yoho.isAliApp ? 'xianyu' : '').then(res.json).catch(next);
|
|
|
} else {
|
|
|
res.json({
|
|
|
code: 200,
|
...
|
...
|
@@ -236,7 +266,8 @@ const bind = { |
|
|
model.bindTaobaoAccountByCode({
|
|
|
mobile,
|
|
|
code,
|
|
|
openId: info.openId
|
|
|
openId: info.openId,
|
|
|
sourceTypeSecond: req.yoho.isAliApp ? 'xianyu' : ''
|
|
|
}).then(result => {
|
|
|
if (_.get(result, 'data.is_bind') === 'Y') {
|
|
|
model.syncUserSession({
|
...
|
...
|
|