-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
resetpassword command supports send password reset link and display link #32345
Conversation
898e78b
to
b25dac0
Compare
Codecov Report
@@ Coverage Diff @@
## master #32345 +/- ##
============================================
+ Coverage 64.06% 64.11% +0.05%
- Complexity 18634 18641 +7
============================================
Files 1176 1176
Lines 70152 70185 +33
Branches 1270 1270
============================================
+ Hits 44944 45002 +58
+ Misses 24838 24813 -25
Partials 370 370
Continue to review full report at Codecov.
|
Do we have an use case for both options? Having the "via-mail" option is hard to figure out why we need the "via-link" option. |
In addition, I don't have a clear view of the expected flow. I don't think this is the flow we want, but the current code doesn't seem to have a clear idea such as the one above. |
@jvillafanez the option to output the link on the CLI is intended for docker setups where VMs are created automatically and a custom email is sent by VM scripts, including the link. For example "your server has been setup, click here to set your initial password: XYZ" |
As far as I understand this PR is only for generating a password reset token and sending the link by email and/or outputting on the CLI. It is not intended to actually set a password. |
Review required @PVince81 |
core/Command/User/ResetPassword.php
Outdated
'The email-id set while creating the user, will be used to send link for password reset. This option will also display the link sent to user.' | ||
) | ||
->addOption( | ||
'via-link', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"via link" means "something will be send through a link" and doesn't reflect what is happening here
maybe call it "output-link" or something similar
and rename "via-email" to "send-email"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to "send-email" and "output-link".
core/Command/User/ResetPassword.php
Outdated
$mail = new TemplateResponse('core', 'lostpassword/email', $mailData, 'blank'); | ||
$mailContent = $mail->render(); | ||
|
||
$subject = $this->l10n->t('Your password is reset'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this copy-pasted from another location ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this was copy-pasted from LostController.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make the code reusable ? not too happy to see that many lines copy-pasted...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I have refactored the code, in which case at this point of time refactoring LostController, would be too much for this PR, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see what has been refactored.
Is there a way then to pick smaller pieces ? I'm a bit worried that for example the token generation + token expiration code is duplicated. If one would decide to change the token format there is a risk of mismatch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code by modifying LostController, to provide link which can be used by ResetPassword for both send-email and output-link options.
core/Command/User/ResetPassword.php
Outdated
$output->writeln('<error>Email address is not set for the user ' . $user->getUID() . '</error>'); | ||
return 1; | ||
} | ||
} elseif ($displayLink) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emailing and displaying link aren't mutually exclusive. one could specify both
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the code, user can execute either email or displaying link or both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comments
b25dac0
to
c265f4d
Compare
core/Command/User/ResetPassword.php
Outdated
if (!$password) { | ||
$output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>'); | ||
return 1; | ||
} | ||
} elseif ($emailLink | $displayLink) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
core/Command/User/ResetPassword.php
Outdated
$message->setFrom([Util::getDefaultEmailAddress('no-reply') => $this->defaults->getName()]); | ||
$this->mailer->send($message); | ||
} catch (\Exception $e) { | ||
$output->writeln('<error>Can\'t send new user mail to ' . $user->getEMailAddress() . ': ' . $e->getMessage()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing </error>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added </error>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few more minor things, see comments
c1f9b01
to
c027c9c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better, thanks 👍
The resetpassword supports options to 1) display the password reset link in command line. 2) send email to reset the password for user and display the link in the command line. Signed-off-by: Sujith H <sharidasan@owncloud.com>
c027c9c
to
145a5d2
Compare
Backport stable10 : #32500 |
The resetpassword supports options to
display the link in the command line.
Signed-off-by: Sujith H sharidasan@owncloud.com
Description
The resetpassword supports options to
Related Issue
Motivation and Context
The resetpassword supports options to
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist:
Open tasks: