-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathValidationForm.php
72 lines (64 loc) · 1.48 KB
/
ValidationForm.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace omnilight\tokens;
use yii\base\Model;
/**
* Class ValidationForm
* @property null|Token $tokenRecord
*/
class ValidationForm extends Model
{
/**
* @var string Type of the token
*/
public $type;
/**
* @var string Name of the token
*/
public $name;
/**
* @var string Token value entered by user
*/
public $token;
/**
* @var string Label of the token
*/
public $tokenLabel;
/**
* @var string Message shown when token is invalid
*/
public $tokenInvalid;
public function init()
{
if ($this->tokenLabel === null) {
$this->tokenLabel = \Yii::t('omnilight/tokens', 'Token');
}
if ($this->tokenInvalid === null) {
$this->tokenInvalid = \Yii::t('omnilight/tokens', 'Token is incorrect');
}
}
public function rules()
{
return [
[['token'], 'required'],
[['token'], 'string'],
[['token'], function() {
if (Token::compare($this->type, $this->name, $this->token) == null) {
$this->addError('token', $this->tokenInvalid);
}
}]
];
}
public function attributeLabels()
{
return [
'token' => $this->tokenLabel,
];
}
/**
* @return null|Token
*/
public function getTokenRecord()
{
return Token::compare($this->type, $this->name, $this->token);
}
}