Commit 1d23c3c6 authored by Tino Goratsch's avatar Tino Goratsch

closes #54

- Moved the password form fields from the users account profile action to the user account settings action
parent 62902eb8
......@@ -19,10 +19,6 @@ class Edit extends AbstractAction
* @var \ACP3\Core\Helpers\FormToken
*/
protected $formTokenHelper;
/**
* @var \ACP3\Core\Helpers\Secure
*/
protected $secureHelper;
/**
* @var \ACP3\Modules\ACP3\Users\Helpers\Forms
*/
......@@ -31,10 +27,6 @@ class Edit extends AbstractAction
* @var \ACP3\Modules\ACP3\Users\Validation\AccountFormValidation
*/
protected $accountFormValidation;
/**
* @var \ACP3\Modules\ACP3\Users\Model\AuthenticationModel
*/
protected $authenticationModel;
/**
* @var Users\Model\UsersModel
*/
......@@ -45,27 +37,21 @@ class Edit extends AbstractAction
*
* @param \ACP3\Core\Controller\Context\FrontendContext $context
* @param \ACP3\Core\Helpers\FormToken $formTokenHelper
* @param \ACP3\Core\Helpers\Secure $secureHelper
* @param \ACP3\Modules\ACP3\Users\Helpers\Forms $userFormsHelper
* @param \ACP3\Modules\ACP3\Users\Model\AuthenticationModel $authenticationModel
* @param Users\Model\UsersModel $usersModel
* @param \ACP3\Modules\ACP3\Users\Validation\AccountFormValidation $accountFormValidation
*/
public function __construct(
Core\Controller\Context\FrontendContext $context,
Core\Helpers\FormToken $formTokenHelper,
Core\Helpers\Secure $secureHelper,
Users\Helpers\Forms $userFormsHelper,
Users\Model\AuthenticationModel $authenticationModel,
Users\Model\UsersModel $usersModel,
Users\Validation\AccountFormValidation $accountFormValidation
) {
parent::__construct($context);
$this->formTokenHelper = $formTokenHelper;
$this->secureHelper = $secureHelper;
$this->userFormsHelper = $userFormsHelper;
$this->authenticationModel = $authenticationModel;
$this->accountFormValidation = $accountFormValidation;
$this->usersModel = $usersModel;
}
......@@ -114,22 +100,8 @@ class Edit extends AbstractAction
->setUserId($this->user->getUserId())
->validate($formData);
if (!empty($formData['new_pwd']) && !empty($formData['new_pwd_repeat'])) {
$salt = $this->secureHelper->salt(Users\Model\UserModel::SALT_LENGTH);
$newPassword = $this->secureHelper->generateSaltedPassword($salt, $formData['new_pwd'], 'sha512');
$formData['pwd'] = $newPassword;
$formData['pwd_salt'] = $salt;
}
$bool = $this->usersModel->save($formData, $this->user->getUserId());
$user = $this->usersModel->getOneById($this->user->getUserId());
$cookie = $this->authenticationModel->setRememberMeCookie(
$this->user->getUserId(),
$user['remember_me_token']
);
$this->response->headers->setCookie($cookie);
return $this->redirectMessages()->setMessage(
$bool,
$this->translator->t('system', $bool !== false ? 'edit_success' : 'edit_error')
......
......@@ -30,20 +30,32 @@ class Settings extends AbstractAction
* @var Users\Model\UsersModel
*/
protected $usersModel;
/**
* @var Core\Helpers\Secure
*/
protected $secureHelper;
/**
* @var Users\Model\AuthenticationModel
*/
protected $authenticationModel;
/**
* Settings constructor.
*
* @param \ACP3\Core\Controller\Context\FrontendContext $context
* @param \ACP3\Core\Helpers\FormToken $formTokenHelper
* @param Core\Helpers\Secure $secureHelper
* @param \ACP3\Modules\ACP3\Users\Helpers\Forms $userFormsHelper
* @param Users\Model\AuthenticationModel $authenticationModel
* @param Users\Model\UsersModel $usersModel
* @param \ACP3\Modules\ACP3\Users\Validation\AccountSettingsFormValidation $accountSettingsFormValidation
*/
public function __construct(
Core\Controller\Context\FrontendContext $context,
Core\Helpers\FormToken $formTokenHelper,
Core\Helpers\Secure $secureHelper,
Users\Helpers\Forms $userFormsHelper,
Users\Model\AuthenticationModel $authenticationModel,
Users\Model\UsersModel $usersModel,
Users\Validation\AccountSettingsFormValidation $accountSettingsFormValidation
) {
......@@ -53,6 +65,8 @@ class Settings extends AbstractAction
$this->userFormsHelper = $userFormsHelper;
$this->accountSettingsFormValidation = $accountSettingsFormValidation;
$this->usersModel = $usersModel;
$this->secureHelper = $secureHelper;
$this->authenticationModel = $authenticationModel;
}
/**
......@@ -106,8 +120,22 @@ class Settings extends AbstractAction
unset($formData['language']);
}
if (!empty($formData['new_pwd']) && !empty($formData['new_pwd_repeat'])) {
$salt = $this->secureHelper->salt(Users\Model\UserModel::SALT_LENGTH);
$newPassword = $this->secureHelper->generateSaltedPassword($salt, $formData['new_pwd'], 'sha512');
$formData['pwd'] = $newPassword;
$formData['pwd_salt'] = $salt;
}
$bool = $this->usersModel->save($formData, $this->user->getUserId());
$user = $this->usersModel->getOneById($this->user->getUserId());
$cookie = $this->authenticationModel->setRememberMeCookie(
$this->user->getUserId(),
$user['remember_me_token']
);
$this->response->headers->setCookie($cookie);
return $this->redirectMessages()->setMessage(
$bool,
$this->translator->t('system', $bool !== false ? 'settings_success' : 'settings_error')
......
......@@ -6,7 +6,6 @@
<li class="active"><a href="#tab-1" data-toggle="tab">{lang t="system|general"}</a></li>
<li><a href="#tab-2" data-toggle="tab">{lang t="users|contact"}</a></li>
<li><a href="#tab-3" data-toggle="tab">{lang t="users|address"}</a></li>
<li><a href="#tab-4" data-toggle="tab">{lang t="users|pwd"}</a></li>
</ul>
<div class="tab-content">
<div id="tab-1" class="tab-pane fade in active">
......@@ -27,9 +26,6 @@
{include file="asset:System/Partials/form_group.input_text.tpl" name="city" value=$form.city maxlength=80 label={lang t="users|address_city"}}
{include file="asset:System/Partials/form_group.select.tpl" options=$countries label={lang t="users|country"}}
</div>
<div id="tab-4" class="tab-pane fade">
{include file="asset:Users/Partials/password_fields.tpl" field_name='new_pwd' translator_phrase="new_pwd"}
</div>
</div>
</div>
{include file="asset:System/Partials/form_group.submit.tpl" form_token=$form_token back_url={uri args="acp/users/account"}}
......
......@@ -5,6 +5,7 @@
<ul class="nav nav-tabs">
<li class="active"><a href="#tab-localization" data-toggle="tab">{lang t="users|localization"}</a></li>
<li><a href="#tab-privacy" data-toggle="tab">{lang t="users|privacy"}</a></li>
<li><a href="#tab-password" data-toggle="tab">{lang t="users|pwd"}</a></li>
</ul>
<div class="tab-content">
<div id="tab-localization" class="tab-pane fade in active">
......@@ -43,6 +44,9 @@
{include file="asset:System/Partials/form_group.button_group.tpl" options=$country_display required=true label={lang t="users|display_country"}}
{include file="asset:System/Partials/form_group.radio.tpl" options=$birthday_display required=true label={lang t="users|birthday"}}
</div>
<div id="tab-password" class="tab-pane fade">
{include file="asset:Users/Partials/password_fields.tpl" field_name='new_pwd' translator_phrase="new_pwd"}
</div>
</div>
</div>
{include file="asset:System/Partials/form_group.submit.tpl" form_token=$form_token back_url={uri args="acp/users/account"}}
......
......@@ -47,9 +47,7 @@ services:
arguments:
- '@core.context.frontend'
- '@core.helpers.formToken'
- '@core.helpers.secure'
- '@users.helpers.forms'
- '@users.model.authentication_model'
- '@users.model.users_model'
- '@users.validator.account'
......@@ -62,7 +60,9 @@ services:
arguments:
- '@core.context.frontend'
- '@core.helpers.formToken'
- '@core.helpers.secure'
- '@users.helpers.forms'
- '@users.model.authentication_model'
- '@users.model.users_model'
- '@users.validation.account_settings_form_validation'
......
......@@ -30,10 +30,8 @@ class AccountFormValidation extends AbstractUserFormValidation
public function validate(array $formData)
{
$this->validator->addConstraint(Core\Validation\ValidationRules\FormTokenValidationRule::class);
;
$this->validateAccountCoreData($formData, $this->userId);
$this->validateNewPassword($formData, 'new_pwd', 'new_pwd_repeat');
$this->validator->validate();
}
......
......@@ -34,6 +34,7 @@ class AccountSettingsFormValidation extends AbstractUserFormValidation
$this->validator->addConstraint(Core\Validation\ValidationRules\FormTokenValidationRule::class);
$this->validateUserSettings($formData, $this->settings['language_override']);
$this->validateNewPassword($formData, 'new_pwd', 'new_pwd_repeat');
$this->validator->validate();
}
......
......@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Extracted the adding of the data grid columns into separate methods
- Updated the [mibe/feedwriter](https://github.com/mibe/FeedWriter) library to version v1.1.0
- [#55](https://github.com/ACP3/cms/pull/55) Changed the argument order of the \FeedWriter\Feed::setImage() method (thanks @mibe)
- [#54](https://github.com/ACP3/cms/issues/54) Moved the password form fields from the users account profile action to the user account settings action
### Fixed
- Fixed the pictures count of the gallery data grid
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment