Commit 5d7e7f4d by Alexander Makarov

Moved creating user to static method of the model

parent b8f14b06
...@@ -27,6 +27,18 @@ class User extends ActiveRecord implements IdentityInterface ...@@ -27,6 +27,18 @@ class User extends ActiveRecord implements IdentityInterface
const ROLE_USER = 10; const ROLE_USER = 10;
public static function create($attributes)
{
/** @var User $user */
$user = new static();
$user->setAttributes($attributes);
if ($user->save()) {
return $user;
} else {
return null;
}
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
......
...@@ -41,10 +41,7 @@ class SignupForm extends Model ...@@ -41,10 +41,7 @@ class SignupForm extends Model
public function signup() public function signup()
{ {
if ($this->validate()) { if ($this->validate()) {
$user = User::create($this->attributes); return User::create($this->attributes);
if ($user->save()) {
return $user;
}
} }
return null; return null;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment