Fix user display
Added mail when forgot password
This commit is contained in:
+39
-1
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user