...
|
...
|
@@ -17,8 +17,6 @@ const config = global.yoho.config; |
|
|
const cert = {
|
|
|
index: (req, res) => {
|
|
|
let refer = req.query.refer || `${config.siteUrl}`;
|
|
|
let username = req.query.username;
|
|
|
let password = req.query.password;
|
|
|
|
|
|
res.render('cert/index', {
|
|
|
region: passportHelper.getCountry(),
|
...
|
...
|
@@ -29,8 +27,6 @@ const cert = { |
|
|
simpleHeader: simpleHeaderModel.setSimpleHeaderData(),
|
|
|
module: 'passport',
|
|
|
page: 'cert',
|
|
|
username,
|
|
|
password,
|
|
|
title: '登录完善信息'
|
|
|
});
|
|
|
},
|
...
|
...
|
@@ -93,45 +89,26 @@ const cert = { |
|
|
check: (req, res, next) => {
|
|
|
let mobile = req.body.mobile;
|
|
|
let area = req.body.area || '86';
|
|
|
let code = req.body.code;
|
|
|
|
|
|
if (mobile && area) {
|
|
|
|
|
|
/**
|
|
|
* 接口绑定返回值:
|
|
|
* code:200,isCanBind=Y // 可绑定
|
|
|
* code:200,isCanBind=Y // 不可绑定
|
|
|
*/
|
|
|
|
|
|
req.ctx(CertService).certCheck(mobile, area).then(result => {
|
|
|
if (!result || !result.code) {
|
|
|
return {code: 400, message: '', data: ''};
|
|
|
} else if (result.code === 200) {
|
|
|
let nextUrl;
|
|
|
|
|
|
if (_.get(result, 'data.isCanBind') === 'Y') {
|
|
|
nextUrl = helpers.urlFormat('/passport/cert/cert');
|
|
|
return {code: 200, message: result.message, data: {next: nextUrl}};
|
|
|
} else {
|
|
|
// 不可以关联
|
|
|
return {code: 403, message: '绑定失败,该手机号已注册,请更换或使用该手机号直接登录'};
|
|
|
}
|
|
|
} else {
|
|
|
return {code: result.code, message: result.message, data: result.data ? result.data : ''};
|
|
|
}
|
|
|
}).then(result => {
|
|
|
return res.json(result);
|
|
|
}).catch(next);
|
|
|
} else {
|
|
|
if (!mobile || !area || !code) {
|
|
|
return res.json({code: 400, message: '', data: ''});
|
|
|
}
|
|
|
|
|
|
req.ctx(CertService).certCheck(mobile, area, code).then(({error, result}) => {
|
|
|
if (error) {
|
|
|
return res.json({code: 400, message: '验证错误,请重新登录', data: ''});
|
|
|
}
|
|
|
|
|
|
return res.json({code: 200, data: result});
|
|
|
}).catch(next);
|
|
|
},
|
|
|
sendCertMsg: (req, res, next) => {
|
|
|
let mobile = req.body.mobile;
|
|
|
let area = req.body.area;
|
|
|
let id = req.session.id;
|
|
|
let captcha = req.body.verifyCode;
|
|
|
|
|
|
req.ctx(CertService).sendCertMsg(mobile, area, id, captcha).then(result => {
|
|
|
req.ctx(CertService).sendCertMsg(mobile, area).then(result => {
|
|
|
console.log(result);
|
|
|
if (result && result.code) {
|
|
|
return res.json(result);
|
|
|
} else {
|
...
|
...
|
@@ -140,37 +117,48 @@ 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 code = _.trim(req.body.code);
|
|
|
let refer = req.body.refer;
|
|
|
|
|
|
req.ctx(CertService).certMobile(uid, mobile, code, area).then(result => {
|
|
|
if (!code) {
|
|
|
return {
|
|
|
code: 400,
|
|
|
message: '短信验证码错误'
|
|
|
};
|
|
|
}
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
let url = helpers.urlFormat('/passport/cert/success', {
|
|
|
type: 'cert',
|
|
|
refer: refer
|
|
|
});
|
|
|
if (!req.session.forceBind ||
|
|
|
!req.session.forceBind.username ||
|
|
|
!req.session.forceBind.password
|
|
|
) {
|
|
|
return {
|
|
|
code: 400,
|
|
|
message: '请重新登录'
|
|
|
};
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
code: 200,
|
|
|
message: result.message,
|
|
|
data: {
|
|
|
nextUrl: url
|
|
|
}
|
|
|
};
|
|
|
} else {
|
|
|
return {
|
|
|
code: _.get(result, 'code', 400),
|
|
|
req.ctx(CertService).certMobile(
|
|
|
req.session.forceBind.username,
|
|
|
req.session.forceBind.password,
|
|
|
mobile, code, area
|
|
|
).then(result => {
|
|
|
delete req.session.forceBind;
|
|
|
|
|
|
if (!result || result.code !== 200) {
|
|
|
return res.json({
|
|
|
code: 400,
|
|
|
message: _.get(result, 'message') || '操作错误,请稍后再试!'
|
|
|
};
|
|
|
});
|
|
|
}
|
|
|
}).then(result => {
|
|
|
res.json(result);
|
|
|
}).catch(next);
|
|
|
|
|
|
return res.json({
|
|
|
code: 200
|
|
|
});
|
|
|
}).catch(() => {
|
|
|
delete req.session.forceBind;
|
|
|
next();
|
|
|
});
|
|
|
},
|
|
|
relateMobile: (req, res, next) => {
|
|
|
let uid = req.user.uid;
|
...
|
...
|
|