Skip to content

Commit ec2ff01

Browse files
author
Igor Chepurnoy
committed
added getUser method to SignupForm
1 parent c93b1ba commit ec2ff01

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

models/SignupForm.php

+19-7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class SignupForm extends Model
2727
*/
2828
public $password;
2929

30+
/**
31+
* @var UserModel
32+
*/
33+
protected $user;
34+
3035
/**
3136
* @inheritdoc
3237
*/
@@ -72,13 +77,20 @@ public function signup()
7277
return null;
7378
}
7479

75-
$user = new UserModel();
76-
$user->username = $this->username;
77-
$user->email = $this->email;
78-
$user->setPassword($this->password);
79-
$user->generateAuthKey();
80-
$user->lastLogin = time();
80+
$this->user = new UserModel();
81+
$this->user->setAttributes($this->attributes);
82+
$this->user->setPassword($this->password);
83+
$this->user->generateAuthKey();
84+
$this->user->lastLogin = time();
85+
86+
return $this->user->save() ? $this->user : null;
87+
}
8188

82-
return $user->save() ? $user : null;
89+
/**
90+
* @return UserModel|null
91+
*/
92+
public function getUser()
93+
{
94+
return $this->user;
8395
}
8496
}

tests/forms/SignupFormTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function testSignupWithAlreadyExistEmail()
3939
$model->username = 'demo';
4040

4141
$this->assertNull($model->signup());
42+
$this->assertNull($model->getUser());
4243
$this->assertArrayHasKey('email', $model->errors);
4344
}
4445

@@ -50,5 +51,6 @@ public function testSignupCorrect()
5051
$model->username = 'demo2';
5152

5253
$this->assertInstanceOf(UserModel::class, $model->signup());
54+
$this->assertInstanceOf(UserModel::class, $model->getUser());
5355
}
5456
}

0 commit comments

Comments
 (0)