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

Trigger password reset email from user management #14411

Open
MorrisJobke opened this issue Feb 27, 2019 · 4 comments
Open

Trigger password reset email from user management #14411

MorrisJobke opened this issue Feb 27, 2019 · 4 comments
Labels
1. to develop Accepted and waiting to be taken care of enhancement feature: authentication feature: users and groups good first issue Small tasks with clear documentation about how and in which place you need to fix things in. security

Comments

@MorrisJobke
Copy link
Member

As of now the password reset email can only be triggered via the lost password page. In some cases this is disabled. It would be useful to trigger the email nevertheless as an admin from the user management.

Use case: having LDAP and DB users - LDAP users are not allowed to change the password but the reset should still be triggered by an admin for the DB users.

The email is sent here:

protected function sendEmail($input) {
$user = $this->findUserByIdOrMail($input);
$email = $user->getEMailAddress();
if (empty($email)) {
throw new \Exception(
$this->l10n->t('Could not send reset email because there is no email address for this username. Please contact your administrator.')
);
}
// Generate the token. It is stored encrypted in the database with the
// secret being the users' email address appended with the system secret.
// This makes the token automatically invalidate once the user changes
// their email address.
$token = $this->secureRandom->generate(
21,
ISecureRandom::CHAR_DIGITS.
ISecureRandom::CHAR_LOWER.
ISecureRandom::CHAR_UPPER
);
$tokenValue = $this->timeFactory->getTime() .':'. $token;
$encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret'));
$this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue);
$link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', array('userId' => $user->getUID(), 'token' => $token));
$emailTemplate = $this->mailer->createEMailTemplate('core.ResetPassword', [
'link' => $link,
]);
$emailTemplate->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()]));
$emailTemplate->addHeader();
$emailTemplate->addHeading($this->l10n->t('Password reset'));
$emailTemplate->addBodyText(
htmlspecialchars($this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.')),
$this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.')
);
$emailTemplate->addBodyButton(
htmlspecialchars($this->l10n->t('Reset your password')),
$link,
false
);
$emailTemplate->addFooter();
try {
$message = $this->mailer->createMessage();
$message->setTo([$email => $user->getUID()]);
$message->setFrom([$this->from => $this->defaults->getName()]);
$message->useTemplate($emailTemplate);
$this->mailer->send($message);
} catch (\Exception $e) {
throw new \Exception($this->l10n->t(
'Couldn\'t send reset email. Please contact your administrator.'
));
}

@MorrisJobke MorrisJobke added enhancement good first issue Small tasks with clear documentation about how and in which place you need to fix things in. 1. to develop Accepted and waiting to be taken care of security feature: users and groups labels Feb 27, 2019
@MorrisJobke
Copy link
Member Author

cc @juliushaertl @skjnldsv @kesselb @newhinton @weeman1337 Maybe one of you wants to look into this

@skjnldsv
Copy link
Member

Basically it would require:

  1. have the option in the ocs api
  2. add the action in the vue user management

@compagnon
Copy link
Contributor

Is a new action in the admin gui override the canResetPassword==false ?
#16245 description of the feature implemented in a PR
a url like https://example.com/newpassword/user@email.com could trigger an email to user for resetting his password

@skjnldsv skjnldsv added this to the Nextcloud 18 milestone Aug 23, 2019
@rullzer rullzer removed this from the Nextcloud 18 milestone Dec 9, 2019
@florian-prd
Copy link

Hello,
is there any plan to add this useful feature?
Kind regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1. to develop Accepted and waiting to be taken care of enhancement feature: authentication feature: users and groups good first issue Small tasks with clear documentation about how and in which place you need to fix things in. security
Projects
None yet
Development

No branches or pull requests

6 participants