creonit/verification-code-bundle
Composer 安装命令:
composer require creonit/verification-code-bundle
包简介
README 文档
README
# config/packages/creonit_verification_code.yaml creonit_verification_code: generator: config: length: 4 scopes: phone: key_pattern: '/^\+\d{1,3} *(\(\d{3,4}\)|\d{3,4})([ -]*\d){6,7}$/' max_age: 180 attempt_time: 120 scope_name: max_age: 120
# config/routes.yaml api_verification_code: resource: '@CreonitVerificationCodeBundle/Controller/' type: annotation
#custom code generator
use Creonit\VerificationCodeBundle\Generator\AbstractCodeGenerator; use Creonit\VerificationCodeBundle\Generator\Exception\InvalidConfigurationException; class MyCodeGenerator extends AbstractCodeGenerator { public function generate(string $key) { return 'code'; } protected function validateConfig(array $config) { $requiredFields = ['length']; if (!empty($undefinedFields = array_diff($requiredFields, array_keys($config)))) { throw new InvalidConfigurationException(sprintf('Not defined parameters [%s]', implode(', ', $undefinedFields))); } } }
# config/packages/creonit_verification_code.yaml creonit_verification_code: generator: service: '@App\MyCodeGenerator' config: length: 8 my_parameter: 'value'
#scope code generator
# config/packages/creonit_verification_code.yaml creonit_verification_code: scopes: scope_name: generator: service: '@App\MyCodeGenerator' config: length: 8 my_parameter: 'value' max_age: 120
#generate code
POST https://mydomain.com/verificationCode/{scope_name} key={key}
use Creonit\VerificationCodeBundle\CodeManager; use Creonit\VerificationCodeBundle\Context\CodeContext; class PhoneVerificationService { /** * @var CodeManager */ protected $codeManager; public function __construct(CodeManager $codeManager) { $this->codeManager = $codeManager; } /** * @param string $key * * @return \Creonit\VerificationCodeBundle\Model\VerificationCodeInterface */ public function generateCode(string $key) { $context = new CodeContext($key, 'scope_name'); return $this->codeManager->createCode($context); } }
#verification code
PUT https://mydomain.com/verificationCode/{scope_name} key={key} code={code}
use Creonit\VerificationCodeBundle\CodeManager; use Creonit\VerificationCodeBundle\Context\CodeContext; class PhoneVerificationService { /** * @var CodeManager */ protected $codeManager; public function __construct(CodeManager $codeManager) { $this->codeManager = $codeManager; } /** * @param string $key * @param string $code * * @return bool */ public function verificationCode(string $key, string $code) { $context = new CodeContext($key, 'scope_name'); $context->setCode($code); return $this->codeManager->verificationCode($context); } }
#events
Creonit\VerificationCodeBundle\Event\VerificationEvents
统计信息
- 总下载量: 466
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2020-07-21