Changeset 9334 for main/waeup.kofa/trunk/src/waeup/kofa/students/student.py
- Timestamp:
- 14 Oct 2012, 21:02:31 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/student.py
r9183 r9334 23 23 import shutil 24 24 import grok 25 from datetime import datetime, timedelta 25 26 from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo 27 from zope.password.interfaces import IPasswordManager 26 28 from zope.component import getUtility, createObject 27 29 from zope.component.interfaces import IFactory … … 52 54 grok.provides(IStudent) 53 55 56 temp_password_minutes = 10 57 54 58 def __init__(self): 55 59 super(Student, self).__init__() … … 60 64 self.student_id = u'Z654321' 61 65 self.password = None 62 return 66 self.temp_password = None 67 return 68 69 def setTempPassword(self, user, password): 70 """Set a temporary password (LDAP-compatible) SSHA encoded for 71 officers. 72 73 """ 74 passwordmanager = getUtility(IPasswordManager, 'SSHA') 75 self.temp_password = {} 76 self.temp_password[ 77 'password'] = passwordmanager.encodePassword(password) 78 self.temp_password['user'] = user 79 self.temp_password['timestamp'] = datetime.utcnow() # offset-naive datetime 80 81 def getTempPassword(self): 82 """Check if a temporary password has been set and if it 83 is not expired. 84 85 Return the temporary password if valid, 86 None otherwise. Unset the temporary password if expired. 87 """ 88 temp_password_dict = getattr(self, 'temp_password', None) 89 if temp_password_dict is not None: 90 delta = timedelta(minutes=self.temp_password_minutes) 91 now = datetime.utcnow() 92 if now < temp_password_dict.get('timestamp') + delta: 93 return temp_password_dict.get('password') 94 else: 95 # Unset temporary password if expired 96 self.temp_password = None 97 return None 63 98 64 99 def writeLogMessage(self, view, message):
Note: See TracChangeset for help on using the changeset viewer.