Beispiel #1
0
 function __invoke($req, $res, $next)
 {
     $apip = apip::getInstance();
     $captchaType = $req->getAttribute('route')->getArgument('AliceSPA_CaptchaType');
     $body = $req->getParsedBody();
     if (!empty($captchaType) && !empty($body) && !empty($body['AliceSPA_Captcha'])) {
         $captcha = $body['AliceSPA_Captcha'];
         $validTime = null;
         if ($captchaType === 'image') {
             $validTime = configHelper::getCoreConfig()['imageCaptchaValidTime'];
         }
         if ($captchaType === 'SMS') {
             $validTime = configHelper::getCoreConfig()['SMSCaptchaValidTime'];
         }
         $r = VCManager::getInstance()->check($captcha['id'], $captcha['code'], $captchaType, $validTime);
         if ($r === false) {
             $apip->pushError(6);
             return $res;
         }
     } else {
         $apip->pushError(6);
         return $res;
     }
     return $next($req, $res);
 }
        if ($session->set('AliceSPA_VerificationCodes', $codes) === false) {
            return false;
        }
        return $codeId;
    }
    public function check($codeId, $code, $type, $validTime = null)
    {
        $session = session::getInstance();
        $codes = $session->get('AliceSPA_VerificationCodes');
        if (empty($codes)) {
            return false;
        }
        if (empty($codes[$type])) {
            return false;
        }
        if (empty($codes[$type][$codeId])) {
            return false;
        }
        $c = $codes[$type][$codeId];
        if (empty($c)) {
            return false;
        }
        if ($c['Code'] === $code && ($validTime === null || utils::datetimeMysql2PHP($c['CreateTime']) > time() - $validTime)) {
            return true;
        }
        return false;
    }
}
$container['VCManager'] = function () {
    return \AliceSPA\Service\VerificationCodeManager::getInstance();
};