Authored by 毕凯

Merge branch 'feature/back' into feature/passport

... ... @@ -5,19 +5,30 @@
'use strict';
const library = '../../../library';
const helpers = require(`${library}/helpers`);
const service = require('../models/back-service');
const helpers = global.yoho.helpers;
const service = require('../models/back-service');
const passportHelper = require('../models/passport-helper');
const moment = require('moment');
// 本地地址 localhost
helpers.urlFormat = helpers.fakeUrlFormat;
const _ = require('lodash');
//helpers.urlFormat = (url, qs) => {
// let localhost = 'http://localhost:6002';
//
// if (_.isEmpty(qs)) {
// return localhost + url;
// }
//
// const queryString = require('queryString');
//
// let str = queryString.stringify(qs);
//
// return localhost + url + '?' + str;
//
//};
/**
* 找回密码主页面
*/
const indexPage = (req, res, next) => {
const index = (req, res, next) => {
service.indexPageDataAsync()
.then(result => {
res.render('back/index', Object.assign({
... ... @@ -34,12 +45,11 @@ const indexPage = (req, res, next) => {
*/
const validateInputAPI = (req, res, next) => {
let userInput = req.body.phoneNum || '';
let areaCode = (req.body.area || '86').replace('+', '');
let areaCode = (req.body.area || '86').replace('+', '');
service.validateEmailOrMobileAsync(userInput, areaCode)
.then(result => {
req.inputInfo = result;
console.log(result);
next();
})
.catch(err => {
... ... @@ -55,7 +65,7 @@ const validateInputAPI = (req, res, next) => {
*/
const validateUserPage = (req, res, next) => {
let userInput = req.body.phoneNum || '';
let areaCode = (req.body.area || '86').replace('+', '');
let areaCode = (req.body.area || '86').replace('+', '');
service.validateEmailOrMobileAsync(userInput, areaCode)
.then(result => {
... ... @@ -63,7 +73,7 @@ const validateUserPage = (req, res, next) => {
next();
})
.catch(()=> {
res.redirect(helpers.urlFormat('/passport/back/index.html'));
res.redirect(helpers.urlFormat('/passport/back/index'));
});
};
... ... @@ -82,16 +92,14 @@ const sendCodePage = (req, res, next) => {
service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
.then(result => {
if (_.isEmpty(result)) {
res.redirect(helpers.urlFormat('/passport/back/index.html'));
if (result.code && result.code === 200) {
return next();
} else {
next();
return res.redirect(helpers.urlFormat('/passport/back/index'));
}
})
.catch(() => {
res.redirect(helpers.urlFormat('/passport/back/index.html'));
});
.catch(next);
};
const saveInSession = (req, res) => {
... ... @@ -99,24 +107,27 @@ const saveInSession = (req, res) => {
case 'email':
{
req.session.email = req.inputInfo.phone;
res.redirect(helpers.urlFormat('/passport/back/sendEmail.html'));
res.redirect(helpers.urlFormat('/passport/back/sendEmail'));
break;
}
case 'mobile':
{
req.session.mobile = req.inputInfo.phone;
req.session.area = req.inputInfo.area;
res.redirect(helpers.urlFormat('/passport/back/verification.html'));
req.session.area = req.inputInfo.area;
res.redirect(helpers.urlFormat('/passport/back/verification'));
break;
}
default:
{
res.redirect(helpers.urlFormat('/passport/back/index.html'));
res.redirect(helpers.urlFormat('/passport/back/index'));
}
}
};
const sendBackMobileAPI = (req, res, next) => {
let mobile = req.body.mobile || '';
let area = req.body.area || '86';
service.sendCodeToMobileAsync(area, mobile)
.then(result => {
res.json(result);
... ... @@ -126,15 +137,13 @@ const sendBackMobileAPI = (req, res, next) => {
const validateMobileAPI = (req, res, next) => {
let mobile = req.body.mobile || '';
let area = req.body.area || '86';
const ERR = {code: 400, message: '验证失败'};
if (!helpers.verifyAreaMobile(helpers.makeAreaMobile(area, mobile))) {
res.json(ERR);
if (!passportHelper.validator.isAreaMobile(passportHelper.makeAreaMobile(area, mobile))) {
return res.json(ERR);
} else {
next();
return next();
}
};
... ... @@ -142,7 +151,7 @@ const validateEmailInSession = (req, res, next) => {
let email = req.session.email || '';
if (!email) {
res.redirect(helpers.urlFormat('/passport/back/index.html'));
res.redirect(helpers.urlFormat('/passport/back/index'));
}
const mapperEmailISP = {
... ... @@ -161,7 +170,7 @@ const sendEmailPage = (req, res, next) => {
res.render('back/send-email', Object.assign({
module: 'passport',
page : 'back-send-email-ok',
title : "邮件发送成功"
title : '邮件发送成功'
}, {
sendEmail: {
coverHref: result.url,
... ... @@ -169,7 +178,8 @@ const sendEmailPage = (req, res, next) => {
email : req.body.emailUrl
}
}));
}).catch(next);
})
.catch(next);
};
... ... @@ -183,11 +193,11 @@ const validateCodeByEmailPage = (req, res, next) => {
service.checkEmailCodeAsync(code)
.then(result => {
if (result) {
next();
} else {
res.redirect(helpers.urlFormat('/passport/back/index.html'));
if (!result) {
return res.redirect(helpers.urlFormat('/passport/back/index'));
}
return next();
})
.catch(next);
};
... ... @@ -207,7 +217,7 @@ const resetPasswordPage = (req, res, next) => {
coverImg : result.img,
code : code
}, req.mobileAuth)
}))
}));
})
.catch(next);
};
... ... @@ -216,6 +226,11 @@ const resetPasswordPage = (req, res, next) => {
* 手机验证页面
*/
const verifyCodeByMobilePage = (req, res, next) => {
req.body.mobile = '15062219934';
req.body.area = '86';
req.body.verifyCode = '8933';
passportHelper.getLeftBannerAsync()
.then(result => {
res.render('back/verification', Object.assign({
... ... @@ -242,7 +257,7 @@ const checkSuccessStatusPage = (req, res, next) => {
delete req.session.successType;
next();
} else {
res.redirect(helpers.urlFormat('/passport/back/index.html'));
res.redirect(helpers.urlFormat('/passport/back/index'));
}
};
... ... @@ -258,27 +273,26 @@ const resetPwdSuccessPage = (req, res, next) => {
coverHref: result.url,
coverImg : result.img
}
}))
}));
})
.catch(next);
};
const verifyCodeByMobileAPI = (req, res) => {
let mobile = req.param('mobile', '');
let area = req.param('area', '86');
let mobile = req.param('mobile', '');
let area = req.param('area', '86');
let mobileCode = req.param('code', '');
const session = req.session;
const session = req.session;
const ERR = {
code : 400,
message: '验证码错误!',
data : helpers.urlFormat('/passport/back/index.html')
data : helpers.urlFormat('/passport/back/index')
};
if (!code || mobile !== session.mobile || area !== session.area) {
res.json(ERR);
return;
}
// if (!code || mobile !== session.mobile || area !== session.area) {
// return res.json(ERR);
// }
service.verifyCodyByMobileAsync(area, mobile, mobileCode)
.then(result => {
... ... @@ -293,14 +307,14 @@ const validateExistCodePage = (req, res, next) => {
let code = req.param('code', '');
if (!code) {
return res.redirect(helpers.urlFormat('/passport/back/index.html'));
return res.redirect(helpers.urlFormat('/passport/back/index'));
}
next();
};
const validateCodeByMobilePage = (req, res, next) => {
let code = req.param('code', '');
let code = req.param('code', '');
let mobile = req.param('mobile', '');
if (!mobile) {
... ... @@ -316,8 +330,10 @@ const validateCodeByMobilePage = (req, res, next) => {
create_time: req.param('create_time', 0)
};
code = new Buffer(code, 'base64').toString();
code = new Buffer(code, 'base64').toString();
req.mobileAuth = service.authRequest(data, code);
next();
};
... ... @@ -327,41 +343,46 @@ const validatePwdPage = (req, res, next) => {
if (helpers.isPassword(pwd)) {
next();
} else {
res.redirect(helpers.urlFormat('/passport/back/index.html'));
res.redirect(helpers.urlFormat('/passport/back/index'));
}
};
const updatePwdAPI = (req, res, next) => {
let code = req.body.code || '';
let mobileAuth = req.mobileAuth;
let newPassword = req.body.pwd;
let code = req.body.code || '';
let mobileAuth = req.mobileAuth || {};
let newPassword = req.body.pwd || '';
service.updatePwdAsync(code, mobileAuth, newPassword)
.then(result => {
if (result.status) {
req.session.successType = result.type;
res.redirect(helpers.urlFormat('/passport/back/resetSuccess.html'));
res.redirect(helpers.urlFormat('/passport/back/resetSuccess'));
} else {
res.redirect(helpers.urlFormat('/passport/back/index.html'));
res.redirect(helpers.urlFormat('/passport/back/index'));
}
})
.catch(next);
};
const validateMobileInSession = (req, res, next) => {
req.body.mobile = req.session.mobile || "";
req.body.verifyCode = req.session.verifyCode || "";
req.body.area = req.session.area || "";
console.log(req.session.mobile);
console.log(req.session.area);
req.body.mobile = req.session.mobile || '';
req.body.verifyCode = req.session.verifyCode || '';
req.body.area = req.session.area || '';
if (req.body.mobile && req.body.verifyCode) {
next()
return next();
} else {
res.redirect(helpers.urlFormat('/passport/back/index.html'));
return res.redirect(helpers.urlFormat('/passport/back/index'));
}
};
module.exports = {
indexPage,
index,
validateInputAPI,
validateUserPage,
getUserInfoAPI,
... ...
... ... @@ -4,24 +4,22 @@
'use strict';
const library = '../../../library';
const captcha = require('../models/captcha-service');
const helpers = require(library + '/helpers');
const helpers = global.yoho.helpers;
const validateAPI = (req, res, next) => {
const requiredAPI = (req, res, next) => {
let captchaToken = (req.body.verifyCode || '').toLowerCase();
if (captchaToken === req.session.captcha) {
return next();
} else {
return res.json({
code : 400,
code: 400,
message: '您输入的验证码不正确!'
});
}
};
const validatePage = (req, res, next) => {
const requiredPage = (req, res, next) => {
let captchaToken = (req.body.verifyCode || '').toLowerCase();
if (captchaToken === req.session.captcha) {
... ... @@ -31,25 +29,8 @@ const validatePage = (req, res, next) => {
}
};
const validate = (req, res, next) => {
};
const generatePage = (req, res, next) => {
let len = req.query.len || 4;
captcha.generateAsync(len)
.then(result => {
req.session.captcha = result.text.toLowerCase();
res.writeHead(200, {'Content-Type': 'image/png'})
res.send(result.image, 'binary');
})
.catch(next);
};
module.exports = {
validateAPI,
validatePage,
validate,
generatePage
requiredAPI,
requiredPage
};
... ...
'use strict';
const sign = global.yoho.sign;
const api = global.yoho.API;
const api = global.yoho.API;
class Auth {
static signinByOpenID(nickname, openId, sourceType, shoppingKey) {
let param = {
nickname: nickname,
openId: openId,
nickname : nickname,
openId : openId,
source_type: sourceType,
method: 'app.passport.signinByOpenID'
method : 'app.passport.signinByOpenID'
};
if (shoppingKey) {
... ... @@ -22,11 +22,11 @@ class Auth {
static signinByWechat(nickname, openId, unionId, sourceType, shoppingKey) {
let param = {
nickname: nickname,
openId: openId,
unionId: unionId,
nickname : nickname,
openId : openId,
unionId : unionId,
source_type: sourceType,
method: 'app.passport.signinByWechat'
method : 'app.passport.signinByWechat'
};
if (shoppingKey) {
... ... @@ -38,7 +38,7 @@ class Auth {
static profile(uid) {
let param = {
uid: uid,
uid : uid,
method: 'app.passport.profile'
};
... ... @@ -48,22 +48,24 @@ class Auth {
static syncUserSession(uid, req, res) {
return Auth.profile(uid).then((userInfo) => {
let token = sign.makeToken(uid);
let data = userInfo.data;
let data = userInfo.data;
if (data) {
let uidCookie = `${data.profile_name}::${data.uid}::${data.vip_info.title}::${token}`;
req.session._TOKEN = token;
req.session._TOKEN = token;
req.session._LOGIN_UID = uid;
res.cookie('_UID', uidCookie, {
domain: 'yohobuy.com'
});
res.cookie('_TOKEN', token, {
domain: 'yohobuy.com'
});
}
});
req.session._TOKEN = token; // esline-disable-line
req.session._LOGIN_UID = uid; // esline-disable-line
res.cookie('_TOKEN', token, {
domain: 'yohobuy.com'
}); // esline-disable-line
}).catch(console.log);
}
}
... ...
... ... @@ -4,11 +4,7 @@
'use strict';
var API = require('../../../library/api').API;
const library = '../../../library';
var api = new API();
const api = global.yoho.API;
const YOHOBUY_URL = 'http://www.yohobuy.com/';
/**
... ...
/**
* Created by TaoHuang on 2016/6/27.
*/
'use strict';
/**
* 签名算法参考微信支付加密算法
* 参考链接:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3
*
*/
const _ = require('lodash');
const SALT = '_+@#$%^';
/**
* 生成加密token
* @param data json
* @returns string
*/
const _packageObject = (data) => {
return _.keys(data).sort().map(key => `${key}=${data[key]}`).join('&').toUpperCase();
};
const _encodeMD5 = (str) => {
const md5 = require('md5');
return md5(str).toUpperCase();
};
const makeToken = (data) => {
let saltData = Object.assign(data, {key: SALT});
let str = _packageObject(saltData);
return _encodeMD5(str);
};
const validateToken = (data, token) => {
let saltData = Object.assign(data, {key: SALT});
let str = _packageObject(saltData);
return _encodeMD5(str) === token;
};
module.exports = {
makeToken,
validateToken
};
... ...
... ... @@ -4,38 +4,39 @@
'use strict';
const helpers = require(`${library}/helpers`);
const api = require('./back-api');
const helpers = global.yoho.helpers;
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 backHelper = require('./back-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 = '';
if (passportHelper.validator.verifyEmail(userInput)) {
result.type = 'email';
result.area = '';
result.phone = userInput;
resolve(result);
} else if (helpers.verifyAreaMobile(helpers.makeAreaMobile(areaCode, userInput))) {
result.type = 'mobile';
result.area = areaCode;
} else if (passportHelper.validator.isAreaMobile(passportHelper.makeAreaMobile(areaCode, userInput))) {
result.type = 'mobile';
result.area = areaCode;
result.phone = userInput;
resolve(result);
} else {
rejected('输入信息出错!');
}
});
};
... ... @@ -44,13 +45,13 @@ const findUserAsync = (type, phone, area) => {
return co(function * () {
const MESSAGE = {
mobile: '您输入的手机号码尚未注册!',
email : '您输入的邮件账户尚未注册!',
ok : '验证成功'
email: '您输入的邮件账户尚未注册!',
ok: '验证成功'
};
const findBy = {
email : userService.findByEmailAsync,
mobile: userService.findByMobileAsync
email: userService.findByEmailAsync,
mobile: (phone1, area1) => userService.findByMobileAsync(area1, phone1) // 交换参数
};
const OK = {code: 200, message: MESSAGE.ok};
... ... @@ -59,7 +60,7 @@ const findUserAsync = (type, phone, area) => {
if (_.isEmpty(user)) {
return {
code : 402,
code: 402,
message: MESSAGE[type]
};
}
... ... @@ -68,34 +69,10 @@ const findUserAsync = (type, phone, area) => {
})();
};
const _sendCodeToEmailAsync = input => {
return api.sendCodeToEmailAsync(input).then(result => {
if (!result.code || result.code !== 200) {
return Promise.reject('request error!');
}
return result.data;
}).catch(() => {
return {};
});
}
const _sendCodeToMobileAsync = (areaCode, userInput) => {
return api.sendCodeToMobileAsync(areaCode, userInput).then(result => {
if (!result.code || result.code !== 200) {
return Promise.reject('request error');
}
return result.data;
}).catch(() => {
return {};
});
}
const sendCodeToUserAsync = (type, mobile, areaCode) => {
let sendTo = {
email : _sendCodeToEmailAsync,
mobile: _sendCodeToMobileAsync
email: api.sendCodeToEmailAsync,
mobile: api.sendCodeToMobileAsync
};
return sendTo[type](mobile, areaCode);
... ... @@ -113,54 +90,57 @@ 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')
};
api.validateMobileCodeAsync(mobile, mobileCode, area)
return api.validateMobileCodeAsync(mobile, mobileCode, area)
.then(result => {
if (!result.code || result.code !== 200) {
if (!(result.code && result.code === 200)) {
return ERR;
}
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');
data.code = new Buffer(backHelper.makeToken(data)).toString('base64');
console.log(data.code);
return {
code : 200,
code: 200,
message: '验证成功',
data : helpers.urlFormat('/passport/back/backcode', data)
data: helpers.urlFormat('/passport/back/backcode', data)
};
})
});
};
const authRequest = (data, token) => {
if (!authHelper.validateToken(data, token)) {
if (!backHelper.validateToken(data, token)) {
return {};
}
... ... @@ -168,7 +148,7 @@ const authRequest = (data, token) => {
let isExpired = (moment().unix() - data.create_time) > existTime;
if (isExpired) {
return {}
return {};
} else {
return data;
}
... ... @@ -177,23 +157,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: 'unknown', 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 +182,7 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => {
return ERR;
}
result.type = 'email';
result.type = 'email';
result.status = true;
}
... ... @@ -210,6 +190,8 @@ const updatePwdAsync = (emailToken, mobileToken, newPassword) => {
})();
};
const checkEmailCodeAsync = api.checkEmailCodeAsync;
module.exports = {
validateEmailOrMobileAsync,
findUserAsync,
... ... @@ -218,5 +200,6 @@ module.exports = {
indexPageDataAsync,
verifyCodyByMobileAsync,
authRequest,
updatePwdAsync
updatePwdAsync,
checkEmailCodeAsync
};
... ...
/**
* Created by TaoHuang on 2016/6/17.
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const fs = require('fs');
const generateAsync = () => {
const path = './fake_captcha_mer2.png';
const readFileAsync = Promise.promisify(fs.readFile);
return co(function * () {
let data = yield readFileAsync(path);
return {
text: "mer2",
image: data
}
})();
};
module.exports = {
generateAsync
};
... ... @@ -3,8 +3,7 @@
*/
'use strict';
const ServiceAPI = require(library + "/api").ServiceAPI;
const serviceAPI = new ServiceAPI();
const serviceAPI = global.yoho.ServiceAPI;
module.exports.getResourceAsync = (resourceCode) => {
return serviceAPI.get('/operations/api/v5/resource/get', {
... ...
... ... @@ -5,14 +5,14 @@
'use strict';
const helpers = require(library + '/helpers');
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');
module.exports.getLeftBannerAsync = (resourceCode) => {
const getLeftBannerAsync = (resourceCode) => {
const DEFAULT_VALUE = {
img: 'http://img12.static.yhbimg.com/' +
'yhb-img01/2015/12/01/07/020a0b6e7ff908d0c2bc4045b4fef42b9f.png?imageView/2/w/252/h/190',
... ... @@ -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;
... ... @@ -35,67 +36,208 @@ module.exports.getLeftBannerAsync = (resourceCode) => {
})();
};
module.exports.getCountry = () => {
const getCountry = () => {
return [
{
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: '中国香港'
}
];
};
/**
* 验证邮箱是否合法
*
* @param string email
* @return boolean
*/
const verifyEmail = email => {
if (!email) {
return false;
}
const emailRegExp = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
return emailRegExp.test(email);
};
/**
* 各国手机号规则
*/
function _areaMobileVerify(phone, area) {
area = area || '86';
phone = phone.trim();
let verify = {
86: {
name: '中国',
match: /^1[3|4|5|8|7][0-9]{9}$/.test(phone)
},
852: {
name: '中国香港',
match: /^[9|6|5][0-9]{7}$/.test(phone)
},
853: {
name: '中国澳门',
match: /^[0-9]{8}$/.test(phone)
},
886: {
name: '中国台湾',
match: /^[0-9]{10}$/.test(phone)
},
65: {
name: '新加坡',
match: /^[9|8][0-9]{7}$/.test(phone)
},
60: {
name: '马来西亚',
match: /^1[1|2|3|4|6|7|9][0-9]{8}$/.test(phone)
},
1: {
name: '加拿大&美国',
match: /^[0-9]{10}$/.test(phone)
},
82: {
name: '韩国',
match: /^01[0-9]{9}$/.test(phone)
},
44: {
name: '英国',
match: /^7[7|8|9][0-9]{8}$/.test(phone)
},
81: {
name: '日本',
match: /^0[9|8|7][0-9]{9}$/.test(phone)
},
61: {
name: '澳大利亚',
match: /^[0-9]{11}$/.test(phone)
}
};
if (verify[area]) {
return verify[area].match;
} else {
return false;
}
}
/**
* 验证国际手机号是否合法
*/
const isAreaMobile = areaMobile => {
if (!areaMobile) {
return false;
}
let mobile = {
area: '86',
phone: ''
};
let splitMobile = areaMobile.split('-');
if (splitMobile.length === 2) {
mobile.area = splitMobile[0];
mobile.phone = splitMobile[1];
} else {
mobile.phone = splitMobile[0];
}
return _areaMobileVerify(mobile.phone, mobile.area);
};
/**
* 验证手机是否合法
*/
const verifyMobile = phone => {
if (!phone) {
return false;
}
return /^1[3|4|5|8|7][0-9]{9}$/.test(phone);
};
const verifyPassword = password => {
if (!password) {
return false;
}
return /^([a-zA-Z0-9\-\+_!@\#$%\^&\*\(\)\:\;\.=\[\]\\\',\?]){6,20}$/.test(password);
};
const makeAreaMobile = (area, mobile) => {
if (!area || area === '86') {
return mobile;
}
return `${area}-${mobile}`;
};
module.exports = {
validator: {
verifyPassword,
verifyMobile,
isAreaMobile,
verifyEmail
},
makeAreaMobile,
getCountry,
getLeftBannerAsync
};
... ...
... ... @@ -3,22 +3,20 @@
*/
'use strict';
const library = '../../../library';
const API = require('../../../library/api').API;
const _ = require('lodash');
const api = new API();
const _ = require('lodash');
const api = global.yoho.API;
const EMPTY = {};
/**
* 根据手机号获取用户信息
*/
const findByMobileAsync = (area, mobile) => {
return api.get('', {
mobile: mobile,
area : area,
method: 'app.passport.getProfileByMobile'
})
mobile: mobile,
area: area,
method: 'app.passport.getProfileByMobile'
})
.then(result => {
if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) {
return EMPTY;
... ... @@ -37,9 +35,9 @@ const findByMobileAsync = (area, mobile) => {
*/
const findByEmailAsync = (email) => {
return api.get('', {
email : email,
method: 'app.passport.getProfileByEmail'
})
email: email,
method: 'app.passport.getProfileByEmail'
})
.then(result => {
if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) {
return EMPTY;
... ...
... ... @@ -7,11 +7,11 @@
'use strict';
const express = require('express');
const cRoot = './controllers';
const login = require(cRoot + '/login');
const cRoot = './controllers';
const login = require(cRoot + '/login');
const Captcha = require(cRoot + '/captcha');
const Back = require(cRoot + '/back');
const Back = require(cRoot + '/back');
const router = express.Router(); // eslint-disable-line
... ... @@ -22,24 +22,26 @@ router.get('/login/wechat/callback', login.wechat.callback);
* 找回密码首页信息
*/
// 找回密码首页
router.get('/back/index.html', Back.indexPage);
router.get('/back/index', Back.index);
// 实时验证输入是否正确
router.post('/back/authcode',
Captcha.validateAPI,
Captcha.requiredAPI,
Back.validateInputAPI,
Back.getUserInfoAPI);
// 提交按钮邮件API
router.post('/back/email',
Captcha.validatePage,
// Captcha.requiredPage,
Back.validateUserPage,
Back.sendCodePage,
Back.saveInSession);
// 提交按钮手机API
router.post('/back/mobile',
Captcha.validatePage,
Captcha.requiredPage,
Back.validateUserPage,
Back.sendCodePage,
Back.saveInSession);
... ... @@ -48,7 +50,7 @@ router.post('/back/mobile',
* 邮件找回密码
*/
// 发送邮件成功页面
router.get('/back/sendEmail.html',
router.get('/back/sendEmail',
Back.validateEmailInSession,
Back.sendEmailPage);
... ... @@ -56,20 +58,23 @@ router.get('/back/sendEmail.html',
* 短信找回密码
*/
// 验证手机短信页面
router.get('/back/verification.html',
Back.validateMobileInSession,
Captcha.validatePage,
router.get('/back/verification',
// Back.validateMobileInSession,
// Captcha.requiredPage,
Back.verifyCodeByMobilePage);
// 重新发送短信接口
router.post('/back/sendBackMobile',
Captcha.validateAPI,
// Captcha.requiredAPI,
Back.validateMobileAPI,
Back.sendBackMobileAPI);
// 验证手机验证码接口
router.post('/back/backMobile',
Captcha.validateAPI,
// Captcha.requiredAPI,
Back.verifyCodeByMobileAPI);
/**
... ... @@ -90,13 +95,9 @@ router.post('/back/update',
Back.updatePwdAPI);
// 重置密码成功页面
router.get('/back/resetSuccess.html',
Back.checkSuccessStatusPage,
Back.resetPwdSuccessPage);
router.get('/back/resetSuccess',
/**
* 验证码生成
*/
router.get('/images', Captcha.generatePage);
// Back.checkSuccessStatusPage,
Back.resetPwdSuccessPage);
module.exports = router;
... ...
... ... @@ -32,10 +32,10 @@ exports.image = (url, width, height, mode) => {
*/
exports.isEqual = (v1, v2, _options) => {
if (_.isEqual(v1, v2)) {
return _options.fn(this); // eslint-disable-line
return _options.fn(this); // eslint-disable-line
}
return _options.inverse(this); // eslint-disable-line
return _options.inverse(this); // eslint-disable-line
};
/**
... ... @@ -276,7 +276,7 @@ function areaMobileVerify(phone, area) {
/**
* 验证国际手机号是否合法
*/
exports.verifyAreaMobile = (areaMobile) => {
exports.isAreaMobile = (areaMobile) => {
if (!areaMobile) {
return false;
}
... ... @@ -321,7 +321,7 @@ exports.makeAreaMobile = (area, mobile) => {
};
exports.isPassword = (pwd) => {
if(!pwd){
if (!pwd) {
return false;
}
... ...
... ... @@ -26,7 +26,7 @@ $sc.click(function() {
}
seconds = 60;
//$sc.addClass('disable').prop('disabled', true);
// $sc.addClass('disable').prop('disabled', true);
$sc.addClass('disable').attr('disabled', true);
$msgTip.removeClass('hide');
... ... @@ -35,7 +35,7 @@ $sc.click(function() {
if (seconds === 0) {
clearInterval(itime);
//$sc.val('发送验证码').removeClass('disable').prop('disabled', false);
// $sc.val('发送验证码').removeClass('disable').prop('disabled', false);
$sc.val('发送验证码').removeClass('disable').removeAttr('disabled');
} else {
$sc.val(seconds-- + '秒后可重新操作');
... ... @@ -50,7 +50,7 @@ $sc.click(function() {
seconds = 60;
//$sc.addClass('disable').prop('disabled', true);
// $sc.addClass('disable').prop('disabled', true);
$sc.addClass('disable').attr('disabled', true);
$msgTip.removeClass('hide');
... ... @@ -59,7 +59,7 @@ itime = setInterval(function() {
if (seconds === 0) {
clearInterval(itime);
//$sc.val('发送验证码').removeClass('disable').prop('disabled', false);
// $sc.val('发送验证码').removeClass('disable').prop('disabled', false);
$sc.val('发送验证码').removeClass('disable').removeAttr('disabled');
} else {
$sc.val(seconds-- + '秒后可重新操作');
... ... @@ -85,7 +85,9 @@ $('#captcha').keyup(function() {
success: function(res) {
if (res.code === 200) {
//添加验证码正确验证
console.log(res.data);
// 添加验证码正确验证
$next.removeClass('disable').attr('href', res.data);
$errTip.addClass('hide');
$(that).removeClass('error');
... ... @@ -104,7 +106,7 @@ $('#captcha').keyup(function() {
if (v === '') {
//添加验证码正确验证
// 添加验证码正确验证
$(this).addClass('error');
$errTip.removeClass('hide').text('请输入验证码');
}
... ...