Skip to content
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
Fix password reset saying Admin changed my password when reset from
login page

Signed-off-by: Thomas Citharel <[email protected]>
  • Loading branch information
tcitworld committed Apr 10, 2020
commit 18e8af4bb838af18eb68111c4d35dd1c68d0a963
4 changes: 4 additions & 0 deletions apps/settings/lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Provider implements IProvider {
public const PASSWORD_CHANGED_BY = 'password_changed_by';
public const PASSWORD_CHANGED_SELF = 'password_changed_self';
public const PASSWORD_RESET = 'password_changed';
public const PASSWORD_RESET_SELF = 'password_reset_self';
public const EMAIL_CHANGED_BY = 'email_changed_by';
public const EMAIL_CHANGED_SELF = 'email_changed_self';
public const EMAIL_CHANGED = 'email_changed';
Expand Down Expand Up @@ -105,6 +106,8 @@ public function parse($language, IEvent $event, IEvent $previousEvent = null): I
$subject = $this->l->t('You changed your password');
} elseif ($event->getSubject() === self::PASSWORD_RESET) {
$subject = $this->l->t('Your password was reset by an administrator');
} elseif ($event->getSubject() === self::PASSWORD_RESET_SELF) {
$subject = $this->l->t('Your password was reset');
} elseif ($event->getSubject() === self::EMAIL_CHANGED_BY) {
$subject = $this->l->t('{actor} changed your email address');
} elseif ($event->getSubject() === self::EMAIL_CHANGED_SELF) {
Expand Down Expand Up @@ -143,6 +146,7 @@ protected function getParameters(IEvent $event): array {
switch ($subject) {
case self::PASSWORD_CHANGED_SELF:
case self::PASSWORD_RESET:
case self::PASSWORD_RESET_SELF:
case self::EMAIL_CHANGED_SELF:
case self::EMAIL_CHANGED:
return [];
Expand Down
13 changes: 11 additions & 2 deletions apps/settings/lib/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function onChangePassword($uid) {
$actor = $this->userSession->getUser();
if ($actor instanceof IUser) {
if ($actor->getUID() !== $user->getUID()) {
// Admin changed the password through the user panel
$this->l = $this->languageFactory->get(
'settings',
$this->config->getUserValue(
Expand All @@ -118,13 +119,21 @@ public function onChangePassword($uid) {
$event->setAuthor($actor->getUID())
->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]);
} else {
// User changed their password themselves through settings
$text = $this->l->t('Your password on %s was changed.', [$instanceUrl]);
$event->setAuthor($actor->getUID())
->setSubject(Provider::PASSWORD_CHANGED_SELF);
}
} else {
$text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]);
$event->setSubject(Provider::PASSWORD_RESET);
if (PHP_SAPI === 'cli') {
// Admin used occ to reset the password
$text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]);
$event->setSubject(Provider::PASSWORD_RESET);
} else {
// User reset their password from Lost page
$text = $this->l->t('Your password on %s was reset.', [$instanceUrl]);
$event->setSubject(Provider::PASSWORD_RESET_SELF);
}
}

$this->activityManager->publish($event);
Expand Down