Authored by 姜枫

短信登录

... ... @@ -14,18 +14,17 @@ if (config.useOneapm) {
const express = require('express');
const path = require('path');
const uuid = require('uuid');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const favicon = require('serve-favicon');
const session = require('express-session');
const memcached = require('connect-memcached');
const session = require('client-sessions');
const hbs = require('express-handlebars');
const multer = require('connect-multiparty');
const pkg = require('./package.json');
const yohoLib = require('yoho-node-lib');
const app = express();
const MemcachedStore = memcached(session);
// 全局注册library
yohoLib.global(config);
... ... @@ -55,26 +54,21 @@ app.use(cookieParser());
app.use(multer());
app.use(session({
proxy: true,
resave: false,
saveUninitialized: true,
unset: 'destroy',
requestKey: 'session',
cookieName: 'yohoblk-session',
secret: '82dd7e724f2c6870472c89dfa43cf48d',
name: 'yohoblk-session',
cookie: {
domain: config.cookieDomain,
httpOnly: true
},
store: new MemcachedStore({
hosts: config.memcache.session,
prefix: 'yohoblk_session:'
})
domain: config.cookieDomain
}));
app.use((req, res, next) => {
req.user = {}; // 全局的用户数据
req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等
if (!req.session || !req.session.uuid) {
req.session = {
uuid: uuid.v4()
};
}
next();
});
... ...
... ... @@ -183,7 +183,7 @@ const local = {
}, req, res);
}
refer = !BlockRedirectFilter.test(decodeURI(refer)) ? decodeURI(refer) : config.siteUrl;
refer = !BlockRedirectFilter.test(decodeURI(refer)) && refer ? decodeURI(refer) : config.siteUrl;
yield LoginService.syncUserSession(user.uid, req, res).then(() => {
res.json({
... ... @@ -198,7 +198,7 @@ const local = {
})(req, res, next);
},
logout: (req, res) => {
req.session.destroy();
req.session.reset();
const clearAll = (v, k) => {
res.clearCookie(k, {
... ...
... ... @@ -7,6 +7,12 @@
<div class="title">登录 SIGN IN</div>
</li>
<li class="clearfix">
<div class="switch">
<div class="left selected" data-type="PasswordLogin">普通登录</div>
<div class="right" data-type="SMSLogin">手机验证码登录</div>
</div>
</li>
<li class="clearfix">
{{> select-header}}
{{> select-list}}
... ... @@ -22,7 +28,7 @@
</div>
</li>
<li class="clearfix">
<li class="clearfix pwd-wrap">
<div class="pwd-wrapper">
<input id="password" class="input password va needTip" name="password" type="password"
placeholder="Password"
... ... @@ -47,6 +53,19 @@
</div>
</li>
<li class="clearfix sms-code-wrap hide">
<div class="img-captcha-wrapper">
<input id="captcha" class="input va captcha needTip" type="text" name="smsCode" placeholder="短信验证码"
autocomplete="off" maxlength="4">
{{> err-tip}}
</div>
<div class="left sms-btn-wrap">
<input type="submit" id="sms-btn" class="btn sms-btn" value='获取短信验证码'/>
</div>
</li>
<li class="clearfix">
<span class="left login-fail-tip hide">
<span class="iconfont">&#xe61d;</span>
... ...
... ... @@ -23,9 +23,9 @@ module.exports = {
cookieDomain: 'yohoblk.com',
domains: {
singleApi: 'http://single.yoho.cn/',
api: 'http://api.yoho.yohoops.org/',
service: 'http://service.yoho.yohoops.org/',
search: 'http://search.yohoops.org/yohosearch/'
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
search: 'http://search.cn/yohosearch/'
},
useOneapm: false,
useCache: false,
... ...
... ... @@ -34,7 +34,7 @@
"bluebird": "^3.4.0",
"body-parser": "^1.15.0",
"captchapng": "0.0.1",
"connect-memcached": "^0.2.0",
"client-sessions": "^0.7.0",
"connect-multiparty": "^2.0.0",
"cookie-parser": "^1.4.3",
"csurf": "^1.9.0",
... ... @@ -44,7 +44,6 @@
"influxdb-winston": "^1.0.1",
"lodash": "^4.13.1",
"md5": "^2.1.0",
"memcached": "^2.2.2",
"moment": "^2.13.0",
"morgan": "^1.7.0",
"oneapm": "^1.2.20",
... ...

374 Bytes | W: | H:

1.38 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
... ... @@ -29,6 +29,7 @@ var $remember = $('.remember-me');
var captchaUrl = '/passport/images?t='; // /passport/images?t=1454464125
var showCaptcha = false;
var $captchaWrap = $('.captcha-wrap'),
$captchaImg = $captchaWrap.find('#captcha-img');
... ... @@ -47,6 +48,10 @@ var selectedIcon = '&#xe60b;';
require('yoho-jquery-placeholder');
function refreshCaptcha() {
$captchaImg.attr('src', captchaUrl + $.now());
}
function errTip(ele, msg) {
var $errTip = ele.next('.tips');
var $errMsg = $errTip.find('.content');
... ... @@ -189,6 +194,7 @@ function validateCaptchaLocal() {
// 密码错误次数,超过三次显示验证码
function showAccountErrTimes() {
$captchaWrap.removeClass('hide');
showCaptcha = true;
$captchaImg.attr('src', captchaUrl + $.now());
$imgCaptchaInput.val('');
}
... ... @@ -425,3 +431,27 @@ $('input.va').on('keypress', function(e) {
// 首次触发
$imgCaptchaInput.triggerHandler('blur');
$('.login-page .switch > div').off().on('click', function() {
var type = $(this).data('type');
if (type === 'PasswordLogin') {
$('.pwd-wrap').toggleClass('hide');
$('.sms-code-wrap').toggleClass('hide');
if (!showCaptcha) {
$('.captcha-wrap').addClass('hide');
} else {
refreshCaptcha();
}
} else if (type === 'SMSLogin') {
$('.pwd-wrap').toggleClass('hide');
$('.sms-code-wrap').toggleClass('hide');
$('.captcha-wrap').removeClass('hide');
refreshCaptcha();
}
$('.login-page .switch > div').removeClass('selected');
$(this).addClass('selected');
});
... ...
... ... @@ -117,4 +117,56 @@
.img-captcha-wrapper {
width: $captcha;
}
$switchbg: #ccc;
.switch {
width: 100%;
height: 26px;
background: url(/passport/login-mode-bg.png) no-repeat;
font-size: 14px;
.left {
width: 170px;
height: 26px;
text-align: center;
line-height: @height;
position: absolute;
left: 0;
cursor: pointer;
&.selected {
background: url(/passport/login-mode-select.png) no-repeat;
color: white;
}
}
.right {
width: 170px;
height: 26px;
text-align: center;
line-height: @height;
position: absolute;
right: 0;
cursor: pointer;
&.selected {
background: url(/passport/login-mode-select.png) no-repeat;
color: white;
}
}
}
.sms-btn-wrap {
margin-left: 15px;
width: 130px;
height: 44px;
.sms-btn {
width: 100%;
height: 44px;
line-height: 44px;
border: none;
}
}
}
... ...