'error.newPassword_required'], ['newRePassword', 'required', 'message' => 'error.newRePassword_required'], ['newPassword', 'string', 'min' => 8, 'tooShort' => 'error.password_too_short'], ['newRePassword', 'validatePasswordAndRePasswordMatch'], ['logoutAll', 'boolean'], ]); } public function validatePasswordAndRePasswordMatch($attribute) { if (!$this->hasErrors($attribute)) { if ($this->newPassword !== $this->newRePassword) { $this->addError($attribute, 'error.newRePassword_does_not_match'); } } } /** * @return boolean if password was changed. */ public function changePassword() { if (!$this->validate()) { return false; } $account = $this->_account; $account->setPassword($this->newPassword); if ($this->logoutAll) { // TODO: реализовать процесс разлогинивания всех авторизованных устройств и дописать под это всё тесты } return $account->save(); } protected function getAccount() { return $this->_account; } /** * @param Account $account * @param array $config */ public function __construct(Account $account, array $config = []) { $this->_account = $account; parent::__construct($config); } }