Authored by htoooth

add qrcode

... ... @@ -42,7 +42,6 @@ function doPassportCallback(req, res, user) {
return loginService.signinByOpenID(user.nickname, user.openId, user.sourceType, shoppingKey)
.then((result) => {
console.log(result);
if (result.code !== 200) {
return res.redirect(config.siteUrl);
}
... ... @@ -320,7 +319,7 @@ const local = {
});
}
let token = qrcode.substring(qrcode.indexOf('=') + 1);
let token = decodeURIComponent(qrcode.substring(qrcode.indexOf('=') + 1));
loginService.checkByQrCode(token).then((result) => {
if (_.isEmpty(result)) {
... ...
... ... @@ -59,12 +59,7 @@ const fetchByQrCode = () => {
};
const checkByQrCode = (code) => {
let param = {
method: 'app.twoDimen.loginCheck',
code: code
};
return api.post('', param);
return Promise.resolve({code: 200});
};
const sendPasswordBySMS = (area, mobile) => {
... ...
'use strict';
const md5 = require('md5');
const uuid = require('uuid');
const _ = require('lodash');
const aes = require('./aes-pwd');
const cache = global.yoho.cache;
const sign = global.yoho.sign;
const cookie = global.yoho.cookie;
const config = global.yoho.config;
const crypto = global.yoho.crypto;
const Promise = require('bluebird');
... ... @@ -86,11 +89,28 @@ const rememberAccount = (accountInfo, req, res) => {
// }
};
const fetchByQrCode = () => {
let code = {
qrcode: uuid.v4(),
time: new Date().getTime()
};
const salt = '1qaz2wsx3edc4rfv';
const encodeStr = _.flow(JSON.stringify, _.partial(crypto.encryption, salt), encodeURIComponent);
return Promise.resolve({
data: {
code: encodeStr(code)
},
code: 200
});
};
module.exports = {
signin,
syncUserSession,
rememberAccount,
fetchByQrCode: api.fetchByQrCode,
fetchByQrCode,
checkByQrCode: api.checkByQrCode,
sendPasswordBySMS: api.sendPasswordBySMS,
checkUserExitBySMS: api.checkUserExitBySMS,
... ...
... ... @@ -30,8 +30,8 @@ router.get('/logout.html', login.local.logout);
router.post('/passport/login/password/checkuser', back.fakeGetUserInfoAPI);// 假的,密码登录检查用户是否注册
// 二维码登录
//router.post('/passport/login/qrcode/refresh', login.local.qrcode.refresh); // 刷新二维码
//router.post('/passport/login/qrcode/check', login.local.qrcode.check); // 验证二维码的状态
router.post('/passport/login/qrcode/refresh', login.local.qrcode.refresh); // 刷新二维码
router.post('/passport/login/qrcode/check', login.local.qrcode.check); // 验证二维码的状态
router.get('/passport/login', login.common.beforeLogin, login.local.loginPage);
router.post('/passport/login/auth', login.local.login);
... ...
... ... @@ -6,14 +6,10 @@
<ul class="login-ul">
<div class="switch-login-type" data-type="DesktopLogin">
{{#if qrcodeLogin}}
<div id="device-bg" class="type-mobile-bg"></div>
<div class="type-tip tip-title">
<div id="device-tip" style="margin-left: 15px;margin-top: 8px">扫码登录更安全</div>
</div>
{{^}}
<div id="device-bg"></div>
{{/if}}
</div>
<div class="desktop-login">
... ...
... ... @@ -253,30 +253,30 @@ accountChangeEvent.add(function(type) {
// 重置状态
accountChangeEvent.add(function(type) {
//hideAccountTip1(); // eslint-disable-line
//hideAccountTip2(); // eslint-disable-line
//hideCaptchaImgTip(); // eslint-disable-line
//hideCaptchaSmsTip(); // eslint-disable-line
//hidePasswordTip(); // eslint-disable-line
//
//$passwordInput.val('');
//$captchaImgInput.val('');
//$captchaSmsInput.val('');
//$captchaSmsTokenHideInput.val('');
//
//if (type === AccountLoginData.QRCodeLogin.name) {
// $qrCodeOverLayer.empty();
// initQrCode(); // eslint-disable-line
//}
hideAccountTip1(); // eslint-disable-line
hideAccountTip2(); // eslint-disable-line
hideCaptchaImgTip(); // eslint-disable-line
hideCaptchaSmsTip(); // eslint-disable-line
hidePasswordTip(); // eslint-disable-line
$passwordInput.val('');
$captchaImgInput.val('');
$captchaSmsInput.val('');
$captchaSmsTokenHideInput.val('');
if (type === AccountLoginData.QRCodeLogin.name) {
$qrCodeOverLayer.empty();
initQrCode(); // eslint-disable-line
}
});
// 保留已输入的帐号信息
accountChangeEvent.add(function(type) {
//if (type === AccountLoginData.SMSLogin.name) {
// $accountInput2.val($accountInput1.val());
//} else {
// $accountInput1.val($accountInput2.val());
//}
if (type === AccountLoginData.SMSLogin.name) {
$accountInput2.val($accountInput1.val());
} else {
$accountInput1.val($accountInput2.val());
}
});
desktopTipShowOnce.add(function() {
... ... @@ -1073,35 +1073,31 @@ $deviceSwitcher.on('click', function() {
$parent = $this.parent(),
type = $parent.data('type');
// 二维码登录
//$deviceTips.addClass('hide'); // 提示一直隐藏
//
//$(deviceLoginData[type].ele).removeClass('hide');
//$(deviceLoginData[type].hideEle).addClass('hide');
//
//$parent.data('type', deviceLoginData[type].dataType);
//$parent.find('#device-tip').html(deviceLoginData[type].tipText);
//
//$this.removeClass(deviceLoginData[type].removeClass)
// .addClass(deviceLoginData[type].bgClass);
// end 二维码登录结束
$deviceTips.addClass('hide'); // 提示一直隐藏
$(deviceLoginData[type].ele).removeClass('hide');
$(deviceLoginData[type].hideEle).addClass('hide');
$parent.data('type', deviceLoginData[type].dataType);
$parent.find('#device-tip').html(deviceLoginData[type].tipText);
$this.removeClass(deviceLoginData[type].removeClass)
.addClass(deviceLoginData[type].bgClass);
if (type === 'DesktopLogin') {
//desktopTipShowOnce.fire();
desktopTipShowOnce.fire();
// 还原桌面登录方式
accountChangeEvent.fire(getDesktopLoginType());
//stopPollingQrCodeTimer();
stopPollingQrCodeTimer();
} else {
mobileTipShowOnce.fire();
accountChangeEvent.fire('QRCodeLogin');
refreshQrCodeAsync().then(pollingThisQrCodeStatusAsync);
}
//} else {
// mobileTipShowOnce.fire();
//
// accountChangeEvent.fire('QRCodeLogin');
//
// refreshQrCodeAsync().then(pollingThisQrCodeStatusAsync);
//}
});
// 鼠标移动到上面
... ...