Create base_url from request rather than hard code
This commit is contained in:
parent
9ce45e6f56
commit
16b02cfe3f
1 changed files with 4 additions and 5 deletions
|
@ -193,14 +193,14 @@ class ResetPassword(View):
|
||||||
return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': emailsend } )
|
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
|
# 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
|
# getting epoch for the time now in UTC to spare us headache with timezones
|
||||||
creationtime = int(datetime.utcnow().timestamp())
|
creationtime = int(datetime.utcnow().timestamp())
|
||||||
# Construct the data for the email
|
# Construct the data for the email
|
||||||
email_from = settings.EMAIL_FROM_ADDRESS
|
email_from = settings.EMAIL_FROM_ADDRESS
|
||||||
to = ['%s <%s>' % (user, email)]
|
to = ['%s <%s>' % (user, email)]
|
||||||
subject = 'Password reset request for %s' % user
|
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 = '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 += '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'
|
body += 'To reset your password, please follow the link below:\n'
|
||||||
|
@ -221,9 +221,8 @@ class ResetPassword(View):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# Builds the reset link for the email and puts the token into the database
|
# 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
|
# set up the data
|
||||||
host = 'account-staging.ungleich.ch'
|
|
||||||
tokengen = PasswordResetTokenGenerator()
|
tokengen = PasswordResetTokenGenerator()
|
||||||
# create some noise for use in the tokengenerator
|
# create some noise for use in the tokengenerator
|
||||||
pseudouser = PseudoUser()
|
pseudouser = PseudoUser()
|
||||||
|
@ -234,7 +233,7 @@ class ResetPassword(View):
|
||||||
newdbentry = ResetToken(user=user, token=token, creation=epochutc)
|
newdbentry = ResetToken(user=user, token=token, creation=epochutc)
|
||||||
newdbentry.save()
|
newdbentry.save()
|
||||||
# set up the link
|
# 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
|
return link
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue