Create base_url from request rather than hard code

This commit is contained in:
PCoder 2019-02-24 18:42:02 +01:00
parent 9ce45e6f56
commit 16b02cfe3f

View file

@ -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