diff --git a/.gitignore b/.gitignore index 7e99e36..da26b06 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -*.pyc \ No newline at end of file +*.pyc +/jm2l/upload/images/* +JM2L.egg-info/* +JM2L.sqlite diff --git a/jm2l/auth.py b/jm2l/auth.py index ca60575..75cfd34 100644 --- a/jm2l/auth.py +++ b/jm2l/auth.py @@ -3,7 +3,11 @@ from pyramid.view import view_config from pyramid.security import remember, forget from pyramid.httpexceptions import HTTPFound from .models import User, DBSession +from mako.template import Template +from pyramid_mailer import get_mailer +from pyramid_mailer.message import Attachment, Message import datetime +import re @view_config(route_name='auth', match_param="action=login", renderer="jm2l:templates/login.mako") def login(request): @@ -11,7 +15,41 @@ def login(request): @view_config(route_name='auth', match_param="action=forgot", renderer="jm2l:templates/login.mako") def forgot(request): - return {'forgot':True} + if request.method == 'POST' and request.POST: + request.POST.get('mail') + Found = re.match(r'^.+@([^.@][^@]+)$', request.POST.get('mail'), re.IGNORECASE) + if not Found: + request.session.flash(('error',u"Vous n'avez pas entré un e-mail valide !")) + return { 'forgot': True } + else: + UserFound = User.by_mail( Found.group(0) ) + if not UserFound: + request.session.flash(('error',u"Nous n'avons pas d'interlocuteur avec cette adresse e-mail !")) + return { 'forgot': True } + else: + # Send the Forgot Mail + mailer = request.registry['mailer'] + # Prepare Plain Text Message : + Mail_template = Template(filename='jm2l/templates/mail_plain.mako') + mail_plain = Mail_template.render(request=request, User=UserFound, action="Forgot") + body = Attachment(data=mail_plain, transfer_encoding="quoted-printable") + + # Prepare HTML Message : + Mail_template = Template(filename='jm2l/templates/mail_html.mako') + mail_html = Mail_template.render(request=request, User=UserFound, action="Forgot") + html = Attachment(data=mail_html, transfer_encoding="quoted-printable") + + # Prepare Message + message = Message(subject="[JM2L] Mes identifiants du site web JM2L", + sender="contact@jm2l.linux-azur.org", + recipients=[UserFound.mail], + body=body, html=html) + + message.add_bcc("spam@style-python.fr") + mailer.send(message) + + request.session.flash(('info',u"Vos informations de connection vous ont été renvoyé par e-mail")) + return { 'forgot': True } @view_config(route_name='bymail', renderer="string") def bymail(request): diff --git a/jm2l/models.py b/jm2l/models.py index 1995fa7..fe56d9b 100644 --- a/jm2l/models.py +++ b/jm2l/models.py @@ -139,6 +139,10 @@ class User(Base): def by_id(cls, id): return DBSession.query(cls).filter(cls.uid == id).first() + @classmethod + def by_mail(cls, mail): + return DBSession.query(cls).filter(cls.mail == mail).first() + @classmethod def by_slug(cls, slug): return DBSession.query(cls).filter(cls.slug == slug).first() diff --git a/jm2l/templates/Profil/Profil.mako b/jm2l/templates/Profil/Profil.mako index 247551c..2e31135 100644 --- a/jm2l/templates/Profil/Profil.mako +++ b/jm2l/templates/Profil/Profil.mako @@ -68,8 +68,9 @@ DicForm2 = { ${helpers.DisplayRespForm(profil_form, DicFormB)}