Authored by 王水玲

登录注册

... ... @@ -56,7 +56,7 @@ passport.use(new LocalStrategy({
let shoppingKey = cookie.getShoppingKey(req);
AuthHelper.signinAes(area, username, password, shoppingKey).then((result) => {
AuthHelper.signin(area, username, password, shoppingKey).then((result) => {
if (result.code && result.code === 200 && result.data.uid) {
done(null, result.data);
} else {
... ...
... ... @@ -35,7 +35,7 @@ const bind = {
res.render('bind/index', {
bindIndex: true, // js标识
backUrl: helpers.urlFormat('/signin.html'), // 返回的URL链接
backUrl: helpers.urlFormat('passport/login'), // 返回的URL链接
showHeaderImg: true, // 控制显示头部图片
isPassportPage: true, // 模板中模块标识
sourceType: sourceType, // 第三方登录来源
... ... @@ -59,7 +59,7 @@ const bind = {
let phoneNum = req.query.phoneNum;
res.render('bind/code', {
backUrl: helpers.urlFormat('/signin.html'),
backUrl: helpers.urlFormat('passport/login'),
showHeaderImg: true,
isPassportPage: true,
sourceType: sourceType,
... ... @@ -168,7 +168,7 @@ const bind = {
}).then(result => {
let refer = req.cookies.refer;
refer = refer ? decodeURI(refer) : helpers.urlFormat();
refer = refer ? decodeURI(refer) : helpers.urlFormat('/bind/success');
if (result && result.code && result.code === 200 && result.data.uid) {
AuthHelper.syncUserSession(result.data.uid, req, res);
result.data.refer = refer;
... ...
... ... @@ -14,7 +14,7 @@ const log = global.yoho.logger;
const config = global.yoho.config;
const AuthHelper = require('../models/auth-helper');
const loginPage = `${config.siteUrl}/passport/login/index`;
const loginPage = `${config.siteUrl}/passport/login`;
function doPassportCallback(openId, nickname, sourceType, req, res) {
let shoppingKey = cookie.getShoppingKey(req);
... ... @@ -45,6 +45,8 @@ function doPassportCallback(openId, nickname, sourceType, req, res) {
}).then((redirectTo) => {
return res.redirect(redirectTo);
});
} else {
return Promise.reject('missing third party login openId or nickname');
}
}
... ... @@ -74,11 +76,11 @@ const local = {
res.render('login', {
loginIndex: true, // 模板中使用JS的标识
// 返回的URL链接
// 返回的URL链接
backUrl: 'javascript:history.go(-1)', // eslint-disable-line
showHeaderImg: true, // 控制显示头部图片
isPassportPage: true, // 模板中模块标识
registerUrl: '/reg.html', // 注册的URL链接
registerUrl: '/passport/reg/index', // 注册的URL链接
aliLoginUrl: '/passport/login/alipay', // 支付宝快捷登录的URL链接
weiboLoginUrl: '/passport/login/sina', // 微博登录的URL链接
qqLoginUrl: '/passport/login/qq', // 腾讯QQ登录的URL链接
... ... @@ -201,12 +203,13 @@ const qq = {
callback: (req, res, next) => {
if (req.session && req.session.authState && req.session.authState === req.query.state) {
passport.authenticate('qq', (err, user) => {
console.log(err, user);
if (err) {
log.error(`qq authenticate error : ${JSON.stringify(err)}`);
return res.redirect(loginPage);
}
let nickname = user.nickname;
let openId = user.openid;
let openId = user.id;
doPassportCallback(openId, nickname, 'qq', req, res).catch(next);
})(req, res, next);
... ...
... ... @@ -9,7 +9,7 @@
const util = require('util');
const _ = require('lodash');
const md5 = require('md5');
const Strategy = require('passport-strategy');
const passport = require('passport-strategy');
// 支付宝网关地址
const ALIPAY_URL = 'https://mapi.alipay.com/gateway.do';
... ... @@ -30,34 +30,30 @@ function paramsToRaw(params) {
let keys = Object.keys(params);
keys = keys.sort();
let newArgs = {};
let string = '';
keys.forEach((key) => {
newArgs[key] = params[key];
string += '&' + key + '=' + params[key];
});
let string = '';
for (let k of newArgs) {
string += '&' + k + '=' + newArgs[k];
}
string = string.substr(1);
return string;
}
function AlipayStrategy(options) {
Strategy.call(this);
function AlipayStrategy(options, verify) {
if (typeof options === 'function') {
verify = options;
}
passport.Strategy.call(this);
this.name = 'alipay';
this._passReqToCallback = options.passReqToCallback;
this._verify = verify;
}
util.inherits(AlipayStrategy, Strategy);
util.inherits(AlipayStrategy, passport.Strategy);
AlipayStrategy.prototype.authenticate = (req, options) => {
if (req.query && req.query.is_success && req.query.sign && req.query.sign_type) {
// sign check
AlipayStrategy.prototype.authenticate = function(req, options) {
if (req.query && req.query.is_success && req.query.sign && req.query.sign_type) {
let query = req.query;
let sign = query.sign;
let signType = query.sign_type;
... ... @@ -85,7 +81,7 @@ AlipayStrategy.prototype.authenticate = (req, options) => {
this.fail(req.error_code);
}
} else {
let params = _.extends(defaultOptions, options);
let params = _.assign(defaultOptions, options);
let signType = params.sign_type;
delete params.sign_type;
... ... @@ -96,9 +92,10 @@ AlipayStrategy.prototype.authenticate = (req, options) => {
params.sign = md5(signString);
params.sign_type = 'MD5';
}
this.redirect(ALIPAY_URL + '?' + paramsToRaw(params));
}
};
module.exports.Strategy = AlipayStrategy;
exports = module.exports = AlipayStrategy;
exports.Strategy = AlipayStrategy;
... ...
... ... @@ -37,6 +37,10 @@ router.get('/login/sina/callback', login.sina.callback);
router.get('/login/qq', login.common.beforeLogin, login.qq.login);
router.get('/login/qq/callback', login.qq.callback);
// 支付宝登录
router.get('/login/alipay', login.common.beforeLogin, login.alipay.login);
router.get('/login/alipay/callback', login.alipay.callback);
// 登录绑定
router.get('/bind/index', bind.indexPage);
router.post('/bind/bindCheck', bind.bindCheck);
... ...
... ... @@ -13,4 +13,4 @@
@import "passport/index";
@import "guang/index";
@import "cart/chose-panel";
@import "me/index";
... ...
@import 'suggest';
\ No newline at end of file
... ...
.yoho-suggest-page {
width: 100%;
height: auto;
.suggest-header {
text-align: center;
color: #fff;
font-size: 26px;
line-height: 46px;
overflow: hidden;
padding-bottom: 20px;
background-image: linear-gradient(#383838, #505050);
&:before {
content: '';
display: block;
background: url("/me/suggest/suggest-logo.png");
width: 104px;
height: 35px;
margin: 10px auto 15px;
}
}
/*意见反馈主体*/
.suggest-content {
border-top: 1px solid #e0e0e0;
}
.suggest-item {
width: 100%;
color: #444;
border-top: 1px solid #e0e0e0;
border-bottom: 30px solid #f0f0f0;
overflow: hidden;
.suggest-item-img {
width: 100%;
overflow: hidden;
> img {
margin: 0 auto;
display: block;
max-width: 100%;
}
}
> h2 {
font-size: 38px;
margin: 30px 0 31px;
padding: 0 35px;
}
> p {
font-size: 26px;
line-height: 48px;
padding: 0 35px;
}
}
.suggest-type {
margin-top: 29px - 11px;
height: 88px;
line-height: 88px;
border-top: 1px solid #e0e0e0;
border-bottom: 1px solid #e0e0e0;
color: #b0b0b0;
font-size: 26px;
display: none;
text-align: center;
> .active {
color: #444;
}
&.show {
display: block;
}
}
.suggest-active {
> div {
width: 50%;
height: 100%;
float: left;
text-align: left;
padding-left: 128px;
box-sizing: border-box;
&:nth-last-of-type(1) {
padding-left: 0;
padding-right: 128px;
text-align: right;
float: right;
> span {
display: inline-block;
height: 100%;
overflow: hidden;
&:nth-of-type(1) {
transform: rotate(180deg);
}
}
}
}
}
.suggest-bad {
> div {
> span {
display: inline-block;
height: 100%;
overflow: hidden;
&:nth-of-type(1) {
transform: rotate(180deg);
}
}
}
}
/*发表意见*/
.create-new-suggest {
display: block;
width: 100%;
height: 88px;
line-height: 88px;
text-align: center;
font-size: 30px;
border-top: 30px solid #f0f0f0;
border-bottom: 30px solid #f0f0f0;
position: relative;
.list-item {
padding: 0 35px;
}
.new-right {
float: right;
margin-left: 40px;
color: #e0e0e0;
}
a {
color: #444;
display: inline-block;
}
}
}
/*提交页面*/
.yoho-suggest-sub-page {
width: 100%;
background: #f0f0f0;
.suggest-sub-form {
background: #fff;
width: 100%;
#suggest-textarea {
box-sizing: border-box;
width: 100%;
max-width: 100%;
min-width: 100%;
height: 255px;
max-height: 255px;
min-height: 255px;
padding: 30px;
font-size: 26px;
line-height: 48px;
color: #000;
display: block;
background: #fff;
border: none;
outline: none;
resize: none;
}
.img-form {
padding: 0 30px;
padding-top: 40px;
overflow: hidden;
.upload-img-list {
float: left;
> li {
display: block;
width: 130px;
height: 130px;
float: left;
margin-right: 30px;
background: resolve('common/loading.gif') center center no-repeat;
background-size: 50%;
position: relative;
> img {
display: block;
width: 100%;
height: 100%;
overflow: hidden;
}
> span {
display: block;
background: url("/me/suggest/sub_del.png");
width: 42px;
height: 42px;
position: absolute;
top: -21px;
right: -21px;
}
}
}
.img-add {
display: block;
width: 130px;
height: 130px;
border: 1px dashed #e0e0e0;
position: relative;
text-indent: -1000px;
float: left;
&:after {
content: '';
display: block;
background: url("/me/suggest/suggest-add.png");
width: 72px;
height: 72px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -36px;
margin-left: -36px;
}
input[type="file"] {
position: absolute;
opacity: 0.2;
border: none;
outline: none;
display: block;
width: 130px;
height: 130px;
top: 0;
left: 0;
}
}
}
}
}
/*dialog*/
.dialog-wrapper {
background: hsla(0, 0%, 0%, .5);
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: none;
.dialog-box {
width: 540px;
border-radius: 20px;
background: hsla(100, 100%, 100%, .8);
position: absolute;
left: 50%;
margin-left: -270px;
font-size: 30px;
text-align: center;
color: #000;
}
.dialog-content {
padding: 60px 30px;
}
.dialog-footer {
border-top: 1px solid #ccc;
height: 88px;
line-height: 88px;
> span {
display: block;
width: 50%;
height: 100%;
float: left;
box-sizing: border-box;
&:nth-last-of-type(1) {
border-left: 1px solid #ccc;
color: #ee0011;
}
}
> span:active {
background-color: #ccc;
}
}
}
... ...