Blame view

frontend/models/SignupForm.php 2.35 KB
b0f143c3   Yarik   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  <?php
  namespace frontend\models;
  
  use common\models\User;
  use yii\base\Model;
  use Yii;
  
  /**
   * Signup form
   */
  class SignupForm extends Model
  {
      public $username;
      public $email;
      public $password;
f0f915df   Administrator   add Vitaliy's wid...
16
17
18
19
      public $firstname;
      public $lastname;
      public $verifyCode;
      public $location;
998611ce   Administrator   add Vitaliy's wid...
20
      public $type;
30fbd0bc   Administrator   09.02.16
21
22
23
      public $is_customer;
      public $is_freelancer;
      public $city;
b0f143c3   Yarik   first commit
24
25
26
27
28
29
30
31
32
33
34
35
  
      /**
       * @inheritdoc
       */
      public function rules()
      {
          return [
              ['username', 'filter', 'filter' => 'trim'],
              ['username', 'required'],
              ['username', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This username has already been taken.'],
              ['username', 'string', 'min' => 2, 'max' => 255],
  
30fbd0bc   Administrator   09.02.16
36
              ['city', 'string', 'min' => 2, 'max' => 255],
f0f915df   Administrator   add Vitaliy's wid...
37
  
b0f143c3   Yarik   first commit
38
39
40
41
42
43
              ['email', 'filter', 'filter' => 'trim'],
              ['email', 'required'],
              ['email', 'email'],
              ['email', 'string', 'max' => 255],
              ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'],
  
f0f915df   Administrator   add Vitaliy's wid...
44
45
              ['verifyCode', 'captcha'],
  
998611ce   Administrator   add Vitaliy's wid...
46
              ['type', 'integer'],
30fbd0bc   Administrator   09.02.16
47
48
              ['is_customer', 'integer'],
              ['is_freelancer', 'integer'],
998611ce   Administrator   add Vitaliy's wid...
49
  
b0f143c3   Yarik   first commit
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
              ['password', 'required'],
              ['password', 'string', 'min' => 6],
          ];
      }
  
      /**
       * Signs user up.
       *
       * @return User|null the saved model or null if saving fails
       */
      public function signup()
      {
          if ($this->validate()) {
              $user = new User();
              $user->username = $this->username;
              $user->email = $this->email;
              $user->setPassword($this->password);
              $user->generateAuthKey();
              if ($user->save()) {
                  return $user;
              }
          }
  
          return null;
      }
30fbd0bc   Administrator   09.02.16
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
      /**
       * @inheritdoc
       */
      public function attributeLabels()
      {
          return [
              'username' => 'Логин',
              'password' => 'Пароль',
              'email' => 'E-mail',
              'type' => Yii::t('app', 'Is Default'),
              'firstname' => 'Имя',
              'lastname' => 'Фамилия',
              'city' => 'Город',
              'alt_location' => 'Город не в списке',
              'is_customer' => '',
              'is_freelancer' => '',
          ];
      }
b0f143c3   Yarik   first commit
93
94
  
  }