Authored by 毕凯

Merge branch 'feature/passport' of git.yoho.cn:fe/yohobuy-node into feature/passport

@@ -77,8 +77,6 @@ const sendCodePage = (req, res, next) => { @@ -77,8 +77,6 @@ const sendCodePage = (req, res, next) => {
77 77
78 service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area) 78 service.sendCodeToUserAsync(inputInfo.type, inputInfo.phone, inputInfo.area)
79 .then(result => { 79 .then(result => {
80 - console.log(result);  
81 -  
82 if (!(result.code && result.code === 200)) { 80 if (!(result.code && result.code === 200)) {
83 return res.redirect(helpers.urlFormat('/passport/back/index')); 81 return res.redirect(helpers.urlFormat('/passport/back/index'));
84 } 82 }
@@ -4,10 +4,13 @@ @@ -4,10 +4,13 @@
4 4
5 'use strict'; 5 'use strict';
6 6
  7 +const Captchapng = require('captchapng');
  8 +const _ = require('lodash');
  9 +
7 const helpers = global.yoho.helpers; 10 const helpers = global.yoho.helpers;
8 11
9 const requiredAPI = (req, res, next) => { 12 const requiredAPI = (req, res, next) => {
10 - let captchaToken = (req.body.verifyCode || '').toLowerCase(); 13 + let captchaToken = +(req.body.verifyCode || '').toLowerCase();
11 14
12 if (captchaToken === req.session.captcha) { 15 if (captchaToken === req.session.captcha) {
13 return next(); 16 return next();
@@ -20,16 +23,48 @@ const requiredAPI = (req, res, next) => { @@ -20,16 +23,48 @@ const requiredAPI = (req, res, next) => {
20 }; 23 };
21 24
22 const requiredPage = (req, res, next) => { 25 const requiredPage = (req, res, next) => {
23 - let captchaToken = (req.body.verifyCode || '').toLowerCase(); 26 + let captchaToken = +(req.body.verifyCode || '').toLowerCase();
24 27
25 if (captchaToken === req.session.captcha) { 28 if (captchaToken === req.session.captcha) {
26 return next(); 29 return next();
27 } else { 30 } else {
28 - return res.redirect(helpers.urlFormat('/passport/back/index.html')); 31 + return res.redirect(helpers.urlFormat('/passport/back/index'));
29 } 32 }
30 }; 33 };
31 34
  35 +
  36 +const _generateCaptcha = (width, height, length) => {
  37 + let min = Math.pow(10, (length - 1 || 1));
  38 + let max = Math.pow(10, (length - 1 || 1)) * 9;
  39 + let token = '' + _.random(min, max);
  40 +
  41 + let png = new Captchapng(width, height, token);//
  42 +
  43 + png.color(0, 0, 0, 0); // First color: background (red, green, blue, alpha)
  44 + png.color(80, 80, 80, 255); // Second color: paint (red, green, blue, alpha)
  45 +
  46 + return {
  47 + image: new Buffer(png.getBase64(), 'base64'),
  48 + text: token
  49 + };
  50 +};
  51 +
  52 +const generate = (req, res) => {
  53 + let width = req.query.w || 150;
  54 + let height = req.query.h || 50;
  55 + let length = +(req.query.l || 4);
  56 + let captcha = _generateCaptcha(width, height, length);
  57 +
  58 + req.session.captcha = captcha.text;
  59 + res.writeHead(200, {
  60 + 'Content-Type': 'image/png'
  61 + });
  62 +
  63 + res.end(captcha.image);
  64 +};
  65 +
32 module.exports = { 66 module.exports = {
33 requiredAPI, 67 requiredAPI,
34 - requiredPage 68 + requiredPage,
  69 + generate
35 }; 70 };
@@ -10,7 +10,7 @@ const express = require('express'); @@ -10,7 +10,7 @@ const express = require('express');
10 const cRoot = './controllers'; 10 const cRoot = './controllers';
11 const login = require(cRoot + '/login'); 11 const login = require(cRoot + '/login');
12 12
13 -// const captcha = require(cRoot + '/captcha'); 13 +const captcha = require(cRoot + '/captcha');
14 const back = require(cRoot + '/back'); 14 const back = require(cRoot + '/back');
15 const reg = require(cRoot + '/reg'); 15 const reg = require(cRoot + '/reg');
16 const bind = require(cRoot + '/bind'); 16 const bind = require(cRoot + '/bind');
@@ -70,23 +70,20 @@ router.get('/back/index', back.index); @@ -70,23 +70,20 @@ router.get('/back/index', back.index);
70 70
71 // 实时验证输入是否正确 71 // 实时验证输入是否正确
72 router.post('/back/authcode', 72 router.post('/back/authcode',
73 -  
74 - // captcha.requiredAPI, 73 + captcha.requiredAPI,
75 back.validateInputAPI, 74 back.validateInputAPI,
76 back.getUserInfoAPI); 75 back.getUserInfoAPI);
77 76
78 // 提交按钮邮件API 77 // 提交按钮邮件API
79 router.post('/back/email', 78 router.post('/back/email',
80 -  
81 - // captcha.requiredPage, 79 + captcha.requiredPage,
82 back.validateUserPage, 80 back.validateUserPage,
83 back.sendCodePage, 81 back.sendCodePage,
84 back.saveInSession); 82 back.saveInSession);
85 83
86 // 提交按钮手机API 84 // 提交按钮手机API
87 router.post('/back/mobile', 85 router.post('/back/mobile',
88 -  
89 - // captcha.requiredPage, 86 + captcha.requiredPage,
90 back.validateUserPage, 87 back.validateUserPage,
91 back.sendCodePage, 88 back.sendCodePage,
92 back.saveInSession); 89 back.saveInSession);
@@ -104,29 +101,26 @@ router.get('/back/sendEmail', @@ -104,29 +101,26 @@ router.get('/back/sendEmail',
104 */ 101 */
105 // 验证手机短信页面 102 // 验证手机短信页面
106 router.get('/back/verification', 103 router.get('/back/verification',
  104 + captcha.requiredPage,
107 back.validateMobileInSession, 105 back.validateMobileInSession,
108 -  
109 - // captcha.requiredPage,  
110 back.verifyCodeByMobilePage); 106 back.verifyCodeByMobilePage);
111 107
112 // 重新发送短信接口 108 // 重新发送短信接口
113 router.post('/back/sendBackMobile', 109 router.post('/back/sendBackMobile',
114 -  
115 - // captcha.requiredAPI, 110 + captcha.requiredAPI,
116 back.validateMobileAPI, 111 back.validateMobileAPI,
117 back.sendBackMobileAPI); 112 back.sendBackMobileAPI);
118 113
119 // 验证手机验证码接口 114 // 验证手机验证码接口
120 router.post('/back/backMobile', 115 router.post('/back/backMobile',
121 -  
122 - // captcha.requiredAPI, 116 + captcha.requiredAPI,
123 back.verifyCodeByMobileAPI); 117 back.verifyCodeByMobileAPI);
124 118
125 /** 119 /**
126 * 重置密码 120 * 重置密码
127 */ 121 */
128 122
129 -// 重置密码页面 123 + // 重置密码页面
130 router.get('/back/backcode', 124 router.get('/back/backcode',
131 back.validateExistCodePage, 125 back.validateExistCodePage,
132 back.validateCodeByMobilePage, 126 back.validateCodeByMobilePage,
@@ -145,4 +139,6 @@ router.get('/back/resetSuccess', @@ -145,4 +139,6 @@ router.get('/back/resetSuccess',
145 back.validateSuccessStatusPage, 139 back.validateSuccessStatusPage,
146 back.resetPwdSuccessPage); 140 back.resetPwdSuccessPage);
147 141
  142 +router.get('/images', captcha.generate);
  143 +
148 module.exports = router; 144 module.exports = router;
1 const seoMap = { 1 const seoMap = {
2 /* eslint-disable */ 2 /* eslint-disable */
3 '/': { 3 '/': {
4 - title: 'YOHO!有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证', 4 + title: 'YOHO!BUY有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证',
5 keywords: 'Yoho! 有货官网,潮流志,潮流男装,潮牌,美国潮牌,日本潮牌,香港潮牌,潮牌店,新品首发,欧美潮流,全球购,代购,时尚,流行,特卖,B2C,正品,购物网站,网上购物,货到付款', 5 keywords: 'Yoho! 有货官网,潮流志,潮流男装,潮牌,美国潮牌,日本潮牌,香港潮牌,潮牌店,新品首发,欧美潮流,全球购,代购,时尚,流行,特卖,B2C,正品,购物网站,网上购物,货到付款',
6 - description: 'YOHO! 有货,年轻人潮流购物中心,中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。作为YOHO!旗下的购物平台,汇集了全球潮流时尚商品和中国最流行的商品,也是国内最大的原创文化商品平台,也是香港,台湾地区流行商品的集中地。同时包含日本、韩国等众多国外潮流品牌,带给您全新潮流购物体验。' 6 + description: 'YOHO!BUY 有货,年轻人潮流购物中心,中国最大的潮流商品购物网站。100%品牌正品保证,支持货到付款。作为YOHO!旗下的购物平台,汇集了全球潮流时尚商品和中国最流行的商品,也是国内最大的原创文化商品平台,也是香港,台湾地区流行商品的集中地。同时包含日本、韩国等众多国外潮流品牌,带给您全新潮流购物体验。'
7 }, 7 },
8 '/woman': { 8 '/woman': {
9 title: '女生|时尚潮流女装,日韩女装,潮牌女装全球购|YOHO!BUY有货 100%正品保证', 9 title: '女生|时尚潮流女装,日韩女装,潮牌女装全球购|YOHO!BUY有货 100%正品保证',
@@ -17,7 +17,7 @@ const seoMap = { @@ -17,7 +17,7 @@ const seoMap = {
17 }, 17 },
18 '/lifestyle': { 18 '/lifestyle': {
19 title: '创意生活|创意生活馆,潮流创意家居,家居生活用品|YOHO!BUY有货 100%正品保证', 19 title: '创意生活|创意生活馆,潮流创意家居,家居生活用品|YOHO!BUY有货 100%正品保证',
20 - keywords: '创意生活,创意生活馆,潮流家居,潮流创意家居,家居生活用品,YOHO!有货', 20 + keywords: '创意生活,创意生活馆,潮流家居,潮流创意家居,家居生活用品,YOHO!BUY有货',
21 description: 'YOHO!BUY有货官网创意生活频道汇集了创意生活馆,潮流创意家居,家居生活用品等正品网购,给您的生活带来更多创意。YOHO!BUY有货购物100%正品保证,支持货到付款。' 21 description: 'YOHO!BUY有货官网创意生活频道汇集了创意生活馆,潮流创意家居,家居生活用品等正品网购,给您的生活带来更多创意。YOHO!BUY有货购物100%正品保证,支持货到付款。'
22 } 22 }
23 /* eslint-enable */ 23 /* eslint-enable */
@@ -30,6 +30,8 @@ var thirdLineNum = 9, @@ -30,6 +30,8 @@ var thirdLineNum = 9,
30 var logoAngle = 0, 30 var logoAngle = 0,
31 loopTime = 500; 31 loopTime = 500;
32 32
  33 +var dataLayer = [];
  34 +
33 // handlebars模板 35 // handlebars模板
34 centerFn = handlebars.compile($('#simple-account-info-tpl').html() || ''); 36 centerFn = handlebars.compile($('#simple-account-info-tpl').html() || '');
35 loginFn = handlebars.compile($('#header-login-info-tpl').html() || ''); 37 loginFn = handlebars.compile($('#header-login-info-tpl').html() || '');
@@ -44,6 +46,22 @@ handlebars.registerHelper('notzero', function(v1, options) { @@ -44,6 +46,22 @@ handlebars.registerHelper('notzero', function(v1, options) {
44 } 46 }
45 }); 47 });
46 48
  49 +function getSource(column, postition, event) {
  50 + try {
  51 + dataLayer.push({
  52 + louceng: column,
  53 + weizhi: postition,
  54 + event: event
  55 + });
  56 + } catch (e) {}
  57 +}
  58 +
  59 +function closeCover() {
  60 + var $cover = $('#cover');
  61 +
  62 + $cover.remove();
  63 +}
  64 +
47 // 格式化三级菜单 65 // 格式化三级菜单
48 function formatThirdMenu() { 66 function formatThirdMenu() {
49 $subNav.each(function() { 67 $subNav.each(function() {