...
|
...
|
@@ -10,21 +10,9 @@ const _ = require('lodash'); |
|
|
const helpers = global.yoho.helpers;
|
|
|
const passportHelper = require('../models/passport-helper');
|
|
|
const certService = require('../models/cert-service');
|
|
|
const loginService = require('../models/login-service');
|
|
|
const userService = require('../models/user-service');
|
|
|
|
|
|
// const UserService = require('../models/user-service');
|
|
|
const simpleHeaderModel = require('../../../doraemon/models/simple-header');
|
|
|
|
|
|
const Sources = {
|
|
|
qq: 'QQ',
|
|
|
sina: '微博',
|
|
|
alipay: '支付宝',
|
|
|
wechat: '微信',
|
|
|
renren: '人人',
|
|
|
douban: '豆瓣'
|
|
|
};
|
|
|
|
|
|
const cert = {
|
|
|
tip: (req, res) => {
|
|
|
let refer = req.query.refer;
|
...
|
...
|
@@ -77,17 +65,15 @@ const cert = { |
|
|
title: '账号关联'
|
|
|
});
|
|
|
|
|
|
res.render('bind/relate', data);
|
|
|
res.render('cert/relate', data);
|
|
|
}).catch(next);
|
|
|
},
|
|
|
success: (req, res) => {
|
|
|
let sourceType = _.trim(req.query.sourceType);
|
|
|
let sourceInfo = sourceType.split('_');
|
|
|
let sourceName = Sources[sourceInfo[0]];
|
|
|
let isRelate = (sourceInfo[1] === 'relate');
|
|
|
let type = _.trim(req.query.type);
|
|
|
let refer = req.query.refer;
|
|
|
let isRelate = (type === 'relate');
|
|
|
let data = {
|
|
|
goShopping: helpers.urlFormat('/'),
|
|
|
sourceName: sourceName,
|
|
|
goShopping: refer,
|
|
|
relate: isRelate,
|
|
|
module: 'passport',
|
|
|
page: 'cert-success',
|
...
|
...
|
@@ -95,16 +81,12 @@ const cert = { |
|
|
title: '绑定手机号'
|
|
|
};
|
|
|
|
|
|
res.render('bind/success', data);
|
|
|
res.render('cert/success', data);
|
|
|
},
|
|
|
check: (req, res, next) => {
|
|
|
let mobile = req.body.mobile;
|
|
|
|
|
|
// let openId = req.body.openId;
|
|
|
let area = req.body.area || '86';
|
|
|
|
|
|
// let sourceType = req.body.sourceType;
|
|
|
|
|
|
if (mobile && area) {
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -148,75 +130,81 @@ const cert = { |
|
|
}).catch(next);
|
|
|
},
|
|
|
certMobile: (req, res, next) => {
|
|
|
|
|
|
let uid = req.user.uid;
|
|
|
let mobile = _.trim(req.body.mobile);
|
|
|
let area = _.trim(req.body.area) || '86';
|
|
|
let openId = _.trim(req.body.openId);
|
|
|
let sourceType = _.trim(req.body.sourceType);
|
|
|
let code = _.trim(req.body.code);
|
|
|
let password = _.trim(req.body.password) || '';
|
|
|
let refer = req.body.refer;
|
|
|
|
|
|
bindService.checkBindCode(area, mobile, code).then(result => {
|
|
|
if (result && result.code !== 200) {
|
|
|
return {code: 402, message: '短信验证码不正确', data: ''};
|
|
|
} else {
|
|
|
return bindService.bindMobile(openId, sourceType, mobile, area, password);
|
|
|
}
|
|
|
}).then(result => {
|
|
|
if (result && result.code) {
|
|
|
if (result.code === 200 && result.data && result.data.uid) {
|
|
|
let refer = helpers.urlFormat('/passport/thirdlogin/bindsuccess', {
|
|
|
sourceType: sourceType + '_bind'
|
|
|
});
|
|
|
certService.certMobile(uid, mobile, code, area).then(result => {
|
|
|
|
|
|
return loginService.syncUserSession(result.data.uid, req, res).then(() => {
|
|
|
return {code: 200, message: result.message, data: {refer: refer}};
|
|
|
});
|
|
|
} else {
|
|
|
return {code: result.code, message: result.message, data: {refer: ''}};
|
|
|
}
|
|
|
if (result && result.code === 200) {
|
|
|
let url = helpers.urlFormat('/passport/cert/success', {
|
|
|
type: 'cert',
|
|
|
refer: refer
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
code: 200,
|
|
|
message: result.message,
|
|
|
data: {
|
|
|
nextUrl: url
|
|
|
}
|
|
|
};
|
|
|
} else {
|
|
|
return {code: 400, message: '', data: ''};
|
|
|
return {
|
|
|
code: _.get(result, 'code', 400),
|
|
|
message: _.get(result, 'message')
|
|
|
};
|
|
|
}
|
|
|
}).then(result => {
|
|
|
return res.json(result);
|
|
|
res.json(result);
|
|
|
}).catch(next);
|
|
|
},
|
|
|
relateMobile: (req, res, next) => {
|
|
|
let mobile = req.body.mobile;
|
|
|
let openId = req.body.openId;
|
|
|
let areaCode = req.body.areaCode || '86';
|
|
|
let sourceType = req.body.sourceType;
|
|
|
let code = req.body.code;
|
|
|
|
|
|
if (_.toNumber(mobile) && openId && areaCode && sourceType && code) {
|
|
|
bindService.checkBindCode(areaCode, mobile, code).then(result => {
|
|
|
if (result && result.code && result.code === 200) {
|
|
|
return bindService.relateMobile(openId, sourceType, mobile, areaCode);
|
|
|
} else {
|
|
|
return {code: 402, message: '短信验证码错误', data: ''};
|
|
|
}
|
|
|
}).then(result => {
|
|
|
if (result && result.code) {
|
|
|
if (result.code === 200 && result.data && result.data.uid) {
|
|
|
let refer = helpers.urlFormat('/passport/thirdlogin/bindsuccess', {
|
|
|
sourceType: sourceType + '_relate'
|
|
|
});
|
|
|
|
|
|
return loginService.syncUserSession(result.data.uid, req, res).then(() => {
|
|
|
return {code: 200, message: result.message, data: {refer: refer}};
|
|
|
});
|
|
|
} else {
|
|
|
return {code: result.code, message: result.message, data: {refer: ''}};
|
|
|
}
|
|
|
let uid = req.user.uid;
|
|
|
let mobile = _.trim(req.body.mobile);
|
|
|
let area = _.trim(req.body.areaCode) || '86';
|
|
|
let code = _.trim(req.body.code);
|
|
|
let refer = req.body.refer;
|
|
|
let email;
|
|
|
|
|
|
userService.profile(uid).then(info => {
|
|
|
|
|
|
if (info && info.code === 200) {
|
|
|
email = _.get(info, 'data.email');
|
|
|
} else {
|
|
|
res.json({
|
|
|
code: 400,
|
|
|
message: '系统错误,请稍后再试!'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
certService.relateMobile(uid, email, code, mobile, area).then(result => {
|
|
|
if (result && result.code === 200) {
|
|
|
let url = helpers.urlFormat('/passport/cert/success', {
|
|
|
type: 'relate',
|
|
|
refer: refer
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
code: 200,
|
|
|
message: result.message,
|
|
|
data: {
|
|
|
nextUrl: url
|
|
|
}
|
|
|
};
|
|
|
} else {
|
|
|
return {code: 400, message: '', data: ''};
|
|
|
return {
|
|
|
code: _.get(result, 'code', 400),
|
|
|
message: _.get(result, 'message')
|
|
|
};
|
|
|
}
|
|
|
}).then(result => {
|
|
|
return res.json(result);
|
|
|
res.json(result);
|
|
|
}).catch(next);
|
|
|
} else {
|
|
|
return res.json({code: 400, message: '', data: ''});
|
|
|
}
|
|
|
}).catch(next);
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
|