Ignore:
Timestamp:
14 Oct 2012, 21:02:31 (12 years ago)
Author:
Henrik Bettermann
Message:

Dedicated officers should be able to login as student with a temporary password set by the system. This is the first part of its implementation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/student.py

    r9183 r9334  
    2323import shutil
    2424import grok
     25from datetime import datetime, timedelta
    2526from hurry.workflow.interfaces import IWorkflowState, IWorkflowInfo
     27from zope.password.interfaces import IPasswordManager
    2628from zope.component import getUtility, createObject
    2729from zope.component.interfaces import IFactory
     
    5254    grok.provides(IStudent)
    5355
     56    temp_password_minutes = 10
     57
    5458    def __init__(self):
    5559        super(Student, self).__init__()
     
    6064            self.student_id = u'Z654321'
    6165        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
    6398
    6499    def writeLogMessage(self, view, message):
Note: See TracChangeset for help on using the changeset viewer.