Added sending welcome email on user registration

This commit is contained in:
wcolmenares 2019-04-25 16:14:58 -04:00
parent 8fff460305
commit f29ac4eb2f

View file

@ -96,7 +96,25 @@ class Register(View):
return render(request, 'error.html', { 'urlname': urlname,
'service': service,
'error': e } )
# Finally, we send the send user credentials via email
creationtime = int(datetime.utcnow().timestamp())
# Construct the data for the email
email_from = settings.EMAIL_FROM_ADDRESS
to = ['%s <%s>' % (username, email)]
subject = '{}, Welcome to datacenterlight'.format(firstname)
body = 'The username {} was successfully created.\n'.format(username)
# Build the email
mail = EmailMessage(
subject=subject,
body=body,
from_email=email_from,
to=to
)
try:
mail.send()
except Exception as e:
print(e)
pass
return render(request, 'usercreated.html', { 'user': username } )
class ChangeData(LoginRequiredMixin, View):
@ -466,6 +484,9 @@ class PseudoUser():
class UserCreateAPI(APIView):
def post(self, request):
print(request.data)
print(request.POST)
username = request.POST.get('username')
email = request.POST.get('email')
firstname = request.POST.get('firstname')