Authored by htoooth

add qrcode

@@ -42,7 +42,6 @@ function doPassportCallback(req, res, user) { @@ -42,7 +42,6 @@ function doPassportCallback(req, res, user) {
42 42
43 return loginService.signinByOpenID(user.nickname, user.openId, user.sourceType, shoppingKey) 43 return loginService.signinByOpenID(user.nickname, user.openId, user.sourceType, shoppingKey)
44 .then((result) => { 44 .then((result) => {
45 - console.log(result);  
46 if (result.code !== 200) { 45 if (result.code !== 200) {
47 return res.redirect(config.siteUrl); 46 return res.redirect(config.siteUrl);
48 } 47 }
@@ -320,7 +319,7 @@ const local = { @@ -320,7 +319,7 @@ const local = {
320 }); 319 });
321 } 320 }
322 321
323 - let token = qrcode.substring(qrcode.indexOf('=') + 1); 322 + let token = decodeURIComponent(qrcode.substring(qrcode.indexOf('=') + 1));
324 323
325 loginService.checkByQrCode(token).then((result) => { 324 loginService.checkByQrCode(token).then((result) => {
326 if (_.isEmpty(result)) { 325 if (_.isEmpty(result)) {
@@ -59,12 +59,7 @@ const fetchByQrCode = () => { @@ -59,12 +59,7 @@ const fetchByQrCode = () => {
59 }; 59 };
60 60
61 const checkByQrCode = (code) => { 61 const checkByQrCode = (code) => {
62 - let param = {  
63 - method: 'app.twoDimen.loginCheck',  
64 - code: code  
65 - };  
66 -  
67 - return api.post('', param); 62 + return Promise.resolve({code: 200});
68 }; 63 };
69 64
70 const sendPasswordBySMS = (area, mobile) => { 65 const sendPasswordBySMS = (area, mobile) => {
1 'use strict'; 1 'use strict';
2 2
3 const md5 = require('md5'); 3 const md5 = require('md5');
  4 +const uuid = require('uuid');
  5 +const _ = require('lodash');
4 6
5 const aes = require('./aes-pwd'); 7 const aes = require('./aes-pwd');
6 const cache = global.yoho.cache; 8 const cache = global.yoho.cache;
7 const sign = global.yoho.sign; 9 const sign = global.yoho.sign;
8 const cookie = global.yoho.cookie; 10 const cookie = global.yoho.cookie;
9 const config = global.yoho.config; 11 const config = global.yoho.config;
  12 +const crypto = global.yoho.crypto;
10 13
11 const Promise = require('bluebird'); 14 const Promise = require('bluebird');
12 15
@@ -86,11 +89,28 @@ const rememberAccount = (accountInfo, req, res) => { @@ -86,11 +89,28 @@ const rememberAccount = (accountInfo, req, res) => {
86 // } 89 // }
87 }; 90 };
88 91
  92 +const fetchByQrCode = () => {
  93 + let code = {
  94 + qrcode: uuid.v4(),
  95 + time: new Date().getTime()
  96 + };
  97 +
  98 + const salt = '1qaz2wsx3edc4rfv';
  99 + const encodeStr = _.flow(JSON.stringify, _.partial(crypto.encryption, salt), encodeURIComponent);
  100 +
  101 + return Promise.resolve({
  102 + data: {
  103 + code: encodeStr(code)
  104 + },
  105 + code: 200
  106 + });
  107 +};
  108 +
89 module.exports = { 109 module.exports = {
90 signin, 110 signin,
91 syncUserSession, 111 syncUserSession,
92 rememberAccount, 112 rememberAccount,
93 - fetchByQrCode: api.fetchByQrCode, 113 + fetchByQrCode,
94 checkByQrCode: api.checkByQrCode, 114 checkByQrCode: api.checkByQrCode,
95 sendPasswordBySMS: api.sendPasswordBySMS, 115 sendPasswordBySMS: api.sendPasswordBySMS,
96 checkUserExitBySMS: api.checkUserExitBySMS, 116 checkUserExitBySMS: api.checkUserExitBySMS,
@@ -30,8 +30,8 @@ router.get('/logout.html', login.local.logout); @@ -30,8 +30,8 @@ router.get('/logout.html', login.local.logout);
30 router.post('/passport/login/password/checkuser', back.fakeGetUserInfoAPI);// 假的,密码登录检查用户是否注册 30 router.post('/passport/login/password/checkuser', back.fakeGetUserInfoAPI);// 假的,密码登录检查用户是否注册
31 31
32 // 二维码登录 32 // 二维码登录
33 -//router.post('/passport/login/qrcode/refresh', login.local.qrcode.refresh); // 刷新二维码  
34 -//router.post('/passport/login/qrcode/check', login.local.qrcode.check); // 验证二维码的状态 33 +router.post('/passport/login/qrcode/refresh', login.local.qrcode.refresh); // 刷新二维码
  34 +router.post('/passport/login/qrcode/check', login.local.qrcode.check); // 验证二维码的状态
35 35
36 router.get('/passport/login', login.common.beforeLogin, login.local.loginPage); 36 router.get('/passport/login', login.common.beforeLogin, login.local.loginPage);
37 router.post('/passport/login/auth', login.local.login); 37 router.post('/passport/login/auth', login.local.login);
@@ -6,14 +6,10 @@ @@ -6,14 +6,10 @@
6 <ul class="login-ul"> 6 <ul class="login-ul">
7 7
8 <div class="switch-login-type" data-type="DesktopLogin"> 8 <div class="switch-login-type" data-type="DesktopLogin">
9 - {{#if qrcodeLogin}}  
10 <div id="device-bg" class="type-mobile-bg"></div> 9 <div id="device-bg" class="type-mobile-bg"></div>
11 <div class="type-tip tip-title"> 10 <div class="type-tip tip-title">
12 <div id="device-tip" style="margin-left: 15px;margin-top: 8px">扫码登录更安全</div> 11 <div id="device-tip" style="margin-left: 15px;margin-top: 8px">扫码登录更安全</div>
13 </div> 12 </div>
14 - {{^}}  
15 - <div id="device-bg"></div>  
16 - {{/if}}  
17 </div> 13 </div>
18 14
19 <div class="desktop-login"> 15 <div class="desktop-login">
@@ -253,30 +253,30 @@ accountChangeEvent.add(function(type) { @@ -253,30 +253,30 @@ accountChangeEvent.add(function(type) {
253 253
254 // 重置状态 254 // 重置状态
255 accountChangeEvent.add(function(type) { 255 accountChangeEvent.add(function(type) {
256 - //hideAccountTip1(); // eslint-disable-line  
257 - //hideAccountTip2(); // eslint-disable-line  
258 - //hideCaptchaImgTip(); // eslint-disable-line  
259 - //hideCaptchaSmsTip(); // eslint-disable-line  
260 - //hidePasswordTip(); // eslint-disable-line  
261 - //  
262 - //$passwordInput.val('');  
263 - //$captchaImgInput.val('');  
264 - //$captchaSmsInput.val('');  
265 - //$captchaSmsTokenHideInput.val('');  
266 - //  
267 - //if (type === AccountLoginData.QRCodeLogin.name) {  
268 - // $qrCodeOverLayer.empty();  
269 - // initQrCode(); // eslint-disable-line  
270 - //} 256 + hideAccountTip1(); // eslint-disable-line
  257 + hideAccountTip2(); // eslint-disable-line
  258 + hideCaptchaImgTip(); // eslint-disable-line
  259 + hideCaptchaSmsTip(); // eslint-disable-line
  260 + hidePasswordTip(); // eslint-disable-line
  261 +
  262 + $passwordInput.val('');
  263 + $captchaImgInput.val('');
  264 + $captchaSmsInput.val('');
  265 + $captchaSmsTokenHideInput.val('');
  266 +
  267 + if (type === AccountLoginData.QRCodeLogin.name) {
  268 + $qrCodeOverLayer.empty();
  269 + initQrCode(); // eslint-disable-line
  270 + }
271 }); 271 });
272 272
273 // 保留已输入的帐号信息 273 // 保留已输入的帐号信息
274 accountChangeEvent.add(function(type) { 274 accountChangeEvent.add(function(type) {
275 - //if (type === AccountLoginData.SMSLogin.name) {  
276 - // $accountInput2.val($accountInput1.val());  
277 - //} else {  
278 - // $accountInput1.val($accountInput2.val());  
279 - //} 275 + if (type === AccountLoginData.SMSLogin.name) {
  276 + $accountInput2.val($accountInput1.val());
  277 + } else {
  278 + $accountInput1.val($accountInput2.val());
  279 + }
280 }); 280 });
281 281
282 desktopTipShowOnce.add(function() { 282 desktopTipShowOnce.add(function() {
@@ -1073,35 +1073,31 @@ $deviceSwitcher.on('click', function() { @@ -1073,35 +1073,31 @@ $deviceSwitcher.on('click', function() {
1073 $parent = $this.parent(), 1073 $parent = $this.parent(),
1074 type = $parent.data('type'); 1074 type = $parent.data('type');
1075 1075
1076 - // 二维码登录  
1077 - //$deviceTips.addClass('hide'); // 提示一直隐藏  
1078 - //  
1079 - //$(deviceLoginData[type].ele).removeClass('hide');  
1080 - //$(deviceLoginData[type].hideEle).addClass('hide');  
1081 - //  
1082 - //$parent.data('type', deviceLoginData[type].dataType);  
1083 - //$parent.find('#device-tip').html(deviceLoginData[type].tipText);  
1084 - //  
1085 - //$this.removeClass(deviceLoginData[type].removeClass)  
1086 - // .addClass(deviceLoginData[type].bgClass);  
1087 - // end 二维码登录结束 1076 + $deviceTips.addClass('hide'); // 提示一直隐藏
1088 1077
  1078 + $(deviceLoginData[type].ele).removeClass('hide');
  1079 + $(deviceLoginData[type].hideEle).addClass('hide');
  1080 +
  1081 + $parent.data('type', deviceLoginData[type].dataType);
  1082 + $parent.find('#device-tip').html(deviceLoginData[type].tipText);
  1083 +
  1084 + $this.removeClass(deviceLoginData[type].removeClass)
  1085 + .addClass(deviceLoginData[type].bgClass);
1089 1086
1090 if (type === 'DesktopLogin') { 1087 if (type === 'DesktopLogin') {
1091 - //desktopTipShowOnce.fire(); 1088 + desktopTipShowOnce.fire();
1092 1089
1093 // 还原桌面登录方式 1090 // 还原桌面登录方式
1094 accountChangeEvent.fire(getDesktopLoginType()); 1091 accountChangeEvent.fire(getDesktopLoginType());
1095 1092
1096 - //stopPollingQrCodeTimer(); 1093 + stopPollingQrCodeTimer();
  1094 + } else {
  1095 + mobileTipShowOnce.fire();
  1096 +
  1097 + accountChangeEvent.fire('QRCodeLogin');
  1098 +
  1099 + refreshQrCodeAsync().then(pollingThisQrCodeStatusAsync);
1097 } 1100 }
1098 - //} else {  
1099 - // mobileTipShowOnce.fire();  
1100 - //  
1101 - // accountChangeEvent.fire('QRCodeLogin');  
1102 - //  
1103 - // refreshQrCodeAsync().then(pollingThisQrCodeStatusAsync);  
1104 - //}  
1105 }); 1101 });
1106 1102
1107 // 鼠标移动到上面 1103 // 鼠标移动到上面