Merge branch 'feature/session2' into 'release/5.6'
Feature/session2 See merge request !488
Showing
20 changed files
with
215 additions
and
181 deletions
@@ -113,13 +113,10 @@ const getUser = (uid) => { | @@ -113,13 +113,10 @@ const getUser = (uid) => { | ||
113 | const getPlatForm = (req) => { | 113 | const getPlatForm = (req) => { |
114 | let userAgent = req.get('User-Agent'); | 114 | let userAgent = req.get('User-Agent'); |
115 | let yoho = {}; | 115 | let yoho = {}; |
116 | - let uids = req.get('User-Agent').match(/uid=([^;]+)/i); | ||
117 | let versions = req.get('User-Agent').match(/app_version=([^;]+)/i); | 116 | let versions = req.get('User-Agent').match(/app_version=([^;]+)/i); |
118 | let arrs = []; | 117 | let arrs = []; |
119 | let isNewVersion = false; | 118 | let isNewVersion = false; |
120 | const isProduction = process.env.NODE_ENV === 'production'; | 119 | const isProduction = process.env.NODE_ENV === 'production'; |
121 | - let sessionKey = _.get(req, 'user.uid.sessionKey'); | ||
122 | - let uid; | ||
123 | 120 | ||
124 | 121 | ||
125 | 122 | ||
@@ -156,16 +153,7 @@ const getPlatForm = (req) => { | @@ -156,16 +153,7 @@ const getPlatForm = (req) => { | ||
156 | if (isProduction) { | 153 | if (isProduction) { |
157 | yoho.http = 'https:'; | 154 | yoho.http = 'https:'; |
158 | } | 155 | } |
159 | - uid = uids && uids.length === 2 ? uids[1] : ''; // 8041246 | ||
160 | - uid = req.user.uid || uid || req.query.uid || req.cookies.studentUID || ''; | ||
161 | - if (uid) { | ||
162 | - yoho.uid = { | ||
163 | - toString: () => { | ||
164 | - return uid.toString(); | ||
165 | - }, | ||
166 | - sessionKey | ||
167 | - }; | ||
168 | - } | 156 | + yoho.uid = req.user.uid; |
169 | yoho.isLogin = yoho.uid ? true : false; | 157 | yoho.isLogin = yoho.uid ? true : false; |
170 | return co(function*() { | 158 | return co(function*() { |
171 | let data = yield getUser(yoho.uid); | 159 | let data = yield getUser(yoho.uid); |
@@ -17,7 +17,7 @@ function humanNum_wan(num) { | @@ -17,7 +17,7 @@ function humanNum_wan(num) { | ||
17 | 17 | ||
18 | exports.beforeIn = (req, res, next) => { | 18 | exports.beforeIn = (req, res, next) => { |
19 | // 将APP登录状态正常化 | 19 | // 将APP登录状态正常化 |
20 | - if (req.yoho.isApp) { | 20 | + if (req.yoho.isApp && !req.user.uid) { |
21 | req.user.uid = req.user.uid || req.query.uid; | 21 | req.user.uid = req.user.uid || req.query.uid; |
22 | } | 22 | } |
23 | 23 |
@@ -26,7 +26,7 @@ exports.checkIsStudent = (req, res, next) => { | @@ -26,7 +26,7 @@ exports.checkIsStudent = (req, res, next) => { | ||
26 | 26 | ||
27 | exports.beforeIn = (req, res, next) => { | 27 | exports.beforeIn = (req, res, next) => { |
28 | // 将APP登录状态正常化 | 28 | // 将APP登录状态正常化 |
29 | - if (req.yoho.isApp) { | 29 | + if (req.yoho.isApp && !req.user.uid) { |
30 | req.user.uid = req.user.uid || req.query.uid; | 30 | req.user.uid = req.user.uid || req.query.uid; |
31 | } | 31 | } |
32 | 32 |
@@ -10,7 +10,10 @@ const _ = require('lodash'); | @@ -10,7 +10,10 @@ const _ = require('lodash'); | ||
10 | const helpers = global.yoho.helpers; | 10 | const helpers = global.yoho.helpers; |
11 | 11 | ||
12 | // 服务器报错页面 | 12 | // 服务器报错页面 |
13 | -const _serverCrash = (res, params) => { | 13 | +const _serverCrash = (res, params, err, next) => { |
14 | + if (err && err.code === 401) { | ||
15 | + return next(err); | ||
16 | + } | ||
14 | params.title = params.title || '有货分期'; | 17 | params.title = params.title || '有货分期'; |
15 | res.render('installment/server-crash', params); | 18 | res.render('installment/server-crash', params); |
16 | }; | 19 | }; |
@@ -27,7 +30,7 @@ const _banksInit = () => { | @@ -27,7 +30,7 @@ const _banksInit = () => { | ||
27 | }; | 30 | }; |
28 | 31 | ||
29 | // 还款列表公共处理块 | 32 | // 还款列表公共处理块 |
30 | -const _repaymentList = (req, res, opt, params) => { | 33 | +const _repaymentList = (req, res, next, opt, params) => { |
31 | params = _.assign({ | 34 | params = _.assign({ |
32 | uid: req.user.uid | 35 | uid: req.user.uid |
33 | }, params); | 36 | }, params); |
@@ -39,16 +42,16 @@ const _repaymentList = (req, res, opt, params) => { | @@ -39,16 +42,16 @@ const _repaymentList = (req, res, opt, params) => { | ||
39 | isInstallmentPage: true, | 42 | isInstallmentPage: true, |
40 | data: result | 43 | data: result |
41 | }, opt)); | 44 | }, opt)); |
42 | - }).catch(() => { | 45 | + }).catch((err) => { |
43 | _serverCrash(res, { | 46 | _serverCrash(res, { |
44 | url: req.originalUrl, | 47 | url: req.originalUrl, |
45 | title: opt.title | 48 | title: opt.title |
46 | - }); | 49 | + }, err, next); |
47 | }); | 50 | }); |
48 | }; | 51 | }; |
49 | 52 | ||
50 | // 开通分期首页 | 53 | // 开通分期首页 |
51 | -const index = (req, res) => { | 54 | +const index = (req, res, next) => { |
52 | let uid = req.user.uid; | 55 | let uid = req.user.uid; |
53 | 56 | ||
54 | Promise.all([ | 57 | Promise.all([ |
@@ -136,15 +139,15 @@ const index = (req, res) => { | @@ -136,15 +139,15 @@ const index = (req, res) => { | ||
136 | isInstallmentPage: true, | 139 | isInstallmentPage: true, |
137 | title: '有货分期' | 140 | title: '有货分期' |
138 | }, result)); | 141 | }, result)); |
139 | - }).catch(() => { | 142 | + }).catch((err) => { |
140 | _serverCrash(res, { | 143 | _serverCrash(res, { |
141 | url: req.originalUrl | 144 | url: req.originalUrl |
142 | - }); | 145 | + }, err, next); |
143 | }); | 146 | }); |
144 | }; | 147 | }; |
145 | 148 | ||
146 | // ajax 请求分期专享商品 | 149 | // ajax 请求分期专享商品 |
147 | -const getInstallmentGoods = (req, res) => { | 150 | +const getInstallmentGoods = (req, res, next) => { |
148 | let allowOrigin = _.get(req, 'headers.origin', null) ? | 151 | let allowOrigin = _.get(req, 'headers.origin', null) ? |
149 | req.headers.origin : req.protocol + '://' + req.headers.host; | 152 | req.headers.origin : req.protocol + '://' + req.headers.host; |
150 | 153 | ||
@@ -162,15 +165,15 @@ const getInstallmentGoods = (req, res) => { | @@ -162,15 +165,15 @@ const getInstallmentGoods = (req, res) => { | ||
162 | } else { | 165 | } else { |
163 | res.json(); | 166 | res.json(); |
164 | } | 167 | } |
165 | - }).catch(() => { | 168 | + }).catch((err) => { |
166 | _serverCrash(res, { | 169 | _serverCrash(res, { |
167 | url: req.originalUrl | 170 | url: req.originalUrl |
168 | - }); | 171 | + }, err, next); |
169 | }); | 172 | }); |
170 | }; | 173 | }; |
171 | 174 | ||
172 | // 开通结果显示 | 175 | // 开通结果显示 |
173 | -const review = (req, res) => { | 176 | +const review = (req, res, next) => { |
174 | let openStatus = req.query.status || false; | 177 | let openStatus = req.query.status || false; |
175 | let uid = req.user.uid; | 178 | let uid = req.user.uid; |
176 | let data = { | 179 | let data = { |
@@ -214,10 +217,10 @@ const review = (req, res) => { | @@ -214,10 +217,10 @@ const review = (req, res) => { | ||
214 | }) | 217 | }) |
215 | } | 218 | } |
216 | }, data)); | 219 | }, data)); |
217 | - }).catch(() => { | 220 | + }).catch((err) => { |
218 | _serverCrash(res, { | 221 | _serverCrash(res, { |
219 | url: req.originalUrl | 222 | url: req.originalUrl |
220 | - }); | 223 | + }, err, next); |
221 | }); | 224 | }); |
222 | 225 | ||
223 | } else { | 226 | } else { |
@@ -249,8 +252,8 @@ const review = (req, res) => { | @@ -249,8 +252,8 @@ const review = (req, res) => { | ||
249 | }; | 252 | }; |
250 | 253 | ||
251 | // 逾期未还款列表 | 254 | // 逾期未还款列表 |
252 | -const overdueList = (req, res) => { | ||
253 | - _repaymentList(req, res, { | 255 | +const overdueList = (req, res, next) => { |
256 | + _repaymentList(req, res, next, { | ||
254 | title: '逾期未还金额', | 257 | title: '逾期未还金额', |
255 | posId: 1 | 258 | posId: 1 |
256 | }, { | 259 | }, { |
@@ -259,8 +262,8 @@ const overdueList = (req, res) => { | @@ -259,8 +262,8 @@ const overdueList = (req, res) => { | ||
259 | }; | 262 | }; |
260 | 263 | ||
261 | // 7日待还款列表 | 264 | // 7日待还款列表 |
262 | -const sevenDayList = (req, res) => { | ||
263 | - _repaymentList(req, res, { | 265 | +const sevenDayList = (req, res, next) => { |
266 | + _repaymentList(req, res, next, { | ||
264 | title: '近7日待还款', | 267 | title: '近7日待还款', |
265 | posId: 2 | 268 | posId: 2 |
266 | }, { | 269 | }, { |
@@ -269,8 +272,8 @@ const sevenDayList = (req, res) => { | @@ -269,8 +272,8 @@ const sevenDayList = (req, res) => { | ||
269 | }; | 272 | }; |
270 | 273 | ||
271 | // 本月待还款列表 | 274 | // 本月待还款列表 |
272 | -const monthRepayList = (req, res) => { | ||
273 | - _repaymentList(req, res, { | 275 | +const monthRepayList = (req, res, next) => { |
276 | + _repaymentList(req, res, next, { | ||
274 | title: '本月待还金额', | 277 | title: '本月待还金额', |
275 | posId: 3 | 278 | posId: 3 |
276 | }, { | 279 | }, { |
@@ -279,8 +282,8 @@ const monthRepayList = (req, res) => { | @@ -279,8 +282,8 @@ const monthRepayList = (req, res) => { | ||
279 | }; | 282 | }; |
280 | 283 | ||
281 | // 待还总金额列表 | 284 | // 待还总金额列表 |
282 | -const totalRepayList = (req, res) => { | ||
283 | - _repaymentList(req, res, { | 285 | +const totalRepayList = (req, res, next) => { |
286 | + _repaymentList(req, res, next, { | ||
284 | title: '待还总金额', | 287 | title: '待还总金额', |
285 | posId: 4 | 288 | posId: 4 |
286 | }, { | 289 | }, { |
@@ -300,7 +303,7 @@ const repayRecordPage = (req, res) => { | @@ -300,7 +303,7 @@ const repayRecordPage = (req, res) => { | ||
300 | }; | 303 | }; |
301 | 304 | ||
302 | // ajax 请求还款记录 | 305 | // ajax 请求还款记录 |
303 | -const getRepayRecord = (req, res) => { | 306 | +const getRepayRecord = (req, res, next) => { |
304 | let params = _.assign({ | 307 | let params = _.assign({ |
305 | uid: req.user.uid, | 308 | uid: req.user.uid, |
306 | pageNo: req.query.page || 1 | 309 | pageNo: req.query.page || 1 |
@@ -315,11 +318,11 @@ const getRepayRecord = (req, res) => { | @@ -315,11 +318,11 @@ const getRepayRecord = (req, res) => { | ||
315 | } else { | 318 | } else { |
316 | res.json(); | 319 | res.json(); |
317 | } | 320 | } |
318 | - }).catch(() => { | 321 | + }).catch((err) => { |
319 | _serverCrash(res, { | 322 | _serverCrash(res, { |
320 | url: req.originalUrl, | 323 | url: req.originalUrl, |
321 | title: '还款记录' | 324 | title: '还款记录' |
322 | - }); | 325 | + }, err, next); |
323 | }); | 326 | }); |
324 | }; | 327 | }; |
325 | 328 | ||
@@ -365,18 +368,18 @@ const bindCard = (req, res) => { | @@ -365,18 +368,18 @@ const bindCard = (req, res) => { | ||
365 | }; | 368 | }; |
366 | 369 | ||
367 | // 添加新银行卡请求 | 370 | // 添加新银行卡请求 |
368 | -const postAccount = (req, res) => { | 371 | +const postAccount = (req, res, next) => { |
369 | var params = _.assign({ | 372 | var params = _.assign({ |
370 | uid: req.user.uid | 373 | uid: req.user.uid |
371 | }, req.query); | 374 | }, req.query); |
372 | 375 | ||
373 | installmentModel.postAccount(params).then((result) => { | 376 | installmentModel.postAccount(params).then((result) => { |
374 | res.json(result); | 377 | res.json(result); |
375 | - }).catch(() => { | 378 | + }).catch((err) => { |
376 | _serverCrash(res, { | 379 | _serverCrash(res, { |
377 | url: req.originalUrl, | 380 | url: req.originalUrl, |
378 | title: '使用新卡还款' | 381 | title: '使用新卡还款' |
379 | - }); | 382 | + }, err, next); |
380 | }); | 383 | }); |
381 | }; | 384 | }; |
382 | 385 | ||
@@ -407,7 +410,7 @@ function getRealIP(req) { | @@ -407,7 +410,7 @@ function getRealIP(req) { | ||
407 | return realIP || forwardedFor.split(',')[0] || req.connection.remoteAddress; | 410 | return realIP || forwardedFor.split(',')[0] || req.connection.remoteAddress; |
408 | } | 411 | } |
409 | 412 | ||
410 | -const activateService = (req, res) => { | 413 | +const activateService = (req, res, next) => { |
411 | 414 | ||
412 | installmentModel.activateService({ | 415 | installmentModel.activateService({ |
413 | uid: req.user.uid, | 416 | uid: req.user.uid, |
@@ -423,34 +426,34 @@ const activateService = (req, res) => { | @@ -423,34 +426,34 @@ const activateService = (req, res) => { | ||
423 | ip: getRealIP(req) | 426 | ip: getRealIP(req) |
424 | }).then((result)=> { | 427 | }).then((result)=> { |
425 | res.json(result); | 428 | res.json(result); |
426 | - }).catch(() => { | 429 | + }).catch((err) => { |
427 | _serverCrash(res, { | 430 | _serverCrash(res, { |
428 | url: req.originalUrl, | 431 | url: req.originalUrl, |
429 | title: '开通有货分期' | 432 | title: '开通有货分期' |
430 | - }); | 433 | + }, err, next); |
431 | }); | 434 | }); |
432 | }; | 435 | }; |
433 | 436 | ||
434 | -const getBankInfo = (req, res) => { | 437 | +const getBankInfo = (req, res, next) => { |
435 | installmentModel.getBankInfo({ | 438 | installmentModel.getBankInfo({ |
436 | cardNo: req.query.cardNo, | 439 | cardNo: req.query.cardNo, |
437 | uid: req.user.uid | 440 | uid: req.user.uid |
438 | }).then((result)=> { | 441 | }).then((result)=> { |
439 | res.json(result); | 442 | res.json(result); |
440 | - }).catch(() => { | 443 | + }).catch((err) => { |
441 | _serverCrash(res, { | 444 | _serverCrash(res, { |
442 | url: req.originalUrl | 445 | url: req.originalUrl |
443 | - }); | 446 | + }, err, next); |
444 | }); | 447 | }); |
445 | }; | 448 | }; |
446 | 449 | ||
447 | -const verifyCode = (req, res) => { | 450 | +const verifyCode = (req, res, next) => { |
448 | installmentModel.sendVerifyCode(req.user.uid || 1, req.query.mobile).then((result)=> { | 451 | installmentModel.sendVerifyCode(req.user.uid || 1, req.query.mobile).then((result)=> { |
449 | res.json(result); | 452 | res.json(result); |
450 | - }).catch(() => { | 453 | + }).catch((err) => { |
451 | _serverCrash(res, { | 454 | _serverCrash(res, { |
452 | url: req.originalUrl | 455 | url: req.originalUrl |
453 | - }); | 456 | + }, err, next); |
454 | }); | 457 | }); |
455 | }; | 458 | }; |
456 | 459 | ||
@@ -465,7 +468,7 @@ const orderIndex = (req, res) => { | @@ -465,7 +468,7 @@ const orderIndex = (req, res) => { | ||
465 | }); | 468 | }); |
466 | }; | 469 | }; |
467 | 470 | ||
468 | -const orderList = (req, res) => { | 471 | +const orderList = (req, res, next) => { |
469 | const params = { | 472 | const params = { |
470 | uid: req.user.uid, | 473 | uid: req.user.uid, |
471 | type: req.query.type || 1, | 474 | type: req.query.type || 1, |
@@ -493,15 +496,15 @@ const orderList = (req, res) => { | @@ -493,15 +496,15 @@ const orderList = (req, res) => { | ||
493 | layout: false, | 496 | layout: false, |
494 | isInstallmentPage: true | 497 | isInstallmentPage: true |
495 | }); | 498 | }); |
496 | - }).catch(() => { | 499 | + }).catch((err) => { |
497 | _serverCrash(res, { | 500 | _serverCrash(res, { |
498 | url: req.originalUrl, | 501 | url: req.originalUrl, |
499 | title: '我的分期订单' | 502 | title: '我的分期订单' |
500 | - }); | 503 | + }, err, next); |
501 | }); | 504 | }); |
502 | }; | 505 | }; |
503 | 506 | ||
504 | -const orderDetail = (req, res) => { | 507 | +const orderDetail = (req, res, next) => { |
505 | const params = { | 508 | const params = { |
506 | uid: req.user.uid, | 509 | uid: req.user.uid, |
507 | orderCode: req.params.id | 510 | orderCode: req.params.id |
@@ -586,16 +589,16 @@ const orderDetail = (req, res) => { | @@ -586,16 +589,16 @@ const orderDetail = (req, res) => { | ||
586 | } | 589 | } |
587 | } | 590 | } |
588 | }); | 591 | }); |
589 | - }).catch(() => { | 592 | + }).catch((err) => { |
590 | _serverCrash(res, { | 593 | _serverCrash(res, { |
591 | url: req.originalUrl, | 594 | url: req.originalUrl, |
592 | title: '分期详情' | 595 | title: '分期详情' |
593 | - }); | 596 | + }, err, next); |
594 | }); | 597 | }); |
595 | }; | 598 | }; |
596 | 599 | ||
597 | // 还款详情 | 600 | // 还款详情 |
598 | -const repayDetail = (req, res) => { | 601 | +const repayDetail = (req, res, next) => { |
599 | let params = { | 602 | let params = { |
600 | uid: req.user.uid, | 603 | uid: req.user.uid, |
601 | rePayNo: req.query.id || '', | 604 | rePayNo: req.query.id || '', |
@@ -608,11 +611,11 @@ const repayDetail = (req, res) => { | @@ -608,11 +611,11 @@ const repayDetail = (req, res) => { | ||
608 | isInstallmentPage: true, | 611 | isInstallmentPage: true, |
609 | isOne: true | 612 | isOne: true |
610 | }, result[0])); | 613 | }, result[0])); |
611 | - }).catch(() => { | 614 | + }).catch((err) => { |
612 | _serverCrash(res, { | 615 | _serverCrash(res, { |
613 | url: req.originalUrl, | 616 | url: req.originalUrl, |
614 | title: '还款详情' | 617 | title: '还款详情' |
615 | - }); | 618 | + }, err, next); |
616 | }); | 619 | }); |
617 | }; | 620 | }; |
618 | 621 | ||
@@ -631,24 +634,24 @@ const agreement = (req, res) => { | @@ -631,24 +634,24 @@ const agreement = (req, res) => { | ||
631 | }; | 634 | }; |
632 | 635 | ||
633 | // 计算金额 | 636 | // 计算金额 |
634 | -const totalAmount = (req, res) => { | 637 | +const totalAmount = (req, res, next) => { |
635 | installmentModel.totalAmount(req.query.prices).then((result) => { | 638 | installmentModel.totalAmount(req.query.prices).then((result) => { |
636 | res.json(result); | 639 | res.json(result); |
637 | - }).catch(() => { | 640 | + }).catch((err) => { |
638 | _serverCrash(res, { | 641 | _serverCrash(res, { |
639 | url: req.originalUrl | 642 | url: req.originalUrl |
640 | - }); | 643 | + }, err, next); |
641 | }); | 644 | }); |
642 | }; | 645 | }; |
643 | 646 | ||
644 | // 检查验证码 | 647 | // 检查验证码 |
645 | -const checkVerifyCode = (req, res) => { | 648 | +const checkVerifyCode = (req, res, next) => { |
646 | installmentModel.checkVerifyCode(req.user.uid, req.query.mobile, req.query.code).then((result) => { | 649 | installmentModel.checkVerifyCode(req.user.uid, req.query.mobile, req.query.code).then((result) => { |
647 | res.json(result); | 650 | res.json(result); |
648 | - }).catch(() => { | 651 | + }).catch((err) => { |
649 | _serverCrash(res, { | 652 | _serverCrash(res, { |
650 | url: req.originalUrl | 653 | url: req.originalUrl |
651 | - }); | 654 | + }, err, next); |
652 | }); | 655 | }); |
653 | }; | 656 | }; |
654 | 657 | ||
@@ -658,7 +661,7 @@ const serverCrash = (req, res) => { | @@ -658,7 +661,7 @@ const serverCrash = (req, res) => { | ||
658 | }; | 661 | }; |
659 | 662 | ||
660 | // 银行卡列表 | 663 | // 银行卡列表 |
661 | -const bankCard = (req, res) => { | 664 | +const bankCard = (req, res, next) => { |
662 | let uid = req.user.uid; | 665 | let uid = req.user.uid; |
663 | 666 | ||
664 | installmentModel.getBankCards(uid).then((result) => { | 667 | installmentModel.getBankCards(uid).then((result) => { |
@@ -668,18 +671,18 @@ const bankCard = (req, res) => { | @@ -668,18 +671,18 @@ const bankCard = (req, res) => { | ||
668 | title: '我的银行卡', | 671 | title: '我的银行卡', |
669 | isInstallmentPage: true, | 672 | isInstallmentPage: true, |
670 | accountList: result, | 673 | accountList: result, |
671 | - userName: result[0].userName | 674 | + userName: _.get(result, '[0].userName') |
672 | }); | 675 | }); |
673 | - }).catch(() => { | 676 | + }).catch((err) => { |
674 | _serverCrash(res, { | 677 | _serverCrash(res, { |
675 | url: req.originalUrl, | 678 | url: req.originalUrl, |
676 | title: '我的银行卡' | 679 | title: '我的银行卡' |
677 | - }); | 680 | + }, err, next); |
678 | }); | 681 | }); |
679 | }; | 682 | }; |
680 | 683 | ||
681 | // 银行卡详情 | 684 | // 银行卡详情 |
682 | -const cardDetail = (req, res) => { | 685 | +const cardDetail = (req, res, next) => { |
683 | let uid = req.user.uid; | 686 | let uid = req.user.uid; |
684 | let cardIdNo = req.query.cardIdNo; | 687 | let cardIdNo = req.query.cardIdNo; |
685 | 688 | ||
@@ -692,16 +695,16 @@ const cardDetail = (req, res) => { | @@ -692,16 +695,16 @@ const cardDetail = (req, res) => { | ||
692 | width750: true, | 695 | width750: true, |
693 | cardDetail: result | 696 | cardDetail: result |
694 | }); | 697 | }); |
695 | - }).catch(() => { | 698 | + }).catch((err) => { |
696 | _serverCrash(res, { | 699 | _serverCrash(res, { |
697 | url: req.originalUrl, | 700 | url: req.originalUrl, |
698 | title: '银行卡详情' | 701 | title: '银行卡详情' |
699 | - }); | 702 | + }, err, next); |
700 | }); | 703 | }); |
701 | }; | 704 | }; |
702 | 705 | ||
703 | // 删除绑定 | 706 | // 删除绑定 |
704 | -const delBankCard = (req, res) => { | 707 | +const delBankCard = (req, res, next) => { |
705 | let params = { | 708 | let params = { |
706 | uid: req.user.uid, | 709 | uid: req.user.uid, |
707 | cardIdNo: req.query.cardIdNo | 710 | cardIdNo: req.query.cardIdNo |
@@ -709,16 +712,16 @@ const delBankCard = (req, res) => { | @@ -709,16 +712,16 @@ const delBankCard = (req, res) => { | ||
709 | 712 | ||
710 | installmentModel.delBankCard(params).then((result) => { | 713 | installmentModel.delBankCard(params).then((result) => { |
711 | res.json(result); | 714 | res.json(result); |
712 | - }).catch(() => { | 715 | + }).catch((err) => { |
713 | _serverCrash(res, { | 716 | _serverCrash(res, { |
714 | url: req.originalUrl, | 717 | url: req.originalUrl, |
715 | title: '银行卡详情' | 718 | title: '银行卡详情' |
716 | - }); | 719 | + }, err, next); |
717 | }); | 720 | }); |
718 | }; | 721 | }; |
719 | 722 | ||
720 | // 切换银行卡绑定 | 723 | // 切换银行卡绑定 |
721 | -const setMasterCard = (req, res) => { | 724 | +const setMasterCard = (req, res, next) => { |
722 | let params = { | 725 | let params = { |
723 | uid: req.user.uid, | 726 | uid: req.user.uid, |
724 | cardIdNo: req.query.cardIdNo | 727 | cardIdNo: req.query.cardIdNo |
@@ -726,27 +729,15 @@ const setMasterCard = (req, res) => { | @@ -726,27 +729,15 @@ const setMasterCard = (req, res) => { | ||
726 | 729 | ||
727 | installmentModel.setMasterCard(params).then((result) => { | 730 | installmentModel.setMasterCard(params).then((result) => { |
728 | res.json(result); | 731 | res.json(result); |
729 | - }).catch(() => { | 732 | + }).catch((err) => { |
730 | _serverCrash(res, { | 733 | _serverCrash(res, { |
731 | url: req.originalUrl, | 734 | url: req.originalUrl, |
732 | title: '银行卡详情' | 735 | title: '银行卡详情' |
733 | - }); | 736 | + }, err, next); |
734 | }); | 737 | }); |
735 | }; | 738 | }; |
736 | 739 | ||
737 | const sessionKeyAuth = (req, res, next) => { | 740 | const sessionKeyAuth = (req, res, next) => { |
738 | - let uid = req.query.uid || req.cookies.installmentUid || (req.user.uid && req.user.uid.toString()) || ''; | ||
739 | - let sessionKey = _.get(req, 'user.uid.sessionKey'); | ||
740 | - | ||
741 | - if (sessionKey && !req.session.SESSION_KEY) { | ||
742 | - req.session.SESSION_KEY = uid.sessionKey; | ||
743 | - } | ||
744 | - req.user.uid = { | ||
745 | - toString: () => { | ||
746 | - return uid.toString(); | ||
747 | - }, | ||
748 | - sessionKey | ||
749 | - }; | ||
750 | next(); | 741 | next(); |
751 | }; | 742 | }; |
752 | 743 |
@@ -19,25 +19,6 @@ const codeContent = { | @@ -19,25 +19,6 @@ const codeContent = { | ||
19 | advertisement: 'f3fe0793a7d59479542a14b15359c47d' | 19 | advertisement: 'f3fe0793a7d59479542a14b15359c47d' |
20 | }; | 20 | }; |
21 | 21 | ||
22 | -/** | ||
23 | - * 处理旧版本的app兼容新接口 | ||
24 | - * @param {*} url url | ||
25 | - * @param {*} data data | ||
26 | - * @param {*} param param | ||
27 | - * @param {*} method method | ||
28 | - */ | ||
29 | -const middleApi = (url, data, param, method) => { | ||
30 | - try { | ||
31 | - let promise = method === 'post' ? api.post : api.get; | ||
32 | - | ||
33 | - if (!_.get(data, 'uid.sessionKey', '') && data.uid) { | ||
34 | - data.app_version = '5.5.0'; | ||
35 | - } | ||
36 | - return promise.call(api, url, data, param); | ||
37 | - } catch (err) { | ||
38 | - return null; | ||
39 | - } | ||
40 | -}; | ||
41 | 22 | ||
42 | // 处理还款列表数据 | 23 | // 处理还款列表数据 |
43 | const _processAmtList = (listData, queryDays) => { | 24 | const _processAmtList = (listData, queryDays) => { |
@@ -217,7 +198,7 @@ const _DEBUG = false;// true; | @@ -217,7 +198,7 @@ const _DEBUG = false;// true; | ||
217 | 198 | ||
218 | // 获取分期开通状态 | 199 | // 获取分期开通状态 |
219 | const getStauts = (uid) => { | 200 | const getStauts = (uid) => { |
220 | - return middleApi('', { | 201 | + return api.get('', { |
221 | method: 'user.instalment.getStatus', | 202 | method: 'user.instalment.getStatus', |
222 | uid: uid | 203 | uid: uid |
223 | }, { | 204 | }, { |
@@ -234,7 +215,7 @@ const getStauts = (uid) => { | @@ -234,7 +215,7 @@ const getStauts = (uid) => { | ||
234 | 215 | ||
235 | // 获取用户可用额度信息 | 216 | // 获取用户可用额度信息 |
236 | const getQueryCreditInfo = (uid) => { | 217 | const getQueryCreditInfo = (uid) => { |
237 | - return middleApi('', { | 218 | + return api.get('', { |
238 | method: 'user.instalment.queryCreditLimit', | 219 | method: 'user.instalment.queryCreditLimit', |
239 | uid: uid | 220 | uid: uid |
240 | }, { | 221 | }, { |
@@ -251,7 +232,7 @@ const getQueryCreditInfo = (uid) => { | @@ -251,7 +232,7 @@ const getQueryCreditInfo = (uid) => { | ||
251 | 232 | ||
252 | // 获取用户待还款金额 | 233 | // 获取用户待还款金额 |
253 | const getQueryAmtInfo = (uid) => { | 234 | const getQueryAmtInfo = (uid) => { |
254 | - return middleApi('', { | 235 | + return api.get('', { |
255 | method: 'app.order.queryAmtInfo', | 236 | method: 'app.order.queryAmtInfo', |
256 | uid: uid | 237 | uid: uid |
257 | }, { | 238 | }, { |
@@ -270,7 +251,7 @@ const getQueryAmtInfo = (uid) => { | @@ -270,7 +251,7 @@ const getQueryAmtInfo = (uid) => { | ||
270 | 251 | ||
271 | // 获取用户待还列表信息 queryDays -1:逾期待还;0:全部待还;7:七日待还;30:本月待还 | 252 | // 获取用户待还列表信息 queryDays -1:逾期待还;0:全部待还;7:七日待还;30:本月待还 |
272 | const getQueryAmtList = (params) => { | 253 | const getQueryAmtList = (params) => { |
273 | - return middleApi('', _.assign({ | 254 | + return api.get('', _.assign({ |
274 | method: 'app.order.queryAmtList', | 255 | method: 'app.order.queryAmtList', |
275 | pageSize: '20' | 256 | pageSize: '20' |
276 | }, params), { | 257 | }, params), { |
@@ -287,14 +268,14 @@ const getQueryAmtList = (params) => { | @@ -287,14 +268,14 @@ const getQueryAmtList = (params) => { | ||
287 | 268 | ||
288 | // 分期专享推荐商品 | 269 | // 分期专享推荐商品 |
289 | const getSearchIntallment = (params) => { | 270 | const getSearchIntallment = (params) => { |
290 | - return middleApi('', { | 271 | + return api.post('', { |
291 | method: 'app.search.instalment', | 272 | method: 'app.search.instalment', |
292 | limit: '50', | 273 | limit: '50', |
293 | page: params.page | 274 | page: params.page |
294 | }, { | 275 | }, { |
295 | cache: true, | 276 | cache: true, |
296 | timeout: API_TIMEOUT | 277 | timeout: API_TIMEOUT |
297 | - }, 'post').then((result) => { | 278 | + }).then((result) => { |
298 | if (result && result.code === 200) { | 279 | if (result && result.code === 200) { |
299 | let goods = productProcess.processProductList(result.data.product_list); | 280 | let goods = productProcess.processProductList(result.data.product_list); |
300 | 281 | ||
@@ -319,7 +300,7 @@ const getSearchIntallment = (params) => { | @@ -319,7 +300,7 @@ const getSearchIntallment = (params) => { | ||
319 | * @param mobile 手机号码 | 300 | * @param mobile 手机号码 |
320 | */ | 301 | */ |
321 | const sendVerifyCode = (uid, mobile) => { | 302 | const sendVerifyCode = (uid, mobile) => { |
322 | - return middleApi('', { | 303 | + return api.get('', { |
323 | method: 'user.instalment.getSnsCheckCode', | 304 | method: 'user.instalment.getSnsCheckCode', |
324 | uid: uid, | 305 | uid: uid, |
325 | mobile: mobile, | 306 | mobile: mobile, |
@@ -342,7 +323,7 @@ const sendVerifyCode = (uid, mobile) => { | @@ -342,7 +323,7 @@ const sendVerifyCode = (uid, mobile) => { | ||
342 | * @returns {*} | 323 | * @returns {*} |
343 | */ | 324 | */ |
344 | const activateService = (params) => { | 325 | const activateService = (params) => { |
345 | - return middleApi('', Object.assign({ | 326 | + return api.get('', Object.assign({ |
346 | method: 'user.instalment.activate' | 327 | method: 'user.instalment.activate' |
347 | }, params), { | 328 | }, params), { |
348 | timeout: 30000 | 329 | timeout: 30000 |
@@ -357,7 +338,7 @@ const activateService = (params) => { | @@ -357,7 +338,7 @@ const activateService = (params) => { | ||
357 | * @returns {*} | 338 | * @returns {*} |
358 | */ | 339 | */ |
359 | const getBankInfo = (params) => { | 340 | const getBankInfo = (params) => { |
360 | - return middleApi('', { | 341 | + return api.get('', { |
361 | method: 'user.instalment.getBankInfoByCardNo', | 342 | method: 'user.instalment.getBankInfoByCardNo', |
362 | cardNo: params.cardNo, | 343 | cardNo: params.cardNo, |
363 | uid: params.uid | 344 | uid: params.uid |
@@ -380,7 +361,7 @@ const getInstallmentOrders = (params) => { | @@ -380,7 +361,7 @@ const getInstallmentOrders = (params) => { | ||
380 | const method = 'app.SpaceOrders.getInstallment'; | 361 | const method = 'app.SpaceOrders.getInstallment'; |
381 | 362 | ||
382 | if (!_DEBUG) { | 363 | if (!_DEBUG) { |
383 | - return middleApi('', { | 364 | + return api.get('', { |
384 | method: method, | 365 | method: method, |
385 | uid: params.uid, | 366 | uid: params.uid, |
386 | type: params.type || 1, | 367 | type: params.type || 1, |
@@ -398,7 +379,7 @@ const getInstallmentOrders = (params) => { | @@ -398,7 +379,7 @@ const getInstallmentOrders = (params) => { | ||
398 | 379 | ||
399 | // 还款记录查询 | 380 | // 还款记录查询 |
400 | const getQueryRePayList = (params) => { | 381 | const getQueryRePayList = (params) => { |
401 | - return middleApi('', _.assign({ | 382 | + return api.get('', _.assign({ |
402 | method: 'app.order.queryRePayList', | 383 | method: 'app.order.queryRePayList', |
403 | pageSize: '20' | 384 | pageSize: '20' |
404 | }, params), { | 385 | }, params), { |
@@ -415,7 +396,7 @@ const getQueryRePayList = (params) => { | @@ -415,7 +396,7 @@ const getQueryRePayList = (params) => { | ||
415 | 396 | ||
416 | // 账号管理 | 397 | // 账号管理 |
417 | const getBankCards = (uid) => { | 398 | const getBankCards = (uid) => { |
418 | - return middleApi('', { | 399 | + return api.get('', { |
419 | method: 'user.instalment.getBankCards', | 400 | method: 'user.instalment.getBankCards', |
420 | uid: uid | 401 | uid: uid |
421 | }, { | 402 | }, { |
@@ -441,7 +422,7 @@ const getBankCards = (uid) => { | @@ -441,7 +422,7 @@ const getBankCards = (uid) => { | ||
441 | const getInstallmentOrderDetail = (params) => { | 422 | const getInstallmentOrderDetail = (params) => { |
442 | const method = 'app.SpaceOrders.installDetail'; | 423 | const method = 'app.SpaceOrders.installDetail'; |
443 | 424 | ||
444 | - return middleApi('', { | 425 | + return api.get('', { |
445 | method: method, | 426 | method: method, |
446 | uid: params.uid, | 427 | uid: params.uid, |
447 | order_code: params.orderCode | 428 | order_code: params.orderCode |
@@ -462,7 +443,7 @@ const getInstallmentOrderDetail = (params) => { | @@ -462,7 +443,7 @@ const getInstallmentOrderDetail = (params) => { | ||
462 | const totalAmount = (params) => { | 443 | const totalAmount = (params) => { |
463 | const method = 'app.order.calPrice'; | 444 | const method = 'app.order.calPrice'; |
464 | 445 | ||
465 | - return middleApi('', { | 446 | + return api.get('', { |
466 | method: method, | 447 | method: method, |
467 | prices: params | 448 | prices: params |
468 | }, { | 449 | }, { |
@@ -476,7 +457,7 @@ const totalAmount = (params) => { | @@ -476,7 +457,7 @@ const totalAmount = (params) => { | ||
476 | const checkVerifyCode = (uid, mobile, code) => { | 457 | const checkVerifyCode = (uid, mobile, code) => { |
477 | const method = 'user.instalment.validateSnsCheckCode'; | 458 | const method = 'user.instalment.validateSnsCheckCode'; |
478 | 459 | ||
479 | - return middleApi('', { | 460 | + return api.get('', { |
480 | uid: uid, | 461 | uid: uid, |
481 | method: method, | 462 | method: method, |
482 | mobile: mobile, | 463 | mobile: mobile, |
@@ -491,7 +472,7 @@ const checkVerifyCode = (uid, mobile, code) => { | @@ -491,7 +472,7 @@ const checkVerifyCode = (uid, mobile, code) => { | ||
491 | 472 | ||
492 | // 添加银行卡请求 | 473 | // 添加银行卡请求 |
493 | const postAccount = (params) => { | 474 | const postAccount = (params) => { |
494 | - return middleApi('', _.assign({ | 475 | + return api.get('', _.assign({ |
495 | method: 'user.instalment.bindingCards' | 476 | method: 'user.instalment.bindingCards' |
496 | }, params), { | 477 | }, params), { |
497 | timeout: 6000 | 478 | timeout: 6000 |
@@ -500,7 +481,7 @@ const postAccount = (params) => { | @@ -500,7 +481,7 @@ const postAccount = (params) => { | ||
500 | 481 | ||
501 | // 获取银行卡详情 | 482 | // 获取银行卡详情 |
502 | const getCardDetail = (uid, cardIdNo) => { | 483 | const getCardDetail = (uid, cardIdNo) => { |
503 | - return middleApi('', { | 484 | + return api.get('', { |
504 | method: 'user.instalment.getBankCardDetail', | 485 | method: 'user.instalment.getBankCardDetail', |
505 | uid: uid, | 486 | uid: uid, |
506 | cardIdNo: cardIdNo | 487 | cardIdNo: cardIdNo |
@@ -518,7 +499,7 @@ const getCardDetail = (uid, cardIdNo) => { | @@ -518,7 +499,7 @@ const getCardDetail = (uid, cardIdNo) => { | ||
518 | 499 | ||
519 | // 解除银行卡绑定 | 500 | // 解除银行卡绑定 |
520 | const delBankCard = (params) => { | 501 | const delBankCard = (params) => { |
521 | - return middleApi('', _.assign({ | 502 | + return api.get('', _.assign({ |
522 | method: 'user.instalment.unbindCard' | 503 | method: 'user.instalment.unbindCard' |
523 | }, params)).then((res) => { | 504 | }, params)).then((res) => { |
524 | return res; | 505 | return res; |
@@ -527,7 +508,7 @@ const delBankCard = (params) => { | @@ -527,7 +508,7 @@ const delBankCard = (params) => { | ||
527 | 508 | ||
528 | // 切换银行卡主卡 | 509 | // 切换银行卡主卡 |
529 | const setMasterCard = (params) => { | 510 | const setMasterCard = (params) => { |
530 | - return middleApi('', _.assign({ | 511 | + return api.get('', _.assign({ |
531 | method: 'user.instalment.toggleCard' | 512 | method: 'user.instalment.toggleCard' |
532 | }, params)).then((res) => { | 513 | }, params)).then((res) => { |
533 | return res; | 514 | return res; |
@@ -536,7 +517,7 @@ const setMasterCard = (params) => { | @@ -536,7 +517,7 @@ const setMasterCard = (params) => { | ||
536 | 517 | ||
537 | // 公告 | 518 | // 公告 |
538 | const getNotices = () => { | 519 | const getNotices = () => { |
539 | - return middleApi('', { | 520 | + return api.get('', { |
540 | method: 'app.resources.getNotices', | 521 | method: 'app.resources.getNotices', |
541 | position: 8, | 522 | position: 8, |
542 | client_type: 'iphone' | 523 | client_type: 'iphone' |
@@ -76,7 +76,13 @@ const common = { | @@ -76,7 +76,13 @@ const common = { | ||
76 | refer && !/signin|login|passport/.test(refer) && res.cookie('refer', encodeURI(refer), { | 76 | refer && !/signin|login|passport/.test(refer) && res.cookie('refer', encodeURI(refer), { |
77 | domain: 'yohobuy.com' | 77 | domain: 'yohobuy.com' |
78 | }); | 78 | }); |
79 | - | 79 | + if (req.yoho.isApp) { |
80 | + return next({ | ||
81 | + code: 401, | ||
82 | + message: 'weblogin', | ||
83 | + refer | ||
84 | + }); | ||
85 | + } | ||
80 | next(); | 86 | next(); |
81 | }, | 87 | }, |
82 | weixinCheck: (req, res, next) => { | 88 | weixinCheck: (req, res, next) => { |
@@ -153,5 +153,4 @@ let captcha = require('./controllers/captcha'); | @@ -153,5 +153,4 @@ let captcha = require('./controllers/captcha'); | ||
153 | router.get('/passport/captcha/get', captcha.get); | 153 | router.get('/passport/captcha/get', captcha.get); |
154 | router.get('/passport/img-check.jpg', captcha.imgCheck); | 154 | router.get('/passport/img-check.jpg', captcha.imgCheck); |
155 | 155 | ||
156 | - | ||
157 | module.exports = router; | 156 | module.exports = router; |
@@ -10,7 +10,6 @@ exports.appAdapter = (req, res, next) => { | @@ -10,7 +10,6 @@ exports.appAdapter = (req, res, next) => { | ||
10 | if (req.yoho.isApp && !req.user.uid) { | 10 | if (req.yoho.isApp && !req.user.uid) { |
11 | req.user.uid = req.query.uid; | 11 | req.user.uid = req.query.uid; |
12 | } | 12 | } |
13 | - | ||
14 | next(); | 13 | next(); |
15 | }; | 14 | }; |
16 | 15 |
@@ -15,11 +15,16 @@ module.exports = (req, res, next) => { | @@ -15,11 +15,16 @@ module.exports = (req, res, next) => { | ||
15 | message: '抱歉,您暂未登录!', | 15 | message: '抱歉,您暂未登录!', |
16 | redirect: '/passport/login' | 16 | redirect: '/passport/login' |
17 | }); | 17 | }); |
18 | + } else if (req.yoho.isApp) { | ||
19 | + return next({ | ||
20 | + code: 401, | ||
21 | + message: 'weblogin' | ||
22 | + }); | ||
23 | + } else { | ||
24 | + return res.redirect(helpers.urlFormat('/signin.html', { | ||
25 | + refer: req.originalUrl | ||
26 | + })); | ||
18 | } | 27 | } |
19 | - | ||
20 | - return res.redirect(helpers.urlFormat('/signin.html', { | ||
21 | - refer: req.originalUrl | ||
22 | - })); | ||
23 | } | 28 | } |
24 | 29 | ||
25 | next(); | 30 | next(); |
@@ -52,7 +52,23 @@ exports.serverError = () => { | @@ -52,7 +52,23 @@ exports.serverError = () => { | ||
52 | 52 | ||
53 | if (err && err.code === 401) { | 53 | if (err && err.code === 401) { |
54 | if (req.xhr) { | 54 | if (req.xhr) { |
55 | - return res.json(err); | 55 | + return res.status(401).json(err); |
56 | + } else if (req.yoho.isApp) { | ||
57 | + if (err.lowVersion) { | ||
58 | + return res.render('error/app-auth', { | ||
59 | + module: 'common', | ||
60 | + page: 'app-update', | ||
61 | + localCss: true, | ||
62 | + message: err.message | ||
63 | + }); | ||
64 | + } | ||
65 | + return res.render('error/app-auth', { | ||
66 | + module: 'common', | ||
67 | + page: 'app-redirect-login', | ||
68 | + message: '验证失败,请登录', | ||
69 | + localCss: true, | ||
70 | + refer: err.refer | ||
71 | + }); | ||
56 | } else { | 72 | } else { |
57 | return res.redirect(helpers.urlFormat('/signin.html', { | 73 | return res.redirect(helpers.urlFormat('/signin.html', { |
58 | refer: req.originalUrl | 74 | refer: req.originalUrl |
@@ -48,7 +48,7 @@ module.exports = () => { | @@ -48,7 +48,7 @@ module.exports = () => { | ||
48 | yoho.channel = channel; | 48 | yoho.channel = channel; |
49 | 49 | ||
50 | // 判断请求是否来自app | 50 | // 判断请求是否来自app |
51 | - yoho.isApp = req.query.app_version || req.query.appVersion; | 51 | + yoho.isApp = req.query.app_version || req.query.appVersion || req.cookies.app_version; |
52 | yoho.isWechat = /micromessenger/i.test(req.get('User-Agent') || ''); | 52 | yoho.isWechat = /micromessenger/i.test(req.get('User-Agent') || ''); |
53 | yoho.isWeibo = ua.indexOf('weibo') !== -1; | 53 | yoho.isWeibo = ua.indexOf('weibo') !== -1; |
54 | yoho.isqq = /MQQBrowser/i.test(req.get('User-Agent') || ''); | 54 | yoho.isqq = /MQQBrowser/i.test(req.get('User-Agent') || ''); |
@@ -33,42 +33,22 @@ module.exports = () => { | @@ -33,42 +33,22 @@ module.exports = () => { | ||
33 | }; | 33 | }; |
34 | } | 34 | } |
35 | 35 | ||
36 | - if (!req.user.uid && req.cookies.app_uid && req.cookies.app_session_key) { | 36 | + if (!req.user.uid && |
37 | + req.cookies.app_uid && | ||
38 | + req.cookies.app_uid !== '0' && | ||
39 | + req.cookies.app_session_key && | ||
40 | + req.cookies.app_version && | ||
41 | + req.cookies.app_client_type) { | ||
37 | // 调用接口传参时切勿使用toString获得字符串 | 42 | // 调用接口传参时切勿使用toString获得字符串 |
38 | req.user.uid = { | 43 | req.user.uid = { |
39 | toString: () => { | 44 | toString: () => { |
40 | - return req.cookies.app_uid; | 45 | + return _.parseInt(req.cookies.app_uid); |
41 | }, | 46 | }, |
42 | sessionKey: req.cookies.app_session_key, | 47 | sessionKey: req.cookies.app_session_key, |
43 | - appVersion: req.cookies.app_version || void 0, | ||
44 | - appSessionType: req.cookies.app_client_type || void 0 | 48 | + appVersion: req.cookies.app_version, |
49 | + appSessionType: req.cookies.app_client_type | ||
45 | }; | 50 | }; |
46 | } | 51 | } |
47 | - | ||
48 | - if (!req.user.uid && | ||
49 | - (req.query.uid || req.cookies.app_uid) && | ||
50 | - (req.query.client_type || req.cookies.app_client_type) && | ||
51 | - (req.query.app_version || req.cookies.app_version)) { | ||
52 | - let uid = req.query.uid || req.cookies.app_uid; | ||
53 | - | ||
54 | - req.query.uid = { | ||
55 | - toString: () => { | ||
56 | - return uid; | ||
57 | - }, | ||
58 | - appVersion: req.query.app_version || req.cookies.app_version || void 0, | ||
59 | - appSessionType: req.query.client_type || req.cookies.app_client_type || void 0 | ||
60 | - }; | ||
61 | - res.cookie('app_uid', req.query.uid.toString(), { | ||
62 | - domain: 'm.yohobuy.com' | ||
63 | - }); | ||
64 | - res.cookie('app_client_type', req.query.uid.appSessionType, { | ||
65 | - domain: 'm.yohobuy.com' | ||
66 | - }); | ||
67 | - res.cookie('app_version', req.query.uid.appVersion, { | ||
68 | - domain: 'm.yohobuy.com' | ||
69 | - }); | ||
70 | - } | ||
71 | - | ||
72 | next(); | 52 | next(); |
73 | }; | 53 | }; |
74 | }; | 54 | }; |
doraemon/views/error/app-auth.hbs
0 → 100644
@@ -50,7 +50,7 @@ | @@ -50,7 +50,7 @@ | ||
50 | "xml2js": "^0.4.17", | 50 | "xml2js": "^0.4.17", |
51 | "yoho-express-session": "^2.0.0", | 51 | "yoho-express-session": "^2.0.0", |
52 | "yoho-md5": "^2.0.0", | 52 | "yoho-md5": "^2.0.0", |
53 | - "yoho-node-lib": "=0.2.17", | 53 | + "yoho-node-lib": "=0.2.18", |
54 | "yoho-zookeeper": "^1.0.8" | 54 | "yoho-zookeeper": "^1.0.8" |
55 | }, | 55 | }, |
56 | "devDependencies": { | 56 | "devDependencies": { |
@@ -66,7 +66,7 @@ const cssLoader = (env, type) => { | @@ -66,7 +66,7 @@ const cssLoader = (env, type) => { | ||
66 | 66 | ||
67 | const getEntries = () => { | 67 | const getEntries = () => { |
68 | const entries = { | 68 | const entries = { |
69 | - libs: ['babel-polyfill', 'yoho-jquery'], | 69 | + libs: ['babel-polyfill', 'yoho-jquery', path.join(__dirname, '../js/global.js')], |
70 | index: path.join(__dirname, '../scss/index.css'), | 70 | index: path.join(__dirname, '../scss/index.css'), |
71 | common: path.join(__dirname, '../scss/common.css'), | 71 | common: path.join(__dirname, '../scss/common.css'), |
72 | feature: path.join(__dirname, '../scss/feature.css') | 72 | feature: path.join(__dirname, '../scss/feature.css') |
public/js/common/app-redirect-login.page.js
0 → 100644
1 | +((function() { | ||
2 | + require('common/_app-auth.css'); | ||
3 | + let yohoApp = require('../yoho-app'), | ||
4 | + $ = require('yoho-jquery'), | ||
5 | + cookie = require('yoho-cookie'); | ||
6 | + let $refer = $('#refer'); | ||
7 | + | ||
8 | + let href = location.href; | ||
9 | + | ||
10 | + if ($refer.length) { | ||
11 | + href = $refer.val(); | ||
12 | + if (href.indexOf(location.host) < 0) { | ||
13 | + href = `${location.protocol}//${location.host}${href}`; | ||
14 | + } | ||
15 | + } | ||
16 | + | ||
17 | + let oldSessionKey = localStorage.getItem('oldSessionKey') || ''; | ||
18 | + let oldSessionKeyErr = parseInt(localStorage.getItem('oldSessionKeyErr') || -1, 10); | ||
19 | + let sessionKey = cookie.get('app_session_key'); | ||
20 | + | ||
21 | + if (!sessionKey) { | ||
22 | + return; | ||
23 | + } | ||
24 | + if (oldSessionKey === sessionKey) { | ||
25 | + if (oldSessionKeyErr < 3) { | ||
26 | + localStorage.setItem('oldSessionKeyErr', oldSessionKeyErr + 1); | ||
27 | + } else { | ||
28 | + localStorage.removeItem('oldSessionKeyErr'); | ||
29 | + return; | ||
30 | + } | ||
31 | + } | ||
32 | + localStorage.setItem('oldSessionKey', sessionKey); | ||
33 | + yohoApp.goLogin(href); | ||
34 | +})()); |
public/js/common/app-update.page.js
0 → 100644
1 | +require('common/_app-auth.css'); |
@@ -5,19 +5,25 @@ | @@ -5,19 +5,25 @@ | ||
5 | */ | 5 | */ |
6 | const $ = require('yoho-jquery'); | 6 | const $ = require('yoho-jquery'); |
7 | const cookie = require('yoho-cookie'); | 7 | const cookie = require('yoho-cookie'); |
8 | -let yoho = require('./yoho-app'); | 8 | +const tip = require('plugin/tip'); |
9 | +const yoho = require('./yoho-app'); | ||
9 | 10 | ||
10 | // 初始化 | 11 | // 初始化 |
11 | 12 | ||
12 | // 注册ajaxError处理服务端401状态 | 13 | // 注册ajaxError处理服务端401状态 |
13 | $(document).ajaxError((event, xhr) => { | 14 | $(document).ajaxError((event, xhr) => { |
14 | if (xhr.status === 401) { | 15 | if (xhr.status === 401) { |
15 | - cookie.remove('_UID'); | ||
16 | - cookie.remove('_TOKEN'); | ||
17 | - if (yoho.isApp) { | ||
18 | - yoho.goLogin(window.location.href); | 16 | + if (xhr.responseJSON && xhr.responseJSON.lowVersion) { |
17 | + tip.show(xhr.responseJSON.message); | ||
19 | } else { | 18 | } else { |
20 | - window.location.href = `/signin.html?refer=${encodeURIComponent(window.location.href)}`; | 19 | + cookie.remove('_UID'); |
20 | + cookie.remove('_TOKEN'); | ||
21 | + | ||
22 | + if (yoho.isApp) { | ||
23 | + yoho.goLogin(window.location.href); | ||
24 | + } else { | ||
25 | + window.location.href = `/signin.html?refer=${encodeURIComponent(window.location.href)}`; | ||
26 | + } | ||
21 | } | 27 | } |
22 | } | 28 | } |
23 | }); | 29 | }); |
@@ -14,6 +14,8 @@ let $ = require('yoho-jquery'); | @@ -14,6 +14,8 @@ let $ = require('yoho-jquery'); | ||
14 | let tip = require('./plugin/tip'); | 14 | let tip = require('./plugin/tip'); |
15 | let cookie = require('yoho-cookie'); | 15 | let cookie = require('yoho-cookie'); |
16 | 16 | ||
17 | +require('common'); | ||
18 | + | ||
17 | /* 空方法 */ | 19 | /* 空方法 */ |
18 | let emptyFn = function() {}; | 20 | let emptyFn = function() {}; |
19 | 21 | ||
@@ -35,7 +37,7 @@ yoho = { | @@ -35,7 +37,7 @@ yoho = { | ||
35 | /** | 37 | /** |
36 | * 判断是否是 APP | 38 | * 判断是否是 APP |
37 | */ | 39 | */ |
38 | - isApp: /YohoBuy/i.test(navigator.userAgent || '') || qs && qs.app_version, | 40 | + isApp: /YohoBuy/i.test(navigator.userAgent || '') || qs && qs.app_version || cookie.get('app_version'), |
39 | isiOS: /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(navigator.userAgent || ''), | 41 | isiOS: /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(navigator.userAgent || ''), |
40 | isAndroid: /Android/i.test(navigator.userAgent || ''), | 42 | isAndroid: /Android/i.test(navigator.userAgent || ''), |
41 | 43 | ||
@@ -130,20 +132,35 @@ yoho = { | @@ -130,20 +132,35 @@ yoho = { | ||
130 | 132 | ||
131 | url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(refer); | 133 | url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(refer); |
132 | refer = yoho.parseUrl(refer || location.href); | 134 | refer = yoho.parseUrl(refer || location.href); |
135 | + if (this.isApp) { | ||
136 | + url = location.href; | ||
137 | + if (this.isAndroid) { | ||
138 | + if (url.indexOf('?') < 0) { | ||
139 | + url += '?appLogin=1'; | ||
140 | + } | ||
141 | + if (location.href.indexOf('&openby') >= 0) { | ||
142 | + url = url.substring(0, url.indexOf('&openby')); | ||
143 | + } | ||
144 | + url += '&'; | ||
145 | + } else { | ||
146 | + if (location.href.indexOf('#openby') >= 0) { | ||
147 | + url = url.substring(0, url.indexOf('#openby')); | ||
148 | + } | ||
149 | + url += '#'; | ||
150 | + } | ||
133 | 151 | ||
134 | - if (yoho.isApp) { | ||
135 | - url = url + '&openby:yohobuy=' + (data || JSON.stringify({ | 152 | + url += 'openby:yohobuy=' + (data || JSON.stringify({ |
136 | action: 'go.weblogin', | 153 | action: 'go.weblogin', |
137 | params: { | 154 | params: { |
138 | priority: 'N', | 155 | priority: 'N', |
139 | jumpurl: { | 156 | jumpurl: { |
140 | url: refer.path, | 157 | url: refer.path, |
141 | param: refer.query | 158 | param: refer.query |
142 | - } | 159 | + }, |
160 | + needlogout: 'Y' | ||
143 | } | 161 | } |
144 | })); | 162 | })); |
145 | } | 163 | } |
146 | - | ||
147 | $appLink.attr('href', url); | 164 | $appLink.attr('href', url); |
148 | $appLink[0].click(); | 165 | $appLink[0].click(); |
149 | return false; | 166 | return false; |
-
Please register or login to post a comment