From f29ac4eb2f326923b0858994df69ba1189b61f75 Mon Sep 17 00:00:00 2001 From: William Colmenares Date: Thu, 25 Apr 2019 16:14:58 -0400 Subject: [PATCH] Added sending welcome email on user registration --- dal/views.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/dal/views.py b/dal/views.py index ed1eef4..893997b 100644 --- a/dal/views.py +++ b/dal/views.py @@ -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')