Authored by htoooth

fix

1 const CaptchaApi = require('./captcha-api'); 1 const CaptchaApi = require('./captcha-api');
2 const logger = global.yoho.logger; 2 const logger = global.yoho.logger;
  3 +const config = global.yoho.config;
3 4
4 module.exports = class extends global.yoho.BaseModel { 5 module.exports = class extends global.yoho.BaseModel {
5 constructor(ctx) { 6 constructor(ctx) {
@@ -16,28 +17,36 @@ module.exports = class extends global.yoho.BaseModel { @@ -16,28 +17,36 @@ module.exports = class extends global.yoho.BaseModel {
16 }); 17 });
17 } 18 }
18 19
  20 + _checkUniverse(captcha) {
  21 + return captcha === config.UNIVERSAL_CAPTCHA ?
  22 + Promise.resolve({code: 200}) :
  23 + Promise.reject();
  24 + }
  25 +
19 check(id, captcha) { 26 check(id, captcha) {
20 - return this.api.check(id, captcha).then((result) => {  
21 - if (result.code === 200) {  
22 - return {  
23 - code: 200,  
24 - message: '验证成功'  
25 - };  
26 - } else if (result.code === 503 || result.code === 504 || result.code === 501) {  
27 - return {  
28 - code: 403,  
29 - message: result.message  
30 - };  
31 - } else {  
32 - return {  
33 - code: 405,  
34 - message: result.message,  
35 - data: {  
36 - needCaptcha: true  
37 - }  
38 - };  
39 - }  
40 - }); 27 + return this._checkUniverse(captcha)
  28 + .catch(() => this.api.check(id, captcha))
  29 + .then((result) => {
  30 + if (result.code === 200) {
  31 + return {
  32 + code: 200,
  33 + message: '验证成功'
  34 + };
  35 + } else if (result.code === 503 || result.code === 504 || result.code === 501) {
  36 + return {
  37 + code: 403,
  38 + message: result.message
  39 + };
  40 + } else {
  41 + return {
  42 + code: 405,
  43 + message: result.message,
  44 + data: {
  45 + needCaptcha: true
  46 + }
  47 + };
  48 + }
  49 + });
41 } 50 }
42 51
43 52
@@ -136,6 +136,7 @@ module.exports = { @@ -136,6 +136,7 @@ module.exports = {
136 id: '356b333091cdb78cd788e7bdd5f05c9f', 136 id: '356b333091cdb78cd788e7bdd5f05c9f',
137 key: '6fef8ee77e41429de68455eeb052ce37' 137 key: '6fef8ee77e41429de68455eeb052ce37'
138 }, 138 },
  139 + UNIVERSAL_CAPTCHA: 'yoho4946abcdef#$%&!@',
139 apiCache: { 140 apiCache: {
140 cache: false 141 cache: false
141 }, 142 },