|
|
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
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
|