Authored by 张丽霞

代码还原到最新

... ... @@ -39,7 +39,9 @@ app.set('view engine', '.hbs');
app.use(favicon(path.join(__dirname, '/public/favicon.ico')));
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.urlencoded({
extended: false
}));
app.use(cookieParser());
app.use(session({
proxy: true,
... ... @@ -52,12 +54,13 @@ app.use(session({
return uuid.v4(); // 兼容 PHP SESSION
},
cookie: {
domain: 'yohobuy.com'
domain: 'yohobuy.com',
httpOnly: false
},
store: new MemcachedStore({
hosts: config.memcache.session,
prefix: 'qinsessionsession:', // 兼容 PHP SESSION
key: 'yohobuy_session' // 兼容 PHP SESSION
prefix: 'qinsessionsession:', // 兼容 PHP SESSION
key: 'yohobuy_session' // 兼容 PHP SESSION
})
}));
... ...
... ... @@ -48,7 +48,7 @@ const getUserStatus = (param) => {
}
if (param.data.newUser === 1) {
dest.newUser = true;
};
}
dest.message = param.data.returnMsg;
// 清空变量,释放内存
param = {};
... ...
/**
* passport 验证策略注册
* @author: jiangfeng<jeff.jiang@yoho.cn>
* @date: 2016/5/31
*/
'use strict';
const passport = require('passport');
const WeixinStrategy = require('passport-weixin-plus');
const config = require('../../config/common');
let siteUrl = config.siteUrl.indexOf('//') === 0 ? 'http:' + config.siteUrl : config.siteUrl;
/**
* wechat登录
*/
passport.use(new WeixinStrategy({
authorizationURL: 'https://open.weixin.qq.com/connect/oauth2/authorize',
tokenURL: 'https://api.weixin.qq.com/sns/oauth2/access_token',
clientID: config.thirdLogin.wechat.appID,
clientSecret: config.thirdLogin.wechat.appSecret,
callbackURL: `${siteUrl}/passport/login/wechat/callback`,
requireState: false,
scope: 'snsapi_userinfo'
}, (accessToken, refreshToken, profile, done) => {
done(null, profile);
}));
... ...
/**
* 登录
* @author: Bi Kai<kai.bi@yoho.cn>
* @date: 2016/05/09
*/
'use strict';
const library = '../../../library';
const passport = require('passport');
const cookie = require(`${library}/cookie`);
const helpers = require(`${library}/helpers`);
const log = require(`${library}/logger`);
const config = require('../../../config/common');
const AuthHelper = require('../models/auth-helper');
const loginPage = `${config.siteUrl}/passport/login/index`;
function doPassportCallback(openId, nickname, sourceType, req, res) {
let shoppingKey = cookie.getShoppingKey(req);
let refer = req.cookies.refer;
if (refer) {
refer = decodeURI(req.cookies.refer);
} else {
refer = `${config.siteUrl}/home`;
}
if (/sign|login/.test(refer)) {
refer = `${config.siteUrl}/home`;
}
if (openId && nickname) {
AuthHelper.signinByOpenID(nickname, openId, sourceType, shoppingKey).then((result) => {
if (result.data['is_bind'] && result.data['is_bind'] === 'N') { //eslint-disable-line
return helpers.urlFormat('/passport/bind/index', {
openId: openId,
sourceType: sourceType,
refer: refer
});
} else if (result.code === 200 && result.data.uid) {
return AuthHelper.syncUserSession(result.data.uid, req, res).then(() => {
return refer;
});
}
}).then((redirectTo) => {
console.log('redirectTo=', redirectTo);
return res.redirect(redirectTo);
}).catch((e) => {
log.error('频道页面渲染错误:' + JSON.stringify(e));
return res.send('error');
});
}
}
const wechat = {
beforeLogin: (req, res, next) => {
let refer = req.query.refer;
if (!refer) {
refer = req.get('Referer');
}
refer && res.cookie('refer', encodeURI(refer), {
domain: 'yohobuy.com'
});
next();
},
login: (req, res, next) => {
return passport.authenticate('weixin')(req, res, next);
},
callback: (req, res, next) => {
passport.authenticate('weixin', (err, user) => {
if (err) {
log.error(`wechat authenticate error : ${JSON.stringify(err)}`);
return res.redirect(loginPage);
}
let nickname = user.displayName || user._json.nickname;
let openId = user.id || user._json.unionid;
doPassportCallback(openId, nickname, 'wechat', req, res);
})(req, res, next);
}
};
exports.wechat = wechat;
... ...
/**
* sub app channel
* @author: Bi Kai<kai.bi@yoho.cn>
* @date: 2016/05/09
*/
'use strict';
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
var passport = require('passport');
var app = express();
// set view engin
var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root
app.on('mount', function(parent) {
delete parent.locals.settings; // 不继承父 App 的设置
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
helpers: require(`${global.library}/helpers`)
}));
require('./auth');
app.use(passport.initialize());
app.use(passport.session());
// router
app.use(require('./router'));
module.exports = app;
... ...
'use strict';
const library = '../../../library';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const api = new API();
class Auth {
static signinByOpenID(nickname, openId, sourceType, shoppingKey) {
let param = {
nickname: nickname,
openId: openId,
source_type: sourceType, // esline-disable-line
method: 'app.passport.signinByOpenID',
shoppingKey: shoppingKey
};
if (shoppingKey) {
param.shopping_key = shoppingKey;
}
return api.get('', sign.apiSign(param));
}
static profile(uid) {
let param = {
uid: uid,
method: 'app.passport.profile'
};
return api.get('', sign.apiSign(param));
}
static syncUserSession(uid, req, res) {
return Auth.profile(uid).then((userInfo) => {
let token = sign.makeToken(uid);
let data = userInfo.data;
if (data) {
let uidCookie = `${data.profile_name}::${data.uid}::${data.vip_info.title}::${token}`;
res.cookie('_UID', uidCookie, {
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);
}
}
module.exports = Auth;
... ...
/**
* router of sub app channel
* @author: Bi Kai<kai.bi@yoho.cn>
* @date: 2016/05/09
*/
'use strict';
const express = require('express');
const cRoot = './controllers';
const login = require(cRoot + '/login');
const router = express.Router(); // eslint-disable-line
router.get('/login/wechat', login.wechat.beforeLogin, login.wechat.login); // 登录
router.get('/login/wechat/callback', login.wechat.callback);
module.exports = router;
... ...
... ... @@ -191,7 +191,7 @@ exports.search = (req, res) => {
if (req.query.saleType === '2') {
vipObj = Object.assign({
saleVip: (req.query.saleType === '2' && (!uid || vipLevel === '1')),
saleVip: (req.query.saleType === '2' && (!uid || vipLevel === '0')),
vipLevel: vipLevel,
saleViplogin: vipLevel >= 1 ? true : false,
vipPrice1: vipLevel === '1',
... ...
... ... @@ -11,15 +11,15 @@ const isTest = process.env.NODE_ENV === 'test';
module.exports = {
port: 6001,
siteUrl: 'http://m.yohobuy.com',
siteUrl: '//m.yohobuy.com',
// domains: {
// api: 'http://testapi.yoho.cn:28078/', // http://192.168.102.205:8080/gateway
// service: 'http://testservice.yoho.cn:28077/'
// },
domains: {
api: 'http://testapi.yoho.cn:28078/', // http://192.168.102.205:8080/gateway
service: 'http://testservice.yoho.cn:28077/'
api: 'http://devapi.yoho.cn:58078/',
service: 'http://devservice.yoho.cn:58077/',
search: 'http://192.168.10.64:8080/yohosearch/'
},
useOneapm: false,
useCache: false,
... ... @@ -45,13 +45,19 @@ module.exports = {
udp: { // send by udp
level: 'debug', // logger level
host: '192.168.102.162', // influxdb host
port: '4444'// influxdb port
port: '4444' // influxdb port
},
console: {
level: 'debug',
colorize: 'all',
prettyPrint: true
}
},
thirdLogin: {
wechat: {
appID: 'wx75e5a7c0c88e45c2',
appSecret: 'ce21ae4a3f93852279175a167e54509b'
}
}
};
... ... @@ -74,6 +80,12 @@ if (isProduction) {
} else if (isTest) {
Object.assign(module.exports, {
appName: 'm.yohobuy.com for test',
memcache: {
master: ['127.0.0.1:11212', '127.0.0.1:11213'],
slave: ['127.0.0.1:11212', '127.0.0.1:11213'],
session: ['127.0.0.1:11212', '127.0.0.1:11213'],
timeout: 3000
},
useOneapm: true,
useCache: true
});
... ...
... ... @@ -13,5 +13,6 @@ module.exports = app => {
// 业务模块
app.use('/product', require('./apps/product'));
app.use('/passport', require('./apps/passport'));
app.use('/coupon', require('./apps/coupon'));
};
... ...
... ... @@ -35,15 +35,15 @@
{{#if @root.saleViplogin}}
<i class="vip-grade vip-grade-{{@root.vipLevel}}"></i>
<span class="sale-price {{^marketPrice}}no-price{{/marketPrice}}">¥
{{#if @root.vipPrice1}}{{vip1Price}}{{/if}}
{{#if @root.vipPrice2}}{{vip2Price}}{{/if}}
{{#if @root.vipPrice3}}{{vip3Price}}{{/if}}
{{#if @root.vipPrice1}}{{round vip1Price}}{{/if}}
{{#if @root.vipPrice2}}{{round vip2Price}}{{/if}}
{{#if @root.vipPrice3}}{{round vip3Price}}{{/if}}
</span>
{{else}}
<span class="sale-price {{^marketPrice}}no-price{{/marketPrice}}">¥{{salesPrice}}</span>
<span class="sale-price {{^marketPrice}}no-price{{/marketPrice}}">¥{{round salesPrice}}</span>
{{/if}}
{{#marketPrice}}
<span class="market-price">¥{{.}}</span>
<span class="market-price">¥{{round .}}</span>
{{/marketPrice}}
</div>
{{#if @root.saleVip}}
... ...
... ... @@ -3,6 +3,8 @@
* @param {[object]} req
* @return {[string]}
*/
'use strict';
exports.getUid = (req) => {
const cookie = req.cookies._UID;
let _uid = 0;
... ... @@ -21,3 +23,7 @@ exports.getUid = (req) => {
return _uid;
};
exports.getShoppingKey = (req) => {
return req.cookies['_SPK'] ? req.cookies['_SPK'] : ''; // eslint-disable-line
};
... ...
... ... @@ -92,6 +92,19 @@ exports.upperCase = (str) => {
return str.toUpperCase();
};
/**
* 四舍五入
* @param {[type]} num 数字
* @param {[type]} precision 精度
* @return {[type]}
*/
exports.round = (num, precision) => {
precision = _.isNumber(precision) ? precision : 2;
num = _.isInteger(num) ? (+num).toFixed(precision) : _.round(num, precision);
return num;
};
/**
* 时间格式化
* @param format 格式化token @see{http://momentjs.cn/docs/#/displaying/format/}
... ...
... ... @@ -11,12 +11,12 @@ const FileTransport = require('winston-daily-rotate-file');
require('influxdb-winston');
const logger = new (winston.Logger)({
const logger = new(winston.Logger)({
transports: [
new (FileTransport)(config.loggers.infoFile),
new (FileTransport)(config.loggers.errorFile),
new (winston.transports.UdpTransport)(config.loggers.udp),
new (winston.transports.Console)(config.loggers.console)
new(FileTransport)(config.loggers.infoFile),
new(FileTransport)(config.loggers.errorFile),
new(winston.transports.UdpTransport)(config.loggers.udp),
new(winston.transports.Console)(config.loggers.console)
],
exitOnError: false
});
... ...
... ... @@ -72,7 +72,7 @@ exports.apiSign = (params) => {
// 检查签名,APP 访问 H5 页面的时候需要检查
exports.checkSign = (params) => {
const // eslint-disable-line camelcase
clientSecret = params.client_secret;
clientSecret = params.client_secret;
let sortedParams;
... ... @@ -94,3 +94,7 @@ exports.webSign = (params) => {
return params.key === md5(md5(webPrivateKey) + params.uid);
};
exports.makeToken = (string) => {
return md5(md5(string + '#@!@#'));
};
... ...
... ... @@ -43,6 +43,8 @@
"moment": "^2.13.0",
"morgan": "^1.7.0",
"oneapm": "^1.2.20",
"passport": "^0.3.2",
"passport-weixin-plus": "0.0.4",
"request-promise": "^3.0.0",
"serve-favicon": "^2.3.0",
"uuid": "^2.0.2",
... ...
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.

84.5 KB | W: | H:

44.8 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
... ... @@ -37,6 +37,10 @@ if ($('#activityEnded').html()) {
$('.tip-wrap .title').html(tipMessage);
}
if (!$('#newUser').html()) {
$('.gain-coupon-centent .coupon img').attr('src', oldUserCouponPic);
}
$('.input-content').on('click', '.verification-code', function() {
$('.input-content div').eq('0').removeClass('verification-code');
phone = $(this).siblings('input').val();
... ...
... ... @@ -100,7 +100,7 @@
.has-clear {
padding-right: 30px;
}
.clear-input {
position: absolute;
padding: 10px;
... ...
... ... @@ -72,22 +72,22 @@ exports.processProductList = (list, options) => {
// thumb: product.defaultImages
// });
if (options.showPoint) {
product.marketPrice += '.00';
product.salesPrice += '.00';
if (product.vip1Price) {
product.vip1Price = parseInt(product.vip1Price) + '.00';
}
if (product.vip2Price) {
product.vip2Price = parseInt(product.vip2Price) + '.00';
}
if (product.vip3Price) {
product.vip3Price = parseInt(product.vip3Price) + '.00';
}
}
// if (options.showPoint) {
// // product.marketPrice += '.00';
// // product.salesPrice += '.00';
// // if (product.vip1Price) {
// // product.vip1Price = parseInt(product.vip1Price) + '.00';
// // }
// // if (product.vip2Price) {
// // product.vip2Price = parseInt(product.vip2Price) + '.00';
// // }
// // if (product.vip3Price) {
// // product.vip3Price = parseInt(product.vip3Price) + '.00';
// // }
// }
product.isSoonSoldOut = product.isSoonSoldOut === 'Y';
product.url = helpers.urlFormat(`/product/pro_${product.productId}_${product.goodsList[0].goodsId}/${product.cnAlphabet}.html`); // eslint-disable-line
... ...