Browse Source

Optimized forms code a bit

tags/2.0.0-beta
Alexander Makarov 11 years ago
parent
commit
c2e0b5beb5
  1. 3
      apps/advanced/common/models/User.php
  2. 10
      apps/advanced/frontend/models/forms/ResetPasswordForm.php
  3. 8
      apps/advanced/frontend/models/forms/SignupForm.php
  4. 2
      framework/db/BaseActiveRecord.php

3
apps/advanced/common/models/User.php

@ -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'],

10
apps/advanced/frontend/models/forms/ResetPasswordForm.php

@ -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;
}
} }
} }

8
apps/advanced/frontend/models/forms/SignupForm.php

@ -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;
} }

2
framework/db/BaseActiveRecord.php

@ -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.

Loading…
Cancel
Save