Skip to content

Commit

Permalink
switch to use getter & setter.
Browse files Browse the repository at this point in the history
  • Loading branch information
vistart committed Mar 27, 2017
1 parent 921800f commit bd06cb7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
14 changes: 7 additions & 7 deletions traits/IdentityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public function setAuthKeyRules($rules)
public function onInitAuthKey($event)
{
$sender = $event->sender;
$authKeyAttribute = $sender->authKeyAttribute;
$sender->$authKeyAttribute = sha1(Yii::$app->security->generateRandomString());
/* @var $sender static */
$sender->setAuthKey(sha1(Yii::$app->security->generateRandomString()));
}

/**
Expand Down Expand Up @@ -204,8 +204,8 @@ public function setAccessTokenRules($rules)
public function onInitAccessToken($event)
{
$sender = $event->sender;
$accessTokenAttribute = $sender->accessTokenAttribute;
$sender->$accessTokenAttribute = sha1(Yii::$app->security->generateRandomString());
/* @var $sender static */
$sender->setAccessToken(sha1(Yii::$app->security->generateRandomString()));
}

/**
Expand Down Expand Up @@ -267,9 +267,9 @@ public function setStatusRules($rules)
public function onInitStatusAttribute($event)
{
$sender = $event->sender;
$statusAttribute = $sender->statusAttribute;
if (empty($sender->$statusAttribute)) {
$sender->$statusAttribute = self::$statusActive;
/* @var $sender static */
if (empty($sender->getStatus())) {
$sender->setStatus(self::$statusActive);
}
}
}
24 changes: 14 additions & 10 deletions traits/PasswordTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ public function setPassword($password = null)
$password = $this->getEmptyPasswordSpecialty();
}
$phAttribute = $this->passwordHashAttribute;
if (empty($phAttribute) || !is_string($phAttribute)) {
return;
}
$this->$phAttribute = $this->generatePasswordHash($password);
$this->_password = $password;
$this->trigger(static::$eventAfterSetPassword);
Expand Down Expand Up @@ -247,8 +250,7 @@ public function applyForNewPassword()
$this->trigger(static::$eventNewPasswordAppliedFor);
return true;
}
$prtAttribute = $this->passwordResetTokenAttribute;
$this->$prtAttribute = static::generatePasswordResetToken();
$this->setPasswordResetToken(static::generatePasswordResetToken());
if (!$this->save()) {
$this->trigger(static::$eventResetPasswordFailed);
return false;
Expand All @@ -272,9 +274,7 @@ public function resetPassword($password, $token)
}
$this->trigger(static::$eventBeforeResetPassword);
$this->password = $password;
if (is_string($this->passwordResetTokenAttribute)) {
$this->setPasswordResetToken();
}
$this->setPasswordResetToken();
if (!$this->save()) {
$this->trigger(static::$eventResetPasswordFailed);
return false;
Expand Down Expand Up @@ -311,7 +311,7 @@ public function onAfterSetNewPassword($event)
*/
protected function validatePasswordResetToken($token)
{
if (!is_string($this->passwordResetTokenAttribute)) {
if (!is_string($this->passwordResetTokenAttribute) || empty($this->passwordResetTokenAttribute)) {
return true;
}
return $this->getPasswordResetToken() === $token;
Expand All @@ -324,10 +324,8 @@ protected function validatePasswordResetToken($token)
public function onInitPasswordResetToken($event)
{
$sender = $event->sender;
if (!is_string($sender->passwordResetTokenAttribute)) {
return;
}
$this->setPasswordResetToken();
/* @var $sender static */
return $sender->setPasswordResetToken();
}

/**
Expand All @@ -337,6 +335,9 @@ public function onInitPasswordResetToken($event)
*/
public function setPasswordResetToken($token = '')
{
if (empty($this->passwordResetTokenAttribute) || !is_string($this->passwordResetTokenAttribute)) {
return null;
}
return $this->{$this->passwordResetTokenAttribute} = $token;
}

Expand All @@ -346,6 +347,9 @@ public function setPasswordResetToken($token = '')
*/
public function getPasswordResetToken()
{
if (empty($this->passwordResetTokenAttribute) || !is_string($this->passwordResetTokenAttribute)) {
return null;
}
return $this->{$this->passwordResetTokenAttribute};
}
}
6 changes: 3 additions & 3 deletions traits/RegistrationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function getSource()
public function setSource($source)
{
$sourceAttribute = $this->sourceAttribute;
return is_string($sourceAttribute) ? $this->$sourceAttribute = $source : null;
return (is_string($sourceAttribute) && !empty($sourceAttribute)) ? $this->$sourceAttribute = $source : null;
}

/**
Expand Down Expand Up @@ -250,7 +250,7 @@ public function setSourceRules($rules)
public function onInitSourceAttribute($event)
{
$sender = $event->sender;
$sourceAttribute = $sender->sourceAttribute;
$sender->$sourceAttribute = static::$sourceSelf;
/* @var $sender static */
return $sender->setSource(static::$sourceSelf);
}
}

0 comments on commit bd06cb7

Please sign in to comment.