Authored by htoooth

Merge branch 'hotfix/universe' into gray

const CaptchaApi = require('./captcha-api');
const logger = global.yoho.logger;
const config = global.yoho.config;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
... ... @@ -16,28 +17,36 @@ module.exports = class extends global.yoho.BaseModel {
});
}
_checkUniverse(captcha) {
return captcha === config.UNIVERSAL_CAPTCHA ?
Promise.resolve({code: 200}) :
Promise.reject();
}
check(id, captcha) {
return this.api.check(id, captcha).then((result) => {
if (result.code === 200) {
return {
code: 200,
message: '验证成功'
};
} else if (result.code === 503 || result.code === 504 || result.code === 501) {
return {
code: 403,
message: result.message
};
} else {
return {
code: 405,
message: result.message,
data: {
needCaptcha: true
}
};
}
});
return this._checkUniverse(captcha)
.catch(() => this.api.check(id, captcha))
.then((result) => {
if (result.code === 200) {
return {
code: 200,
message: '验证成功'
};
} else if (result.code === 503 || result.code === 504 || result.code === 501) {
return {
code: 403,
message: result.message
};
} else {
return {
code: 405,
message: result.message,
data: {
needCaptcha: true
}
};
}
});
}
... ...
... ... @@ -136,6 +136,7 @@ module.exports = {
id: '356b333091cdb78cd788e7bdd5f05c9f',
key: '6fef8ee77e41429de68455eeb052ce37'
},
UNIVERSAL_CAPTCHA: 'yoho4946abcdef#$%&!@',
apiCache: {
cache: false
},
... ...