login: Fix password reset mail link.

- Pyramid needs the request object to generate an URL.
- Therefore we generate the URL in the view and pass it to the model
  to send the email.
This commit is contained in:
Johannes Bornhold 2016-05-25 12:10:24 +02:00
parent 4ae78a405b
commit b7a3eecf07
2 changed files with 13 additions and 7 deletions

View file

@ -326,7 +326,17 @@ class LoginView(object):
error_dict = {'recaptcha_field': _msg}
raise formencode.Invalid(_msg, _value, None,
error_dict=error_dict)
UserModel().reset_password_link(form_result)
# Generate reset URL and send mail.
user_email = form_result['email']
user = User.get_by_email(user_email)
password_reset_url = self.request.route_url(
'reset_password_confirmation',
_query={'key': user.api_key})
UserModel().reset_password_link(
form_result, password_reset_url)
# Display success message and redirect.
self.session.flash(
_('Your password reset link was sent'),
queue='success')

View file

@ -493,7 +493,7 @@ class UserModel(BaseModel):
log.error(traceback.format_exc())
raise
def reset_password_link(self, data):
def reset_password_link(self, data, pwd_reset_url):
from rhodecode.lib.celerylib import tasks, run_task
from rhodecode.model.notification import EmailNotificationModel
user_email = data['email']
@ -502,12 +502,8 @@ class UserModel(BaseModel):
if user:
log.debug('password reset user found %s', user)
password_reset_url = url(
'reset_password_confirmation', key=user.api_key,
qualified=True)
email_kwargs = {
'password_reset_url': password_reset_url,
'password_reset_url': pwd_reset_url,
'user': user,
'email': user_email,
'date': datetime.datetime.now()