app/models/Data/User.php: implement beforeSave() and trigger "user:onPasswordCreated" and "user:onPasswordChanged"
This commit is contained in:
parent
8061c674f4
commit
bebb0ba5f9
1 changed files with 18 additions and 0 deletions
|
|
@ -206,4 +206,22 @@ class User extends Model
|
|||
"bind" => [ 'v' => $value ]
|
||||
]);
|
||||
}
|
||||
|
||||
public function beforeSave()
|
||||
{
|
||||
$manager = $this->getEventsManager();
|
||||
|
||||
// EventManager exist and password field has changed.
|
||||
if ($manager && $this->hasChanged('password')) {
|
||||
|
||||
$old_value = $this->getOldSnapshotData()['password'];
|
||||
|
||||
// Empty password before
|
||||
if (strlen($old_value) < 1) {
|
||||
$manager->fire('user:onPasswordCreated', $this);
|
||||
} else {
|
||||
$manager->fire('user:onPasswordChanged', $this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue