checkMailCode($identity, $code); } elseif (CommonValidator::phone($identity)) { $this->checkSmsCode($identity, $code); } else { throw new BadRequestException('verify.invalid_code'); } } public function checkSmsCode($phone, $code) { $service = new VerifyService(); $result = $service->checkSmsCode($phone, $code); if (!$result) { throw new BadRequestException('verify.invalid_sms_code'); } } public function checkMailCode($email, $code) { $service = new VerifyService(); $result = $service->checkMailCode($email, $code); if (!$result) { throw new BadRequestException('verify.invalid_mail_code'); } } public function checkRand($rand) { list($time, $number) = explode('-', $rand); if (abs($time - time()) > 300) { throw new BadRequestException('verify.invalid_rand'); } if ($number < 1000 || $number > 9999) { throw new BadRequestException('verify.invalid_rand'); } return $rand; } public function checkTicket($ticket, $rand) { $ticket = $this->crypt->decrypt($ticket); if ($ticket != $rand) { throw new BadRequestException('verify.invalid_ticket'); } } }