Showing
1 changed file
with
51 additions
and
4 deletions
@@ -4,6 +4,8 @@ const aes = require('./aes-pwd'); | @@ -4,6 +4,8 @@ const aes = require('./aes-pwd'); | ||
4 | const authcode = require('../../../utils/authcode'); | 4 | const authcode = require('../../../utils/authcode'); |
5 | const logger = global.yoho.logger; | 5 | const logger = global.yoho.logger; |
6 | const sign = global.yoho.sign; | 6 | const sign = global.yoho.sign; |
7 | +const config = global.yoho.config; | ||
8 | +const utils = require('../../../utils'); | ||
7 | const uuid = require('uuid'); | 9 | const uuid = require('uuid'); |
8 | const url = require('url'); | 10 | const url = require('url'); |
9 | const md5 = require('yoho-md5'); | 11 | const md5 = require('yoho-md5'); |
@@ -99,7 +101,7 @@ class AuthModel extends global.yoho.BaseModel { | @@ -99,7 +101,7 @@ class AuthModel extends global.yoho.BaseModel { | ||
99 | return md5(secretStr + clientSecret); | 101 | return md5(secretStr + clientSecret); |
100 | } | 102 | } |
101 | 103 | ||
102 | - thirdLogin(req, res, uid) { | 104 | + referUrl(req, res, uid, sessionKey) { |
103 | if (req.cookies.third_type && req.cookies.third_backurl && req.cookies.third_refer) { | 105 | if (req.cookies.third_type && req.cookies.third_backurl && req.cookies.third_refer) { |
104 | let backurl = url.parse(req.cookies.third_backurl), | 106 | let backurl = url.parse(req.cookies.third_backurl), |
105 | account = thirdAccount[req.cookies.third_type]; | 107 | account = thirdAccount[req.cookies.third_type]; |
@@ -119,7 +121,7 @@ class AuthModel extends global.yoho.BaseModel { | @@ -119,7 +121,7 @@ class AuthModel extends global.yoho.BaseModel { | ||
119 | return { | 121 | return { |
120 | refer: `${backurl.protocol}//${backurl.host}${backurl.pathname}?${queryStr}` | 122 | refer: `${backurl.protocol}//${backurl.host}${backurl.pathname}?${queryStr}` |
121 | }; | 123 | }; |
122 | - } | 124 | + } else { |
123 | res.clearCookie('third_type', { | 125 | res.clearCookie('third_type', { |
124 | domain: 'yohobuy.com' | 126 | domain: 'yohobuy.com' |
125 | }); | 127 | }); |
@@ -129,6 +131,51 @@ class AuthModel extends global.yoho.BaseModel { | @@ -129,6 +131,51 @@ class AuthModel extends global.yoho.BaseModel { | ||
129 | res.clearCookie('third_refer', { | 131 | res.clearCookie('third_refer', { |
130 | domain: 'yohobuy.com' | 132 | domain: 'yohobuy.com' |
131 | }); | 133 | }); |
134 | + try { | ||
135 | + let refer = req.cookies.refer; | ||
136 | + | ||
137 | + if (refer) { | ||
138 | + refer = decodeURI(refer); | ||
139 | + } else { | ||
140 | + refer = `${config.siteUrl}/home`; | ||
141 | + } | ||
142 | + | ||
143 | + if (/sign|login/.test(refer)) { | ||
144 | + refer = `${config.siteUrl}/home`; | ||
145 | + } | ||
146 | + | ||
147 | + refer = utils.refererLimit(refer); | ||
148 | + | ||
149 | + let referUrl; | ||
150 | + | ||
151 | + let backurl = url.parse(refer, false, true); | ||
152 | + const qs = querystring.parse(backurl.query); | ||
153 | + | ||
154 | + if (!qs.skcall) { | ||
155 | + return; // 不处理 外层有各自的refer逻辑 | ||
156 | + } | ||
157 | + let params = Object.assign({ | ||
158 | + uid: uid, | ||
159 | + app_version: config.appVersion, | ||
160 | + app_client_type: config.app, | ||
161 | + session_key: sessionKey | ||
162 | + }, qs); | ||
163 | + let queryStr = _.join(_.map(params, (v, k) => { | ||
164 | + return `${k}=${encodeURIComponent(v)}`; | ||
165 | + }), '&'); | ||
166 | + | ||
167 | + if (backurl.hostname && backurl.protocol) { | ||
168 | + referUrl = `${backurl.protocol}//${backurl.hostname}`; | ||
169 | + } | ||
170 | + referUrl = `${referUrl || ''}${backurl.pathname}?${queryStr}`; | ||
171 | + | ||
172 | + return { | ||
173 | + refer: referUrl | ||
174 | + }; | ||
175 | + } catch (e) { | ||
176 | + return; | ||
177 | + } | ||
178 | + } | ||
132 | } | 179 | } |
133 | 180 | ||
134 | syncUserSession(uid, req, res, sessionKey) { | 181 | syncUserSession(uid, req, res, sessionKey) { |
@@ -192,8 +239,8 @@ class AuthModel extends global.yoho.BaseModel { | @@ -192,8 +239,8 @@ class AuthModel extends global.yoho.BaseModel { | ||
192 | expires: new Date(Date.now() + 2592000000) // 有效期一年 | 239 | expires: new Date(Date.now() + 2592000000) // 有效期一年 |
193 | }); | 240 | }); |
194 | 241 | ||
195 | - // 第三方登录逻辑 | ||
196 | - return this.thirdLogin(req, res, uid); | 242 | + // 登录回调地址 |
243 | + return this.referUrl(req, res, uid, sessionKey); | ||
197 | }); | 244 | }); |
198 | } | 245 | } |
199 | } | 246 | } |
-
Please register or login to post a comment