1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-27 21:10:24 +08:00
2020-04-03 19:20:46 +08:00

42 lines
1.0 KiB
PHP

<?php
namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException;
use App\Library\Validator\Common as CommonValidator;
use App\Services\Captcha as CaptchaService;
use App\Services\VerifyCode as VerifyCodeService;
class Security extends Validator
{
public function checkVerifyCode($key, $code)
{
$verifyCodeService = new VerifyCodeService();
$result = false;
if (CommonValidator::email($key)) {
$result = $verifyCodeService->checkMailCode($key, $code);
} elseif (CommonValidator::phone($key)) {
$result = $verifyCodeService->checkSmsCode($key, $code);
}
if (!$result) {
throw new BadRequestException('security.invalid_verify_code');
}
}
public function checkCaptchaCode($ticket, $rand)
{
$captchaService = new CaptchaService();
$result = $captchaService->verify($ticket, $rand);
if (!$result) {
throw new BadRequestException('security.invalid_captcha_code');
}
}
}