Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug][Pimcore 11] User cannot update own password #76

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 57 additions & 37 deletions public/js/pimcore/settings/profile/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ pimcore.settings.profile.panel = Class.create({
this.currentUser = pimcore.currentuser;

var passwordCheck = function (el) {
if (/^(?=.*\d)(?=.*[a-zA-Z]).{6,100}$/.test(el.getValue())) {
if (pimcore.helpers.isValidPassword(el.getValue())) {
el.getEl().addCls("password_valid");
el.getEl().removeCls("password_invalid");
passwordHint.hide();
} else {
el.getEl().addCls("password_invalid");
el.getEl().removeCls("password_valid");
passwordHint.show();
}
};

Expand Down Expand Up @@ -171,6 +173,14 @@ pimcore.settings.profile.panel = Class.create({
}
});

var passwordHint = new Ext.Container({
xtype: "container",
itemId: "password_hint",
html: t("password_hint"),
style: "color: red;",
hidden: true
});

generalItems.push({
xtype: "fieldset",
title: t("change_password"),
Expand Down Expand Up @@ -220,7 +230,7 @@ pimcore.settings.profile.panel = Class.create({
}.bind(this)
}
]
}, retypePasswordField]
}, retypePasswordField, passwordHint]
});

var twoFactorSettings = new pimcore.settings.profile.twoFactorSettings(this.currentUser.twoFactorAuthentication);
Expand Down Expand Up @@ -317,12 +327,21 @@ pimcore.settings.profile.panel = Class.create({
var values = this.basicPanel.getForm().getFieldValues();
var contentLanguages = this.editorSettings.getContentLanguages();
values.contentLanguages = contentLanguages;
let canBeSaved = true;

if (values["new_password"]) {
if (!pimcore.helpers.isValidPassword(values["new_password"]) || values["new_password"] != values["retype_password"]) {
if (!pimcore.helpers.isValidPassword(values["new_password"])) {
delete values["new_password"];
delete values["retype_password"];
Ext.MessageBox.alert(t('error'), t("password_was_not_changed"));
canBeSaved = false;
}

if(canBeSaved && values["new_password"] !== values["retype_password"]) {
delete values["new_password"];
delete values["retype_password"];
Ext.MessageBox.alert(t('error'), t("password_does_not_match"));
canBeSaved = false;
}
}

Expand All @@ -333,43 +352,44 @@ pimcore.settings.profile.panel = Class.create({
}


if (canBeSaved) {
Ext.Ajax.request({
url: Routing.generate('pimcore_admin_user_updatecurrentuser'),
method: "PUT",
params: {
id: this.currentUser.id,
data: Ext.encode(values),
keyBindings: keyBindings
},
success: function (response) {
try {
var res = Ext.decode(response.responseText);
if (res.success) {

if (this.forceReloadOnSave) {
this.forceReloadOnSave = false;

Ext.MessageBox.confirm(t("info"), t("reload_pimcore_changes"), function (buttonValue) {
if (buttonValue == "yes") {
window.location.reload();
}
}.bind(this));
}

Ext.Ajax.request({
url: Routing.generate('pimcore_admin_user_updatecurrentuser'),
method: "PUT",
params: {
id: this.currentUser.id,
data: Ext.encode(values),
keyBindings: keyBindings
},
success: function (response) {
try {
var res = Ext.decode(response.responseText);
if (res.success) {

if (this.forceReloadOnSave) {
this.forceReloadOnSave = false;

Ext.MessageBox.confirm(t("info"), t("reload_pimcore_changes"), function (buttonValue) {
if (buttonValue == "yes") {
window.location.reload();
}
}.bind(this));
}

pimcore.helpers.showNotification(t("success"), t("saved_successfully"), "success");
if (contentLanguages) {
pimcore.settings.websiteLanguages = contentLanguages;
pimcore.currentuser.contentLanguages = contentLanguages.join(',');
pimcore.helpers.showNotification(t("success"), t("saved_successfully"), "success");
if (contentLanguages) {
pimcore.settings.websiteLanguages = contentLanguages;
pimcore.currentuser.contentLanguages = contentLanguages.join(',');
}
} else {
pimcore.helpers.showNotification(t("error"), t("saving_failed"), "error", t(res.message));
}
} else {
pimcore.helpers.showNotification(t("error"), t("saving_failed"), "error", t(res.message));
} catch (e) {
pimcore.helpers.showNotification(t("error"), t("saving_failed"), "error");
}
} catch (e) {
pimcore.helpers.showNotification(t("error"), t("saving_failed"), "error");
}
}.bind(this)
});
}.bind(this)
});
}
},

activate: function () {
Expand Down
3 changes: 3 additions & 0 deletions src/Controller/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ public function updateCurrentUserAction(Request $request, ValidatorInterface $va
if ($oldPasswordCheck && $values['new_password'] == $values['retype_password']) {
$values['password'] = Tool\Authentication::getPasswordHash($user->getName(), $values['new_password']);
} else {
if (!$oldPasswordCheck) {
return $this->adminJson(['success' => false, 'message' => 'incorrect_password']);
}
return $this->adminJson(['success' => false, 'message' => 'password_cannot_be_changed']);
}
}
Expand Down
2 changes: 2 additions & 0 deletions translations/admin.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ usermodification: 'User Modification'
userowner: Owner
languages: Languages
password_was_not_changed: "Password wasn't changed because it isn't secure enough"
password_does_not_match: "New password and confirm password doesn't match"
incorrect_password: "Given password is incorrect"
marketing: Marketing
clear_content_of_current_view: 'Clear content of current view'
highlight_editable_elements: 'Highlight editable elements'
Expand Down