Authored by 姜枫

update yoho-node-lib

... ... @@ -5,31 +5,31 @@
'use strict';
const helpers = global.yoho.helpers;
const api = require('./back-api');
const api = require('./back-api');
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const moment = require('moment');
const co = Promise.coroutine;
const _ = require('lodash');
const moment = require('moment');
const userService = require('./user-service');
const userService = require('./user-service');
const passportHelper = require('./passport-helper');
const authHelper = require('./auth-helper');
const authHelper = require('./auth-helper');
const BACK_LEFT_BANNER_CODE = '3bbaf502c447a2ddad60879042e286d8'; //找回密码左边的banner
const BACK_LEFT_BANNER_CODE = '3bbaf502c447a2ddad60879042e286d8'; // 找回密码左边的banner
const validateEmailOrMobileAsync = (userInput, areaCode) => {
return new Promise(function (resolve, rejected) {
return new Promise(function(resolve, rejected) {
let result = {type: 'email', area: '', phone: ''};
if (helpers.verifyEmail(userInput)) {
result.type = 'email';
result.area = '';
result.type = 'email';
result.area = '';
result.phone = userInput;
resolve(result);
} else if (helpers.verifyAreaMobile(helpers.makeAreaMobile(areaCode, userInput))) {
result.type = 'mobile';
result.area = areaCode;
result.type = 'mobile';
result.area = areaCode;
result.phone = userInput;
resolve(result);
... ... @@ -44,12 +44,12 @@ const findUserAsync = (type, phone, area) => {
return co(function * () {
const MESSAGE = {
mobile: '您输入的手机号码尚未注册!',
email : '您输入的邮件账户尚未注册!',
ok : '验证成功'
email: '您输入的邮件账户尚未注册!',
ok: '验证成功'
};
const findBy = {
email : userService.findByEmailAsync,
email: userService.findByEmailAsync,
mobile: userService.findByMobileAsync
};
... ... @@ -59,7 +59,7 @@ const findUserAsync = (type, phone, area) => {
if (_.isEmpty(user)) {
return {
code : 402,
code: 402,
message: MESSAGE[type]
};
}
... ... @@ -78,7 +78,7 @@ const _sendCodeToEmailAsync = input => {
}).catch(() => {
return {};
});
}
};
const _sendCodeToMobileAsync = (areaCode, userInput) => {
return api.sendCodeToMobileAsync(areaCode, userInput).then(result => {
... ... @@ -90,11 +90,11 @@ const _sendCodeToMobileAsync = (areaCode, userInput) => {
}).catch(() => {
return {};
});
}
};
const sendCodeToUserAsync = (type, mobile, areaCode) => {
let sendTo = {
email : _sendCodeToEmailAsync,
email: _sendCodeToEmailAsync,
mobile: _sendCodeToMobileAsync
};
... ... @@ -113,27 +113,27 @@ const sendCodeToMobileAsync = (areaCode, mobile) => {
*/
const indexPageDataAsync = () => {
return co(function *() {
let banner = yield passportHelper.getLeftBannerAsync(BACK_LEFT_BANNER_CODE);
let banner = yield passportHelper.getLeftBannerAsync(BACK_LEFT_BANNER_CODE);
let countryList = passportHelper.getCountry();
return {
back: {
coverHref : banner.url,
coverImg : banner.img,
coverHref: banner.url,
coverImg: banner.img,
countryCode: 86,
countryName: "中国",
captchaUrl : helpers.urlFormat('/passport/images', {t: moment().unix()}),
countryName: '中国',
captchaUrl: helpers.urlFormat('/passport/images', {t: moment().unix()}),
countryList: countryList
}
}
};
})();
};
const verifyCodyByMobileAsync = (area, mobile, mobileCode) => {
const ERR = {
code : 400,
code: 400,
message: '验证码错误!',
data : helpers.urlFormat('/passport/back/index.html')
data: helpers.urlFormat('/passport/back/index.html')
};
api.validateMobileCodeAsync(mobile, mobileCode, area)
... ... @@ -143,19 +143,19 @@ const verifyCodyByMobileAsync = (area, mobile, mobileCode) => {
}
let data = {
mobile : mobile,
area : area,
token : result.data.token,
mobile: mobile,
area: area,
token: result.data.token,
create_time: moment().unix()
};
data.code = new Buffer(authHelper.makeToken(data)).toString('base64');
return {
code : 200,
code: 200,
message: '验证成功',
data : helpers.urlFormat('/passport/back/backcode', data)
data: helpers.urlFormat('/passport/back/backcode', data)
};
})
});
};
... ... @@ -168,7 +168,7 @@ const authRequest = (data, token) => {
let isExpired = (moment().unix() - data.create_time) > existTime;
if (isExpired) {
return {}
return {};
} else {
return data;
}
... ... @@ -177,23 +177,23 @@ const authRequest = (data, token) => {
const updatePwdAsync = (emailToken, mobileToken, newPassword) => {
return co(function * () {
let result = {type: 'mobile', status: false};
const ERR = {type: '', status: false};
const ERR = {type: '', status: false};
if (!_.isEmpty(mobileToken)) {
if (!mobileToken.mobile || mobileToken.uid) {
return ERR;
}
let mobile = mobileToken.mobile;
let area = mobileToken.area;
let token = mobileToken.token;
let mobile = mobileToken.mobile;
let area = mobileToken.area;
let token = mobileToken.token;
let modifyStatus = yield api.modifyPasswordByMobileAsync(mobile, token, newPassword, area);
if (!modifyStatus.code || modifyStatus.code !== 200) {
return ERR;
}
result.type = 'mobile';
result.type = 'mobile';
result.status = true;
} else {
let modifyStatus = yield api.modifyPasswordByEmailCodeAsync(emailToken, newPassword);
... ... @@ -202,7 +202,7 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => {
return ERR;
}
result.type = 'email';
result.type = 'email';
result.status = true;
}
... ...
... ... @@ -7,8 +7,8 @@
const helpers = global.yoho.helpers;
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const co = Promise.coroutine;
const _ = require('lodash');
const indexService = require('./index-service');
... ... @@ -27,6 +27,7 @@ module.exports.getLeftBannerAsync = (resourceCode) => {
}
let value = {};
// 有点问题 // passport model 58
value.img = helpers.image(resource[0].data[0].src, 252, 190);
value.url = resource[0].data[0].url;
... ... @@ -40,62 +41,62 @@ module.exports.getCountry = () => {
{
areaCode: '+61',
selected: false,
name : '澳大利亚'
name: '澳大利亚'
},
{
areaCode: '+82',
selected: false,
name : '韩国'
name: '韩国'
},
{
areaCode: '+1',
selected: false,
name : '加拿大'
name: '加拿大'
},
{
areaCode: '+60',
selected: false,
name : '马来西亚'
name: '马来西亚'
},
{
areaCode: '+1',
selected: false,
name : '美国'
name: '美国'
},
{
areaCode: '+81',
selected: false,
name : '日本'
name: '日本'
},
{
areaCode: '+65',
selected: false,
name : '新加坡'
name: '新加坡'
},
{
areaCode: '+44',
selected: false,
name : '英国'
name: '英国'
},
{
areaCode: '+86',
selected: true,
name : '中国'
name: '中国'
},
{
areaCode: '+853',
selected: false,
name : '中国澳门'
name: '中国澳门'
},
{
areaCode: '+886',
selected: false,
name : '中国台湾'
name: '中国台湾'
},
{
areaCode: '+852',
selected: false,
name : '中国香港'
name: '中国香港'
}
];
};
... ...