_addMessageTemplate(static::MSG_PASSWORD_CHANGED, 'Your password has been changed'); $this->_setMessage('Your profile has been updated', static::MSG_UPDATED); $lockMessage = 'Your profile is currently being edited by "%firstName% %lastName%" %userRoleTitle%. ' . 'Please try again later.'; $this->_setMessage($lockMessage, static::MSG_LOCKED); $this->_setBackUrl($this->_getRedirectUrl()); return $this; } protected function _initAction() { $defaultAction = $this->getConfig('defaultAction'); if (!in_array($defaultAction, $this->_actions)) { throw new Qs_Exception('Default action is not set properly'); } $this->_defaultAction = $defaultAction; return parent::_initAction(); } protected function _callAction() { $this->_getDataObj()->setPrimarykey($this->_doc->getAuthData('id')); parent::_callAction(); } protected function _initFromForm(\Qs_Form $form) { if (($password = $form->getElement('password'))) { $this->_newPassword = $password->getValue(); } return parent::_initFromForm($form); } protected function _postUpdate() { $this->_updateCredential(); return parent::_postUpdate(); } protected function _updateCredential() { if (!empty($this->_newPassword)) { $data = $this->_doc->getAuth()->getStorage()->read(); $data['credential'] = $this->_newPassword; $this->_doc->getAuth()->getStorage()->write($data); } return $this; } protected function _getRedirectUrl() { $redirectUrl = Qs_SiteMap::findFirst(null, ['type' => 'User\\'], ['defaultAction' => 'view'], 'url'); if (!$redirectUrl) { /** * якщо немає сторінки з блоком інформації про юзера, то робимо перехід на першу сторінку в юзерського меню */ $redirectUrl = Qs_SiteMap::findFirst(['isAccountNavigation' => 'y'], null, null, 'url'); } if (!$redirectUrl) { $redirectUrl = BASE_URL_LANGUAGE . '/' . PARENT_PAGE; } return $redirectUrl; } protected function _doEditPassword() { if (null === $this->_getDataObj()->getData()) { $this->_setBackError(static::MSG_DATA_UNAVAILABLE); $this->_doBack(); } if (!$this->_lock()) { $this->_setBackAttention($this->_createMessage(static::MSG_LOCKED, $this->_getLocker())); $this->_doBack(); } $form = $this->_getEditPasswordForm(); $this->_addFormItem($form); $this->_postEditPassword(); return $this; } protected function _getEditPasswordForm(array $options = []) { return $this->_getFormInstance('editPassword', $options); } protected function _postEditPassword() { $this->_log(); return $this; } protected function _doUpdatePasswordAjax() { if ($this->_isLocked()) { $data = ['isLocked' => true, 'error' => $this->_createMessage(static::MSG_LOCKED, $this->_getLocker())]; } else { $form = $this->_getEditPasswordForm(); $data = $form->validateAjax(); } $this->_displayJson($data); } protected function _doUpdatePassword() { if (null === $this->_getDataObj()->getData()) { $this->_setBackError(static::MSG_DATA_UNAVAILABLE); $this->_doBack(); } if ($this->_isLocked()) { $this->_setBackAttention($this->_createMessage(static::MSG_LOCKED, $this->_getLocker())); $this->_doBack(); } $form = $this->_getEditPasswordForm(); if ($form->validate()) { $this->_initFromForm($form); if (false === $this->_getDataObj()->updatePassword()) { $this->_setBackErrors($this->_getDataObj()->getErrors()); } else { $this->_postPasswordUpdate(); $this->_unlock(); $this->_setBackMessage(static::MSG_PASSWORD_CHANGED); } $this->_doBack(); } else { $this->_addFormItem($form); } return $this; } protected function _postPasswordUpdate() { $this->_updateCredential(); $this->_log(); return $this; } }