|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace inblank\activeuser\models\forms; |
|
4
|
|
|
|
|
5
|
|
|
use inblank\activeuser\traits\CommonTrait; |
|
6
|
|
|
use yii; |
|
7
|
|
|
use yii\base\Model; |
|
8
|
|
|
|
|
9
|
|
|
class RegisterForm extends Model |
|
10
|
|
|
{ |
|
11
|
|
|
use CommonTrait; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var string user email for register |
|
15
|
|
|
*/ |
|
16
|
|
|
public $email; |
|
17
|
|
|
/** |
|
18
|
|
|
* @var string user name for register |
|
19
|
|
|
*/ |
|
20
|
|
|
public $name; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var string user password for register |
|
23
|
|
|
*/ |
|
24
|
|
|
public $password; |
|
25
|
|
|
|
|
26
|
|
|
/** @inheritdoc */ |
|
27
|
4 |
|
public function attributeLabels() |
|
28
|
|
|
{ |
|
29
|
|
|
return [ |
|
30
|
4 |
|
'email' => Yii::t('activeuser_general', 'Email'), |
|
31
|
4 |
|
'name' => Yii::t('activeuser_general', 'Name'), |
|
32
|
4 |
|
'password' => Yii::t('activeuser_general', 'Password'), |
|
33
|
|
|
]; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @inheritdoc |
|
38
|
|
|
*/ |
|
39
|
4 |
|
public function rules() |
|
40
|
|
|
{ |
|
41
|
|
|
return [ |
|
42
|
4 |
|
['email', 'required'], |
|
43
|
|
|
['email', 'email'], |
|
44
|
4 |
|
['email', 'unique', 'targetClass' => self::di('User'), 'targetAttribute' => 'email'], |
|
45
|
|
|
['name', 'required', 'when' => function () { |
|
46
|
4 |
|
return $this->getModule()->isFieldForRegister('name'); |
|
47
|
4 |
|
}], |
|
48
|
4 |
|
['password', 'required', 'when' => function () { |
|
49
|
4 |
|
return $this->getModule()->isFieldForRegister('password'); |
|
50
|
4 |
|
}], |
|
51
|
|
|
['password', 'string', 'length' => [6, 20], 'skipOnEmpty' => true], |
|
52
|
|
|
]; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Registration |
|
57
|
|
|
* @return bool |
|
58
|
|
|
* @throws yii\base\InvalidConfigException |
|
59
|
|
|
*/ |
|
60
|
4 |
|
public function register() |
|
61
|
|
|
{ |
|
62
|
4 |
|
if (!$this->validate()) { |
|
63
|
4 |
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
/** @var \inblank\activeuser\models\User $user */ |
|
66
|
4 |
|
$user = Yii::createObject(self::di('User')); |
|
|
|
|
|
|
67
|
4 |
|
$user->setAttributes($this->getAttributes()); |
|
68
|
4 |
|
return $user->register(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: