From e6d1c7edf7be72017877fb9f5b77229afbea29f0 Mon Sep 17 00:00:00 2001 From: Jogi Hofmüller Date: Sun, 31 Jul 2011 16:38:40 +0000 Subject: - have a confirmation request sent by email for registration now * still trouble with unicode/utf-8 characters entered in form ... git-svn-id: https://svn.spreadspace.org/mur.sat@86 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- tools/mmd/MmdCommands.py | 24 ++++++++++++++++++++++-- tools/mmd/MmdDb.py | 9 ++++++--- tools/mmd/MmdUser.py | 16 +++++++++++++++- tools/mmd/MmdWidgets.py | 9 ++++++--- 4 files changed, 49 insertions(+), 9 deletions(-) (limited to 'tools/mmd') diff --git a/tools/mmd/MmdCommands.py b/tools/mmd/MmdCommands.py index 19a5968..0ac98da 100644 --- a/tools/mmd/MmdCommands.py +++ b/tools/mmd/MmdCommands.py @@ -41,12 +41,32 @@ def register (session): confirm = session.getQsConfirm () if password != confirm: - error_message = {'error': 'Password', 'description': 'Passwords do not match'} + error_message = {'error': 'Password', 'description': 'Passwords do not match.'} return indexWidget (dataWidget (), errorWidget (error_message), statusWidget (session.session_id, session.email)) user = User () - user.create (session.session_id, firstname, lastname, email, callsign, longitude, latitude, password) + confreg = user.create (session.session_id, firstname, lastname, email, callsign, longitude, latitude, password) + user.email = email + message = '''From: noreply +To: {0} +Subject: MMD registration confirmation request +Good day! + +Someone (probably you) has registered at the MURSAT1 Mission Dashbaord +(MMD) at http://sat.mur.at/dashboard. Please confirm the registration +using the link below: + + + http://hofos.at/mmd/mmd?cmd=confirmRegistration&code={1} + +Regards, +MURSAT1 team +'''.format (user.email, confreg) + + if not user.sendEmail (message): + error_message = {'error': 'Email', 'description': 'Email could not be sent.'} + return indexWidget (dataWidget (), errorWidget (error_message), statusWidget (session.session_id, session.email)) return indexWidget (dataWidget (), registerWidget (), statusWidget (session.session_id, session.email)) diff --git a/tools/mmd/MmdDb.py b/tools/mmd/MmdDb.py index 640a8ff..18a4df8 100644 --- a/tools/mmd/MmdDb.py +++ b/tools/mmd/MmdDb.py @@ -39,9 +39,12 @@ class Db: self.conn.commit () return self.cursor.rowcount - def userCreate (self, user_id, firstname, lastname, email, callsign, password): - self.cursor.execute ('INSERT INTO user (id, firstname, lastname, email, callsign, password) VALUES (?,?,?,?,?,?)', - (user_id, firstname, lastname, email, callsign, password)) + # + # user related methods + # + def userCreate (self, user_id, firstname, lastname, email, callsign, password, confreg): + self.cursor.execute ('INSERT INTO user (id, firstname, lastname, email, callsign, password, confreg) VALUES (?,?,?,?,?,?,?)', + (user_id, firstname, lastname, email, callsign, password, confreg)) self.conn.commit () def close (self): diff --git a/tools/mmd/MmdUser.py b/tools/mmd/MmdUser.py index 86e0a3d..ee45e72 100644 --- a/tools/mmd/MmdUser.py +++ b/tools/mmd/MmdUser.py @@ -2,6 +2,7 @@ User class for MURSAT1 Mission Dashboard """ import hashlib +import smtplib from cgi import parse_qs, escape from MmdDb import Db @@ -12,7 +13,20 @@ class User: def create (self, user_id, firstname, lastname, email, callsign, longitude, latitude, password): password_hash = hashlib.sha1 (password).hexdigest () - self.db.userCreate (user_id, firstname, lastname, email, callsign, password_hash) + token = str ('{0}{1}{2}{3}'.format (user_id, firstname, lastname, email)) + confreg = hashlib.sha1 (token).hexdigest () + self.db.userCreate (user_id, firstname, lastname, email, callsign, password_hash, confreg) + return confreg + + def sendEmail (self, message): + server = smtplib.SMTP ('localhost') + try: + server.sendmail ('noreply@mur.at', self.email, message) + server.quit () + return True + except (smtplib.SMTPRecipientsRefused, smtplib.SMTPHeloError, smtplib.SMTPSenderRefused, smtplib.SMTPDataError): + server.quit () + return False if __name__ == "__main__": pass diff --git a/tools/mmd/MmdWidgets.py b/tools/mmd/MmdWidgets.py index 9219e8c..1402410 100644 --- a/tools/mmd/MmdWidgets.py +++ b/tools/mmd/MmdWidgets.py @@ -11,7 +11,8 @@ def loginFormWidget (): - + +
Email:
Password:
@@ -40,7 +41,8 @@ def registerFormWidget (): Latitude: Password*: Confirm Password*: - + + @@ -51,7 +53,8 @@ def registerFormWidget (): def registerWidget (): html = ''' - you could be registered iff I had finished this code +

Thank you for registering!

+ You will receive an email conataining a link to confirm your registration. Please use this link within 24 hours to complete registration. ''' return html -- cgit v1.2.3