Commit c2e0b5be by Alexander Makarov

Optimized forms code a bit

parent a43be083
...@@ -129,7 +129,10 @@ class User extends ActiveRecord implements IdentityInterface ...@@ -129,7 +129,10 @@ class User extends ActiveRecord implements IdentityInterface
public function rules() public function rules()
{ {
return [ return [
['status', 'default', 'value' => self::STATUS_ACTIVE],
['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]], ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
['role', 'default', 'value' => self::ROLE_USER],
['role', 'in', 'range' => [self::ROLE_USER]], ['role', 'in', 'range' => [self::ROLE_USER]],
['username', 'filter', 'filter' => 'trim'], ['username', 'filter', 'filter' => 'trim'],
......
...@@ -58,13 +58,9 @@ class ResetPasswordForm extends Model ...@@ -58,13 +58,9 @@ class ResetPasswordForm extends Model
public function resetPassword() public function resetPassword()
{ {
$user = $this->_user; $user = $this->_user;
if ($user->validate()) { $user->password = $this->password;
$user->password = $this->password; $user->removePasswordResetToken();
$user->removePasswordResetToken(); return $user->save();
return $user->save();
} else {
return false;
}
} }
} }
\ No newline at end of file
...@@ -41,13 +41,7 @@ class SignupForm extends Model ...@@ -41,13 +41,7 @@ class SignupForm extends Model
public function signup() public function signup()
{ {
if ($this->validate()) { if ($this->validate()) {
$user = new User(); $user = User::create($this->attributes);
$user->username = $this->username;
$user->email = $this->email;
$user->password = $this->password;
$user->generatePasswordResetToken();
$user->role = User::ROLE_USER;
$user->status = User::STATUS_ACTIVE;
if ($user->save()) { if ($user->save()) {
return $user; return $user;
} }
......
...@@ -986,8 +986,6 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface ...@@ -986,8 +986,6 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
/** /**
* Creates an active record object using a row of data from the database/storage. * Creates an active record object using a row of data from the database/storage.
* *
* This method is *not* meant to be used to create new records.
*
* It is an internal method meant to be called to create active record objects after * It is an internal method meant to be called to create active record objects after
* fetching data from the database. It is mainly used by [[ActiveQuery]] to populate * fetching data from the database. It is mainly used by [[ActiveQuery]] to populate
* the query results into Active Records. * the query results into Active Records.
......
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