Merge pull request #20427 from nextcloud/bug/noid/fix-password-reset-activity
Fix password reset saying Admin changed my password when reset from login page
This commit is contained in:
commit
a307d82e1d
|
@ -41,6 +41,7 @@ class Provider implements IProvider {
|
||||||
public const PASSWORD_CHANGED_BY = 'password_changed_by';
|
public const PASSWORD_CHANGED_BY = 'password_changed_by';
|
||||||
public const PASSWORD_CHANGED_SELF = 'password_changed_self';
|
public const PASSWORD_CHANGED_SELF = 'password_changed_self';
|
||||||
public const PASSWORD_RESET = 'password_changed';
|
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_BY = 'email_changed_by';
|
||||||
public const EMAIL_CHANGED_SELF = 'email_changed_self';
|
public const EMAIL_CHANGED_SELF = 'email_changed_self';
|
||||||
public const EMAIL_CHANGED = 'email_changed';
|
public const EMAIL_CHANGED = 'email_changed';
|
||||||
|
@ -105,6 +106,8 @@ class Provider implements IProvider {
|
||||||
$subject = $this->l->t('You changed your password');
|
$subject = $this->l->t('You changed your password');
|
||||||
} elseif ($event->getSubject() === self::PASSWORD_RESET) {
|
} elseif ($event->getSubject() === self::PASSWORD_RESET) {
|
||||||
$subject = $this->l->t('Your password was reset by an administrator');
|
$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) {
|
} elseif ($event->getSubject() === self::EMAIL_CHANGED_BY) {
|
||||||
$subject = $this->l->t('{actor} changed your email address');
|
$subject = $this->l->t('{actor} changed your email address');
|
||||||
} elseif ($event->getSubject() === self::EMAIL_CHANGED_SELF) {
|
} elseif ($event->getSubject() === self::EMAIL_CHANGED_SELF) {
|
||||||
|
@ -143,6 +146,7 @@ class Provider implements IProvider {
|
||||||
switch ($subject) {
|
switch ($subject) {
|
||||||
case self::PASSWORD_CHANGED_SELF:
|
case self::PASSWORD_CHANGED_SELF:
|
||||||
case self::PASSWORD_RESET:
|
case self::PASSWORD_RESET:
|
||||||
|
case self::PASSWORD_RESET_SELF:
|
||||||
case self::EMAIL_CHANGED_SELF:
|
case self::EMAIL_CHANGED_SELF:
|
||||||
case self::EMAIL_CHANGED:
|
case self::EMAIL_CHANGED:
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -106,6 +106,7 @@ class Hooks {
|
||||||
$actor = $this->userSession->getUser();
|
$actor = $this->userSession->getUser();
|
||||||
if ($actor instanceof IUser) {
|
if ($actor instanceof IUser) {
|
||||||
if ($actor->getUID() !== $user->getUID()) {
|
if ($actor->getUID() !== $user->getUID()) {
|
||||||
|
// Admin changed the password through the user panel
|
||||||
$this->l = $this->languageFactory->get(
|
$this->l = $this->languageFactory->get(
|
||||||
'settings',
|
'settings',
|
||||||
$this->config->getUserValue(
|
$this->config->getUserValue(
|
||||||
|
@ -118,13 +119,21 @@ class Hooks {
|
||||||
$event->setAuthor($actor->getUID())
|
$event->setAuthor($actor->getUID())
|
||||||
->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]);
|
->setSubject(Provider::PASSWORD_CHANGED_BY, [$actor->getUID()]);
|
||||||
} else {
|
} else {
|
||||||
|
// User changed their password themselves through settings
|
||||||
$text = $this->l->t('Your password on %s was changed.', [$instanceUrl]);
|
$text = $this->l->t('Your password on %s was changed.', [$instanceUrl]);
|
||||||
$event->setAuthor($actor->getUID())
|
$event->setAuthor($actor->getUID())
|
||||||
->setSubject(Provider::PASSWORD_CHANGED_SELF);
|
->setSubject(Provider::PASSWORD_CHANGED_SELF);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
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]);
|
$text = $this->l->t('Your password on %s was reset by an administrator.', [$instanceUrl]);
|
||||||
$event->setSubject(Provider::PASSWORD_RESET);
|
$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);
|
$this->activityManager->publish($event);
|
||||||
|
|
Loading…
Reference in New Issue