Authored by 姜枫

merge from develop. change library to lib

... ... @@ -17,6 +17,7 @@ const path = require('path');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const favicon = require('serve-favicon');
const yohoLib = require('yoho-node-lib');
const session = require('express-session');
const memcached = require('connect-memcached');
const hbs = require('express-handlebars');
... ... @@ -29,12 +30,14 @@ const MemcachedStore = memcached(session);
app.locals.devEnv = app.get('env') === 'development';
app.locals.version = pkg.version;
// 全局注册library
yohoLib.global(config);
// 指定libray目录
global.library = path.resolve('./library/');
global.middleware = path.resolve('./doraemon/middleware');
global.utils = path.resolve('./utils');
const logger = require(global.library + '/logger');
const logger = global.yoho.logger;
app.set('view engine', '.hbs');
app.set('views', './doraemon/views');
... ... @@ -43,7 +46,7 @@ app.engine('.hbs', hbs({
defaultLayout: 'layout',
layoutsDir: './doraemon/views',
partialsDir: './doraemon/views/partial',
helpers: require(`${global.library}/helpers`)
helpers: global.yoho.helpers
}));
app.use(favicon(path.join(__dirname, '/public/favicon.ico')));
... ... @@ -98,6 +101,7 @@ try {
// YOHO 后置中间件
app.use(errorHanlder.serverError());
} catch (err) {
console.error(err);
logger.error(err);
}
... ...
... ... @@ -23,7 +23,7 @@ app.engine('.hbs', hbs({
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: ['./views/partial', `${doraemon}/partial`],
helpers: require(`${global.library}/helpers`)
helpers: global.yoho.helpers
}));
// router
... ...
... ... @@ -4,10 +4,10 @@
* @date: 2016/05/09
*/
'use strict';
const library = '../../../library';
const _ = require('lodash');
const channelModel = require('../models/channel');
const helpers = require(`${library}/helpers`);
const helpers = global.yoho.helpers;
let _renderData = {
module: 'channel',
... ...
... ... @@ -24,7 +24,7 @@ app.engine('.hbs', hbs({
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
helpers: require(`${global.library}/helpers`)
helpers: global.yoho.helpers
}));
// router
... ...
... ... @@ -4,17 +4,14 @@
* @date: 2016/05/09
*/
'use strict';
const library = '../../../library';
const utils = '../../../utils';
const contentCodeConfig = require('../../../config/content-code');
const _ = require('lodash');
const ServiceAPI = require(`${library}/api`).ServiceAPI;
const camelCase = require(`${library}/camel-case`);
const logger = require(`${library}/logger`);
const api = global.yoho.ServiceAPI;
const camelCase = global.yoho.camelCase;
const logger = global.yoho.logger;
const resourcesProcess = require(`${utils}/resources-process`);
const api = new ServiceAPI();
/**
* 性别数据
... ...
... ... @@ -24,7 +24,7 @@ app.engine('.hbs', hbs({
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
helpers: require(`${global.library}/helpers`)
helpers: global.yoho.helpers
}));
// router
... ...
... ... @@ -4,18 +4,15 @@
* @date: 2016/05/30
*/
'use strict';
const library = '../../../library';
const utils = '../../../utils';
const contentCodeConfig = require('../../../config/content-code');
const resourcesProcess = require(`${utils}/resources-process`);
const ServiceAPI = require(`${library}/api`).ServiceAPI;
const API = require(`${library}/api`).API;
const logger = require(`${library}/logger`);
const camelCase = require(`${library}/camel-case`);
const helpers = require(`${library}/helpers`);
const logger = global.yoho.logger;
const camelCase = global.yoho.camelCase;
const helpers = global.yoho.helpers;
const _ = require('lodash');
const serviceAPI = new ServiceAPI();
const api = new API();
const serviceAPI = global.yoho.ServiceAPI;
const api = global.yoho.API;
const contentCode = contentCodeConfig.guang;
... ...
... ... @@ -16,10 +16,10 @@ const AlipayStrategy = require('./models/passport-alipay').Strategy;
const _ = require('lodash');
const md5 = require('md5');
const config = require('../../config/common');
const logger = require(global.library + '/logger');
const helpers = require(global.library + '/helpers');
const cookie = require(global.library + '/cookie');
const config = global.yoho.config;
const logger = global.yoho.logger;
const helpers = global.yoho.helpers;
const cookie = global.yoho.cookie;
const AuthHelper = require('./models/auth-helper');
... ...
... ... @@ -5,9 +5,10 @@
'use strict';
const _ = require('lodash');
const library = '../../../library';
const helpers = require(`${library}/helpers`);
const _ = require('lodash');
const helpers = global.yoho.helpers;
const service = require('../models/back-service');
const SIGN_IN = helpers.urlFormat('/passport/login');
... ... @@ -16,16 +17,18 @@ const SIGN_IN = helpers.urlFormat('/passport/login');
* 通过邮箱找回密码页面
*/
const indexEmailPage = (req, res) => {
res.render('back/email', Object.assign({
module: 'passport',
page : 'back-email',
title : '找回密码-通过邮箱'
}, {
backUrl : SIGN_IN,
headerText : '找回密码',
isPassportPage: true,
backEmail : true
}));
res.render('back/email', Object.assign(
{
module: 'passport',
page: 'back-email',
title: '找回密码-通过邮箱'
}, {
backUrl: SIGN_IN,
headerText: '找回密码',
isPassportPage: true,
backEmail: true
}
));
};
/**
... ... @@ -34,9 +37,9 @@ const indexEmailPage = (req, res) => {
const sendCodeToEmailAPI = (req, res) => {
let email = req.body.email || '';
const ERR = {
code : 400,
code: 400,
message: '邮箱格式不正确,请重新输入',
data : ''
data: ''
};
if (!helpers.verifyEmail(email)) {
... ... @@ -47,7 +50,7 @@ const sendCodeToEmailAPI = (req, res) => {
service.sendCodeToEmailAsync(email)
.then(result => {
if (result.code === 200) {
result.data = helpers.urlFormat('/passport/back/success', {email: email});
result.data = helpers.urlFormat('/passport/back/success', { email: email });
}
res.json(result);
... ... @@ -73,7 +76,7 @@ const resendCodeToEmailAPI = (req, res) => {
})
.catch(err => {
res.json({
code : 400,
code: 400,
message: err
});
});
... ... @@ -89,28 +92,28 @@ const backSuccessByEmailPage = (req, res) => {
res.redirect(400);
}
let domain = email.split('@')[1];
let domain = email.split('@')[1];
let emailUrl = `http://${domain === 'gmail.com' ? 'mail.google.com' : 'mail.'}${domain}`;
res.render('back/email-success', Object.assign({
module: 'passport',
page : 'back-email-success',
title : '找回密码-通过邮箱'
page: 'back-email-success',
title: '找回密码-通过邮箱'
}, {
backUrl : helpers.urlFormat('/passport/back/email'),
headerText : '找回密码',
isPassportPage : true,
backEmailSuccess: true,
goEmail : emailUrl,
resendUrl : helpers.urlFormat('/passport/back/resendemail', {email: email})
}));
backUrl: helpers.urlFormat('/passport/back/email'),
headerText: '找回密码',
isPassportPage: true,
backEmailSuccess: true,
goEmail: emailUrl,
resendUrl: helpers.urlFormat('/passport/back/resendemail', { email: email })
}));
};
/**
* 根据邮箱修改密码
*/
const setNewPasswordByEmailAPI = (req, res) => {
let pwd = req.body.password || '';
let pwd = req.body.password || '';
let code = req.body.code || '';
let data = {
code: 200,
... ... @@ -120,7 +123,7 @@ const setNewPasswordByEmailAPI = (req, res) => {
service.modifyPasswordByEmailAsync(pwd, code)
.then(result => {
if (result.includes('history.back')) {
data.code = 400;
data.code = 400;
data.message = '修改失败';
}
... ... @@ -139,16 +142,16 @@ const indexMobilePage = (req, res, next) => {
.then(result => {
res.render('back/mobile', Object.assign({
module: 'passport',
page : 'back-mobile',
title : '找回密码-通过手机号'
page: 'back-mobile',
title: '找回密码-通过手机号'
}, {
backUrl : SIGN_IN,
headerText : '找回密码',
isPassportPage: true,
backMobile : true,
countrys : result.data,
areaCode : '+86'
}));
backUrl: SIGN_IN,
headerText: '找回密码',
isPassportPage: true,
backMobile: true,
countrys: result.data,
areaCode: '+86'
}));
})
.catch(next);
};
... ... @@ -159,8 +162,8 @@ const indexMobilePage = (req, res, next) => {
const sendCodeToMobileAPI = (req, res, next) => {
let phoneNum = req.body.phoneNum || '';
let areaCode = req.body.areaCode || '86';
let ERR = {
code : 400,
let ERR = {
code: 400,
message: '输入手机号码出错'
};
... ... @@ -197,17 +200,17 @@ const verifyCodeByMobilePage = (req, res) => {
res.render('back/mobile-code', Object.assign({
module: 'passport',
page : 'back-code',
title : '找回密码-通过手机号'
page: 'back-code',
title: '找回密码-通过手机号'
}, {
backUrl : helpers.urlFormat('/passport/back/mobile'),
headerText : '找回密码',
isPassportPage: true,
backCode : true,
areaCode : areaCode,
phoneNum : phoneNum
}));
backUrl: helpers.urlFormat('/passport/back/mobile'),
headerText: '找回密码',
isPassportPage: true,
backCode: true,
areaCode: areaCode,
phoneNum: phoneNum
}));
};
/**
... ... @@ -215,7 +218,7 @@ const verifyCodeByMobilePage = (req, res) => {
*/
const verifyCodeByMobileAPI = (req, res, next) => {
let phoneNum = req.body.phoneNum || '';
let code = req.body.code || '';
let code = req.body.code || '';
let areaCode = req.body.areaCode || '86';
service.validateMobileCodeAsync(phoneNum, code, areaCode)
... ... @@ -225,13 +228,13 @@ const verifyCodeByMobileAPI = (req, res, next) => {
code: 200,
data: helpers.urlFormat('/passport/back/backcode', {
phoneNum: phoneNum,
token : result.data.token,
token: result.data.token,
areaCode: areaCode
})
})
} else {
res.json({
code : 400,
code: 400,
message: '验证码失败'
})
}
... ... @@ -244,9 +247,9 @@ const verifyCodeByMobileAPI = (req, res, next) => {
*/
const setNewPasswordByMobilePage = (req, res) => {
let phoneNum = req.query.phoneNum || '';
let token = req.query.token || '';
let token = req.query.token || '';
let areaCode = req.query.areaCode || '86';
let code = req.query.code || '';
let code = req.query.code || '';
if (!(code || (token && helpers.verifyMobile(phoneNum)))) {
res.redirect(400);
... ... @@ -255,18 +258,18 @@ const setNewPasswordByMobilePage = (req, res) => {
res.render('back/new-password', Object.assign({
module: 'passport',
page : 'back-new-password',
title : '找回密码-输入新密码'
page: 'back-new-password',
title: '找回密码-输入新密码'
}, {
backUrl : SIGN_IN,
headerText : '找回密码',
isPassportPage: true,
backNewPwd : true,
phoneNum : phoneNum,
token : token,
areaCode : areaCode,
code : code
}));
backUrl: SIGN_IN,
headerText: '找回密码',
isPassportPage: true,
backNewPwd: true,
phoneNum: phoneNum,
token: token,
areaCode: areaCode,
code: code
}));
};
/**
... ... @@ -274,9 +277,9 @@ const setNewPasswordByMobilePage = (req, res) => {
*/
const setNewPasswordByMobileAPI = (req, res, next) => {
let phoneNum = req.body.phoneNum || '';
let token = req.body.token || '';
let token = req.body.token || '';
let areaCode = req.body.areaCode || '86';
let newPwd = req.body.password || '';
let newPwd = req.body.password || '';
service.modifyPasswordByMobileAsync(phoneNum, token, newPwd, areaCode)
.then(result => {
... ... @@ -288,7 +291,7 @@ const setNewPasswordByMobileAPI = (req, res, next) => {
});
} else {
res.json({
code : 400,
code: 400,
message: "修改密码失败"
})
}
... ...
... ... @@ -7,7 +7,7 @@
'use strict';
const helpers = require(global.library + '/helpers');
const helpers = global.yoho.helpers;
const RegService = require('../models/reg-service');
const BindService = require('../models/bind-service');
const AuthHelper = require('../models/auth-helper');
... ...
... ... @@ -5,14 +5,13 @@
*/
'use strict';
const library = '../../../library';
const passport = require('passport');
const md5 = require('md5');
const uuid = require('uuid');
const cookie = require(`${library}/cookie`);
const helpers = require(`${library}/helpers`);
const log = require(`${library}/logger`);
const config = require('../../../config/common');
const cookie = global.yoho.cookie;
const helpers = global.yoho.helpers;
const log = global.yoho.logger;
const config = global.yoho.config;
const AuthHelper = require('../models/auth-helper');
const loginPage = `${config.siteUrl}/passport/login/index`;
... ... @@ -74,7 +73,7 @@ const local = {
res.render('login', {
loginIndex: true, // 模板中使用JS的标识
backUrl: 'javascript:history.go(-1)', // 返回的URL链接
backUrl: 'javascript:history.go(-1)', // eslint-disable-line // 返回的URL链接
showHeaderImg: true, // 控制显示头部图片
isPassportPage: true, // 模板中模块标识
registerUrl: '/reg.html', // 注册的URL链接
... ...
... ... @@ -8,9 +8,9 @@
'use strict';
const _ = require('lodash');
const helpers = require(global.library + '/helpers');
const sign = require(global.library + '/sign');
const cookie = require(global.library + '/cookie');
const helpers = global.yoho.helpers;
const sign = global.yoho.sign;
const cookie = global.yoho.cookie;
const RegService = require('../models/reg-service');
const AuthHelper = require('../models/auth-helper');
... ...
... ... @@ -26,7 +26,7 @@ app.engine('.hbs', hbs({
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
helpers: require(`${global.library}/helpers`)
helpers: global.yoho.helpers
}));
... ...
'use strict';
const library = '../../../library';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const api = new API();
const sign = global.yoho.sign;
const api = global.yoho.API;
class Auth {
... ...
... ... @@ -4,10 +4,8 @@
'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/';
... ... @@ -43,7 +41,7 @@ const getAreaDataAsync = () => {
const sendCodeToEmailAsync = (email) => {
return api.get('', {
method: 'app.register.backpwdByEmail',
email : email
email: email
});
};
... ... @@ -55,11 +53,11 @@ const sendCodeToEmailAsync = (email) => {
*/
const modifyPasswordByEmailAsync = (pwd, code) => {
const options = {
url : `${YOHOBUY_URL}passport/back/update`,
form : {
pwd : pwd,
url: `${YOHOBUY_URL}passport/back/update`,
form: {
pwd: pwd,
're-input': pwd,
code : code
code: code
},
timeout: 3000
};
... ... @@ -76,7 +74,7 @@ const modifyPasswordByEmailAsync = (pwd, code) => {
const sendCodeToMobileAsync = (mobile, area) => {
return api.get('', {
mobile: mobile,
area : area,
area: area,
method: 'app.register.sendBackpwdCodeToMobile'
});
};
... ... @@ -92,8 +90,8 @@ const validateMobileCodeAsync = (mobile, code, area) => {
area = area || 86;
return api.get('', {
mobile: mobile,
code : code,
area : area,
code: code,
area: area,
method: 'app.register.validBackpwdCode'
});
};
... ... @@ -105,12 +103,12 @@ const validateMobileCodeAsync = (mobile, code, area) => {
* @param string token 验证手机验证码返回的token
* @param integer area 地区码ID
*/
const modifyPasswordByMobileAsync = (mobile, token, newpwd, area)=> {
const modifyPasswordByMobileAsync = (mobile, token, newpwd, area) => {
return api.get('', {
mobile: mobile,
token : token,
token: token,
newpwd: newpwd,
area : area,
area: area,
method: 'app.register.changepwdByMobileCode'
});
};
... ...
... ... @@ -7,8 +7,7 @@
'use strict';
const API = require(`${global.library}/api`).API;
const api = new API();
const api = global.yoho.API;
const RegService = {
bindCheck(mobile, openId, sourceType, area) {
... ...
... ... @@ -7,8 +7,7 @@
'use strict';
const API = require(`${global.library}/api`).API;
const api = new API();
const api = global.yoho.API;
const RegService = {
getAreaData() {
... ... @@ -47,7 +46,7 @@ const RegService = {
name: '英国'
}, {
areaCode: '+86',
selected: true,
selected: true, // default choose
name: '中国'
}, {
areaCode: '+853',
... ...
... ... @@ -24,7 +24,7 @@ app.engine('.hbs', hbs({
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
helpers: require(`${global.library}/helpers`)
helpers: global.yoho.helpers
}));
// router
... ...
... ... @@ -6,12 +6,9 @@
'use strict';
const library = '../../../library';
const API = require(`${library}/api`).API;
const api = global.yoho.API;
const _ = require('lodash');
const helpers = require(`${library}/helpers`);
const api = new API();
const helpers = global.yoho.helpers;
/**
* 处理品牌关联店铺信息
... ...
... ... @@ -7,13 +7,11 @@
'use strict';
const library = '../../../library';
const API = require(`${library}/api`).API;
const _ = require('lodash');
// const log = require(`${library}/logger`);
var api = new API();
var api = global.yoho.API;
/**
* 商品尺码信息处理
... ...
... ... @@ -5,20 +5,17 @@
*/
'use strict';
const library = '../../../library';
const utils = '../../../utils';
const contentCodeConfig = require('../../../config/content-code');
const _ = require('lodash');
const ServiceAPI = require(`${library}/api`).ServiceAPI;
const API = require(`${library}/api`).API;
const camelCase = require(`${library}/camel-case`);
const resourcesProcess = require(`${utils}/resources-process`);
const log = require(`${library}/logger`);
const serviceApi = new ServiceAPI();
const api = new API();
const camelCase = global.yoho.camelCase;
const log = global.yoho.logger;
const serviceApi = global.yoho.ServiceAPI;
const api = global.yoho.API;
const resourcesProcess = require(`${utils}/resources-process`);
const dateFormate = (str) =>{
var time = new Date(str * 1000);
... ...
... ... @@ -7,12 +7,10 @@
'use strict';
const library = '../../../library';
const utils = '../../../utils';
const API = require(`${library}/api`).API;
const api = global.yoho.API;
const _ = require('lodash');
const productProcess = require(`${utils}/product-process`);
var api = new API();
module.exports = (data) => {
var finalResult;
... ...
... ... @@ -4,20 +4,17 @@
* @date: 2016/05/17
*/
'use strict';
const library = '../../../library';
const utils = '../../../utils';
const contentCodeConfig = require('../../../config/content-code');
const API = require(`${library}/api`).API;
const ServiceAPI = require(`${library}/api`).ServiceAPI;
const logger = require(`${library}/logger`);
const camelCase = require(`${library}/camel-case`);
const logger = global.yoho.logger;
const camelCase = global.yoho.camelCase;
const resourcesProcess = require(`${utils}/resources-process`);
const productProcess = require(`${utils}/product-process`);
const processTime = require(`${utils}/time-process`);
const _ = require('lodash');
const api = new API();
const serviceAPI = new ServiceAPI();
const api = global.yoho.API;
const serviceAPI = global.yoho.ServiceAPI;
... ...
const _ = require('lodash');
const cookie = require('../../library/cookie');
const cookie = global.yoho.cookie;
module.exports = () => {
return (req, res, next) => {
... ...
... ... @@ -55,6 +55,7 @@
"serve-favicon": "^2.3.0",
"uuid": "^2.0.2",
"winston": "^2.2.0",
"yoho-node-lib": "0.0.5",
"winston-daily-rotate-file": "^1.1.4"
},
"devDependencies": {
... ...
'use strict';
const _ = require('lodash');
const camelCase = require('../library/camel-case');
const helpers = require('../library/helpers');
const camelCase = global.yoho.camelCase;
const helpers = global.yoho.helpers;
/**
* 根据性别来决定 默认图片获取字段 如果是 2、3
... ...
const _ = require('lodash');
const camelCase = require('../library/camel-case');
const camelCase = global.yoho.camelCase;
/**
* 处理楼层数据
... ...
... ... @@ -4,8 +4,7 @@
'use strict';
const library = '../library';
const helpers = require(`${library}/helpers`);
const helpers = global.yoho.helpers;
const timeFormat = {
d: '剩{d}天',
... ...