1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\basic\forms; |
4
|
|
|
|
5
|
|
|
use app\basic\models\UserModels; |
6
|
|
|
use yii\base\Application; |
7
|
|
|
use yii\base\Model; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* SignupForm is the model behind the signup form Web Application Basic. |
11
|
|
|
**/ |
12
|
|
|
class SignupForm extends Model |
13
|
|
|
{ |
14
|
|
|
public $username; |
15
|
|
|
public $email; |
16
|
|
|
public $password; |
17
|
|
|
public $verifyCode; |
18
|
|
|
|
19
|
|
|
protected $app; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* __construct |
23
|
|
|
* |
24
|
|
|
* @param Application $app |
25
|
|
|
**/ |
26
|
|
|
public function __construct(Application $app) |
27
|
|
|
{ |
28
|
|
|
$this->app = $app; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* rules |
33
|
|
|
* |
34
|
|
|
* @return array the validation rules. |
35
|
|
|
**/ |
36
|
|
|
public function rules() |
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
|
|
['username', 'trim'], |
40
|
|
|
['username', 'required'], |
41
|
|
|
['username', 'unique', 'targetClass' => 'app\basic\models\UserModels', 'message' => 'This username has already been taken.'], |
42
|
|
|
['username', 'string', 'min' => 2, 'max' => 255], |
43
|
|
|
['email', 'trim'], |
44
|
|
|
['email', 'required'], |
45
|
|
|
['email', 'email'], |
46
|
|
|
['email', 'string', 'max' => 255], |
47
|
|
|
['email', 'unique', 'targetClass' => 'app\basic\models\UserModels', 'message' => 'This email address has already been taken.'], |
48
|
|
|
['password', 'required'], |
49
|
|
|
['password', 'string', 'min' => 6], |
50
|
|
|
// verifyCode needs to be entered correctly |
51
|
|
|
//['verifyCode', \yii\captcha\CaptchaValidator::class], |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* atributeLabels |
57
|
|
|
* Translate Atribute Labels. |
58
|
|
|
* |
59
|
|
|
* @return array customized attribute labels. |
60
|
|
|
**/ |
61
|
|
|
public function attributeLabels() |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
'email' => $this->app->t('basic', 'Email'), |
65
|
|
|
'username' => $this->app->t('basic', 'Username'), |
66
|
|
|
'password' => $this->app->t('basic', 'Password'), |
67
|
|
|
'verifyCode' => $this->app->t('basic', 'VerifyCode'), |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* signup |
73
|
|
|
* Signs user up. |
74
|
|
|
* |
75
|
|
|
* @return User|null the saved model or null if saving fails. |
|
|
|
|
76
|
|
|
**/ |
77
|
|
|
public function signup() |
78
|
|
|
{ |
79
|
|
|
if (!$this->validate()) { |
80
|
|
|
return null; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$user = new UserModels(); |
84
|
|
|
|
85
|
|
|
$user->username = $this->username; |
86
|
|
|
$user->email = $this->email; |
87
|
|
|
$user->setPassword($this->password); |
88
|
|
|
$user->generateAuthKey(); |
89
|
|
|
|
90
|
|
|
return $user->save() ? $user : null; |
|
|
|
|
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths