...
|
...
|
@@ -4,6 +4,8 @@ const aes = require('./aes-pwd'); |
|
|
const authcode = require('../../../utils/authcode');
|
|
|
const logger = global.yoho.logger;
|
|
|
const sign = global.yoho.sign;
|
|
|
const config = global.yoho.config;
|
|
|
const utils = require('../../../utils');
|
|
|
const uuid = require('uuid');
|
|
|
const url = require('url');
|
|
|
const md5 = require('yoho-md5');
|
...
|
...
|
@@ -99,7 +101,7 @@ class AuthModel extends global.yoho.BaseModel { |
|
|
return md5(secretStr + clientSecret);
|
|
|
}
|
|
|
|
|
|
thirdLogin(req, res, uid) {
|
|
|
referUrl(req, res, uid, sessionKey) {
|
|
|
if (req.cookies.third_type && req.cookies.third_backurl && req.cookies.third_refer) {
|
|
|
let backurl = url.parse(req.cookies.third_backurl),
|
|
|
account = thirdAccount[req.cookies.third_type];
|
...
|
...
|
@@ -119,7 +121,7 @@ class AuthModel extends global.yoho.BaseModel { |
|
|
return {
|
|
|
refer: `${backurl.protocol}//${backurl.host}${backurl.pathname}?${queryStr}`
|
|
|
};
|
|
|
}
|
|
|
} else {
|
|
|
res.clearCookie('third_type', {
|
|
|
domain: 'yohobuy.com'
|
|
|
});
|
...
|
...
|
@@ -129,6 +131,51 @@ class AuthModel extends global.yoho.BaseModel { |
|
|
res.clearCookie('third_refer', {
|
|
|
domain: 'yohobuy.com'
|
|
|
});
|
|
|
try {
|
|
|
let refer = req.cookies.refer;
|
|
|
|
|
|
if (refer) {
|
|
|
refer = decodeURI(refer);
|
|
|
} else {
|
|
|
refer = `${config.siteUrl}/home`;
|
|
|
}
|
|
|
|
|
|
if (/sign|login/.test(refer)) {
|
|
|
refer = `${config.siteUrl}/home`;
|
|
|
}
|
|
|
|
|
|
refer = utils.refererLimit(refer);
|
|
|
|
|
|
let referUrl;
|
|
|
|
|
|
let backurl = url.parse(refer, false, true);
|
|
|
const qs = querystring.parse(backurl.query);
|
|
|
|
|
|
if (!qs.skcall) {
|
|
|
return; // 不处理 外层有各自的refer逻辑
|
|
|
}
|
|
|
let params = Object.assign({
|
|
|
uid: uid,
|
|
|
app_version: config.appVersion,
|
|
|
app_client_type: config.app,
|
|
|
session_key: sessionKey
|
|
|
}, qs);
|
|
|
let queryStr = _.join(_.map(params, (v, k) => {
|
|
|
return `${k}=${encodeURIComponent(v)}`;
|
|
|
}), '&');
|
|
|
|
|
|
if (backurl.hostname && backurl.protocol) {
|
|
|
referUrl = `${backurl.protocol}//${backurl.hostname}`;
|
|
|
}
|
|
|
referUrl = `${referUrl || ''}${backurl.pathname}?${queryStr}`;
|
|
|
|
|
|
return {
|
|
|
refer: referUrl
|
|
|
};
|
|
|
} catch (e) {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
syncUserSession(uid, req, res, sessionKey) {
|
...
|
...
|
@@ -192,8 +239,8 @@ class AuthModel extends global.yoho.BaseModel { |
|
|
expires: new Date(Date.now() + 2592000000) // 有效期一年
|
|
|
});
|
|
|
|
|
|
// 第三方登录逻辑
|
|
|
return this.thirdLogin(req, res, uid);
|
|
|
// 登录回调地址
|
|
|
return this.referUrl(req, res, uid, sessionKey);
|
|
|
});
|
|
|
}
|
|
|
}
|
...
|
...
|
|