From 502b6a813a6f90c2e7adb5781b1beecd559014d9 Mon Sep 17 00:00:00 2001 From: Jogi Hofmüller Date: Wed, 3 Aug 2011 11:19:44 +0000 Subject: - added functionality for location - user's default location is save - map centers on user's location iff available git-svn-id: https://svn.spreadspace.org/mur.sat@96 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- tools/mmd/MmdUser.py | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'tools/mmd/MmdUser.py') diff --git a/tools/mmd/MmdUser.py b/tools/mmd/MmdUser.py index d9597b1..feb8f5a 100644 --- a/tools/mmd/MmdUser.py +++ b/tools/mmd/MmdUser.py @@ -6,15 +6,16 @@ import smtplib import time from cgi import parse_qs, escape from MmdDb import Db -from MmdLocation import Location +from MmdLocationList import LocationList class User: def __init__ (self, email = 'Anonymous'): self.db = Db () self.email = email + self.location_list = LocationList () - def create (self, user_id, firstname, lastname, email, callsign, longitude, latitude, password): + def create (self, user_id, firstname, lastname, email, callsign, password): password_hash = hashlib.sha1 (password).hexdigest () code = hashlib.sha1 ('{0}{1}{2}{3}'.format (user_id, firstname, lastname, email)).hexdigest () regtimeout = int (time.strftime ('%s')) + (3600 * 24) @@ -23,8 +24,13 @@ class User: self.email = email self.firstname = firstname self.lastname = lastname + self.user_id = user_id return code + def addLocation (self, name, longitude, latitude, is_default): + self.location_list = LocationList (self.user_id) + return self.location_list.addLocation (name, longitude, latitude, is_default) + def findPending (self, code): u = self.db.userFindPending (code) if not u: @@ -45,15 +51,17 @@ class User: self.lastname = u['lastname'] return True - def load (self, email): - u = self.db.userFindEmail (email) + def load (self, email = False): + if email: + self.email = email + u = self.db.userFindEmail (self.email) if not u: return False - self.email = email + self.user_id = u['id'] self.firstname = u['firstname'] self.lastname = u['lastname'] self.password = u['password'] - # include loading of location data here + self.location_list = LocationList (self.user_id) return True def checkPassword (self, password): @@ -62,8 +70,15 @@ class User: return False def cancel (self, code): + self.deleteLocationList () self.db.userCancel (code) + def deleteLocationList (self): + self.location_list.delete () + + def getDefaultLocation (self): + return self.location_list.getDefaultLocation () + def sendEmail (self, message): server = smtplib.SMTP ('localhost') try: @@ -76,12 +91,19 @@ class User: if __name__ == "__main__": user = User () + email = 'the6@mur.at' try: assert user, 'no user object' - code = user.create (1, 'jogi', 'hofmueller', 'jogi@mur.at', '', 14.4, 47.2, 'blah') + code = user.create (1, 'jogi', 'hofmueller', email, '', 14.4, 47.2, 'blah') assert code, 'could not create user' - assert user.load ('jogi@mur.at'), 'could not load user data from db' - print 'passed all tests' + assert user.load (email), 'could not load user data from db' + print 'User:', user.firstname, user.lastname, user.email + assert user.addLocation ('Graz', '14.4', '47.2', 'yes'), 'could not add location' + location = user.getDefaultLocation () + assert location, 'could not get default location' + print 'Location:', location.name, location.longitude, location.latitude, location.is_default + user.cancel (code) + print 'passed all tests and removed objects from database' except AssertionError as error: print 'Test failed: {0}'.format (error) -- cgit v1.2.3