From 16b02cfe3f81f26714e41f63cb93213285ec9d73 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 24 Feb 2019 18:42:02 +0100 Subject: [PATCH] Create base_url from request rather than hard code --- dal/views.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/dal/views.py b/dal/views.py index 2ea6dfb..18ff70d 100644 --- a/dal/views.py +++ b/dal/views.py @@ -193,14 +193,14 @@ class ResetPassword(View): return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': emailsend } ) # Sends an email to the user with the 24h active link for a password reset - def email(self, user, email): + def email(self, user, email, base_url): # getting epoch for the time now in UTC to spare us headache with timezones creationtime = int(datetime.utcnow().timestamp()) # Construct the data for the email email_from = settings.EMAIL_FROM_ADDRESS to = ['%s <%s>' % (user, email)] subject = 'Password reset request for %s' % user - link = self.build_reset_link(user, creationtime) + link = self.build_reset_link(user, creationtime, base_url) body = 'This is an automated email which was triggered by a reset request for the user %s. Please do not reply to this email.\n' % user body += 'If you received this email in error, please disregard it. If you get multiple emails like this, please contact us to look into potential abuse.\n' body += 'To reset your password, please follow the link below:\n' @@ -221,9 +221,8 @@ class ResetPassword(View): return result # Builds the reset link for the email and puts the token into the database - def build_reset_link(self, user, epochutc): + def build_reset_link(self, user, epochutc, base_url): # set up the data - host = 'account-staging.ungleich.ch' tokengen = PasswordResetTokenGenerator() # create some noise for use in the tokengenerator pseudouser = PseudoUser() @@ -234,7 +233,7 @@ class ResetPassword(View): newdbentry = ResetToken(user=user, token=token, creation=epochutc) newdbentry.save() # set up the link - link = 'https://%s/reset/%s/%s/' % (host, userpart.decode('utf-8'), token) + link = (base_url + '/reset/%s/%s/') % (userpart.decode('utf-8'), token) return link