-
Notifications
You must be signed in to change notification settings - Fork 7
/
VerifyController.php
57 lines (50 loc) · 1.47 KB
/
VerifyController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace mdm\filter;
use Yii;
use yii\base\DynamicModel;
/**
* VerifyController
*
* @author Misbahul D Munir <misbahuldmunir@gmail.com>
* @since 1.0
*/
class VerifyController extends \yii\web\Controller
{
/**
* @inheritdoc
*/
public $defaultAction = 'verify';
/**
* @var string file to be rendered
*/
public $viewFile = '@mdm/filter/views/verify.php';
/**
* @var EnterCode
*/
public $filter;
public function actionVerify()
{
$session = Yii::$app->session;
$urlKey = $this->filter->buildKey('_url');
$urls = $session->get($urlKey);
if (is_array($urls) && isset($urls[0], $urls[1])) {
$route = $urls[0];
$returnUrl = $urls[1];
} else {
throw new \yii\base\InvalidCallException();
}
$key = $this->filter->buildKey($route);
$field = 'f' . substr($key, 0, 10);
$model = new DynamicModel([$field]);
$model->addRule($field, 'required');
if ($model->load(Yii::$app->getRequest()->post()) && $model->validate()) {
if ($this->filter->isValid($model->$field, $route)) {
$this->filter->setValid($route);
return Yii::$app->getResponse()->redirect($returnUrl);
} else {
$model->addError($field, $this->filter->message);
}
}
return $this->render($this->viewFile, ['model' => $model, 'field' => $field]);
}
}