From 5ef1d6874228fc202f38faefbe2f688c209764ea Mon Sep 17 00:00:00 2001
From: Charles Anteunis <charles@MacBook-Air-de-Charles.local>
Date: Wed, 16 Oct 2019 09:53:16 +0200
Subject: [PATCH] envoi de mail fonctionnel

---
 website/nutriform/templates/nutriform/index.html |  1 +
 website/nutriform/views.py                       | 10 ++++++++++
 website/website/settings.py                      | 13 +++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/website/nutriform/templates/nutriform/index.html b/website/nutriform/templates/nutriform/index.html
index 2e84298..71526ea 100644
--- a/website/nutriform/templates/nutriform/index.html
+++ b/website/nutriform/templates/nutriform/index.html
@@ -143,6 +143,7 @@
 							<p>N'hésitez pas à nous contacter !</p>
 						</header>
 						<form method="post" action="#">
+							{% csrf_token %}
 							<div class="row uniform 50%" style="color: whitesmoke;">
 								<div class="6u 12u$(xsmall)">
 									<input type="text" name="name" id="name" value="" placeholder="Nom" />
diff --git a/website/nutriform/views.py b/website/nutriform/views.py
index b38009b..747ea6f 100644
--- a/website/nutriform/views.py
+++ b/website/nutriform/views.py
@@ -1,7 +1,17 @@
 from django.shortcuts import render
 from django.http import HttpResponse
+from django.core.mail import send_mail
 
 def index(request):
+	if request.method == 'POST' :
+		if request.POST['name'] and request.POST['email'] and request.POST['message'] :
+			send_mail(
+				'Contact: '+request.POST['name'],
+				'from : '+request.POST['email']+'\n\n'+request.POST['message'],
+				request.POST['email'],
+				['charles.anteunis@gmail.com',]
+			)
+			
 	return render(request, 'nutriform/index.html')
 
 # Create your views here.
diff --git a/website/website/settings.py b/website/website/settings.py
index a4afcf1..ff4902d 100644
--- a/website/website/settings.py
+++ b/website/website/settings.py
@@ -22,6 +22,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 # SECURITY WARNING: keep the secret key used in production secret!
 SECRET_KEY = '2c^k19waap+)_bcypl^jyi83yvlt%da$)w!6hn)@8zs$3au5wh'
 
+# SECURITY WARNING: 
+mdp = "dntzzrgabemlgbra"
+
 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = True
 
@@ -114,6 +117,16 @@ USE_L10N = True
 
 USE_TZ = True
 
+#paramètres mail
+EMAIL_HOST = 'smtp.gmail.com'
+EMAIL_PORT = 587
+EMAIL_HOST_USER = 'nutriformpima@gmail.com'
+EMAIL_HOST_PASSWORD = mdp
+EMAIL_USE_TLS = True
+
+ADMINS = [('Charles', 'charles.anteunis@gmail.com'),]
+
+
 
 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/2.2/howto/static-files/
-- 
GitLab