From a3366c221f530679e118f729908a17d52f822dad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bodor=20M=C3=A1t=C3=A9?= <bodor.mate@kszk.bme.hu>
Date: Sat, 19 Jan 2019 10:43:20 +0100
Subject: [PATCH] Add email settings

---
 src/account/auth_pipeline.py         | 7 +++----
 src/common/email.py                  | 6 ++++++
 src/kszkepzes/settings/base.py       | 9 +--------
 src/kszkepzes/settings/local.py      | 6 ++++++
 src/kszkepzes/settings/production.py | 6 ++++++
 5 files changed, 22 insertions(+), 12 deletions(-)
 create mode 100644 src/common/email.py

diff --git a/src/account/auth_pipeline.py b/src/account/auth_pipeline.py
index 4a9cfa1..16eb573 100644
--- a/src/account/auth_pipeline.py
+++ b/src/account/auth_pipeline.py
@@ -1,15 +1,14 @@
 from django.core import exceptions
-from django.core.mail import send_mail
+from common.email import registration_email
 
 from . import models
 
 
 def create_profile(backend, user, response, *args, **kwargs):
     if backend.name == 'authsch':
+        if user.email is not None:
+            registration_email(user.email)
         try:
             user.profile
         except exceptions.ObjectDoesNotExist:
             models.Profile.objects.create(user=user)
-            if user.email is not None:
-                send_mail('TESZT', 'Udvozlunk a kszkepzesen, ne felejtsd el kitolteni a profilod.',
-                          'noreply@devteam.sch.bme.hu', [user.email, ])
diff --git a/src/common/email.py b/src/common/email.py
new file mode 100644
index 0000000..6e455ad
--- /dev/null
+++ b/src/common/email.py
@@ -0,0 +1,6 @@
+from django.core.mail import send_mail
+
+
+def registration_email(email):
+    send_mail('TESZT', 'Udvozlunk a kszkepzesen, ne felejtsd el kitolteni a profilod.',
+              'noreply@devteam.sch.bme.hu', [email, ])
\ No newline at end of file
diff --git a/src/kszkepzes/settings/base.py b/src/kszkepzes/settings/base.py
index a00562b..b831a0e 100644
--- a/src/kszkepzes/settings/base.py
+++ b/src/kszkepzes/settings/base.py
@@ -38,7 +38,7 @@ INSTALLED_APPS = [
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'django_extensions',
-     'import_export',
+    'import_export',
     'rest_framework',
     'social_django',
     'solo',
@@ -158,10 +158,3 @@ STATIC_URL = '/django-static/'
 
 MEDIA_ROOT = os.getenv('MEDIA_ROOT', '/tmp')
 MEDIA_URL = '/media/'
-
-EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
-EMAIL_HOST = 'smtp.gmail.com'
-EMAIL_USE_TLS = True
-EMAIL_PORT = 587
-EMAIL_HOST_USER = 'bmate711kamu@gmail.com'
-EMAIL_HOST_PASSWORD = '1IronxDog'
diff --git a/src/kszkepzes/settings/local.py b/src/kszkepzes/settings/local.py
index 9d29321..2cb6909 100644
--- a/src/kszkepzes/settings/local.py
+++ b/src/kszkepzes/settings/local.py
@@ -1,3 +1,9 @@
 from .base import *
 
 SESSION_COOKIE_SECURE=False
+EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
+EMAIL_HOST = 'smtp.gmail.com'
+EMAIL_USE_TLS = True
+EMAIL_PORT = 587
+EMAIL_HOST_USER = 'bmate711kamu@gmail.com'
+EMAIL_HOST_PASSWORD = '1IronxDog'
diff --git a/src/kszkepzes/settings/production.py b/src/kszkepzes/settings/production.py
index ebf1050..8fa02bb 100644
--- a/src/kszkepzes/settings/production.py
+++ b/src/kszkepzes/settings/production.py
@@ -26,3 +26,9 @@ REST_FRAMEWORK = {
 }
 
 STATIC_ROOT = os.path.join(BASE_DIR, 'static_collected')
+
+
+EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
+EMAIL_HOST = 'mail.sch.bme.hu'
+EMAIL_USE_TLS = True
+EMAIL_PORT = 587
-- 
GitLab