1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace frontend\models;
- use yii\base\Model;
- use common\models\User;
- /**
- * Signup form
- */
- class SignupForm extends Model
- {
- public $username;
- public $email;
- public $password;
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%user}}';
- }
- public function rules()
- {
- return [
- [['username', 'auth_key', 'password_hash', 'status', 'created_at', 'updated_at'], 'required'],
- [['role'], 'string'],
- [[ 'status', 'created_at', 'updated_at','state'], 'integer'],
- [['username', 'auth_key', 'email'], 'string', 'max' => 32],
- [['password_hash', 'password_reset_token', 'access_token'], 'string', 'max' => 255],
- [['username'], 'unique'],
- // [['email'], 'unique'],
- [['password_reset_token'], 'unique'],
- ];
- }
- /**
- * Signs user up.
- *
- * @return User|null the saved model or null if saving fails
- */
- public function signup()
- {
- if (!$this->validate()) {
- return null;
- }
-
- $user = new User();
- $user->username = $this->username;
- $user->email = $this->email;
- $user->setPassword($this->password);
- $user->generateAuthKey();
-
- return $user->save() ? $user : null;
- }
- }
|