承接 vsevolod-ryzhov/yii2-code-validation 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vsevolod-ryzhov/yii2-code-validation

Composer 安装命令:

composer require vsevolod-ryzhov/yii2-code-validation

包简介

Validate form change via secret code (SMS and etc)

README 文档

README

Validate model change via code delivered by external service (SMS, email & etc)

Installation

Via Composer

composer require vsevolod-ryzhov/yii2-code-validation

Usage

Inject service in your Controller:

private $service;

public function __construct($id, $module, \vsevolodryzhov\yii2CodeValidation\Service $service, $config = [])
{
    parent::__construct($id, $module, $config);
    $this->service = $service;
}

create action with some form (Model or ActiveRecord):

public function actionChangeRequest()
{
    $form = new Form();

    if ($form->load(Yii::$app->request->post()) && $form->validate()) {
        // if form submitted and validated use "set" function to store form and get generated code
        $code = $this->service->set($form);
        // send $code here and then redirect to verify action
        return $this->redirect('/verify');
    }

    return $this->render('change', ['form' => $form]);
}

create verify action:

public function actionVerify()
{
    if (!$this->service->exists()) {
        // if nothing to verify - throw new Exception, redirect or do something else
    }

    // create CodeValidationForm (included in this package) with stored code and new instance of same form, created in previews action
    $form = new \vsevolodryzhov\yii2CodeValidation\CodeValidationForm($this->service->getCode(), new Form($this->service->getData()));

    if ($form->load(Yii::$app->request->post()) && $form->validate()) {
        // clear all data on success
        $this->service->clear();
        // refresh or redirect to success page
        return $this->refresh();
    }

    return $this->render('verify', ['form' => $form]);
}

also, you can create additional action for updating existing code

public function actionUpdate()
{
    $response = $this->service->renewCode();
}

renewCode action returns \vsevolodryzhov\yii2CodeValidation\Response object with some useful information:

  • $response->getDone() returns true if code was updated
  • $response->getWait() returns number of seconds time until the next possible update time
  • $response->getCode() returns new code (if generated) or null

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-05-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固