Changeset 7660 for main/waeup.sirp


Ignore:
Timestamp:
16 Feb 2012, 15:31:58 (13 years ago)
Author:
Henrik Bettermann
Message:

Move SetPasswordPage? and ChangePasswordRequestPage? to the end of the module. They are closely related.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py

    r7647 r7660  
    187187        return
    188188
    189 class SetPasswordPage(SIRPPage):
    190     grok.context(ISIRPObject)
    191     grok.name('setpassword')
    192     grok.require('waeup.Anonymous')
    193     grok.template('setpassword')
    194     label = 'Set password for first-time login'
    195     ac_prefix = 'PWD'
    196     pnav = 0
    197 
    198     def update(self, SUBMIT=None):
    199         self.reg_number = self.request.form.get('reg_number', None)
    200         self.ac_series = self.request.form.get('ac_series', None)
    201         self.ac_number = self.request.form.get('ac_number', None)
    202 
    203         if SUBMIT is None:
    204             return
    205         hitlist = search(query=self.reg_number,
    206             searchtype='reg_number', view=self)
    207         if not hitlist:
    208             self.flash('No student found.')
    209             return
    210         if len(hitlist) != 1:   # Cannot happen but anyway
    211             self.flash('More than one student found.')
    212             return
    213         student = hitlist[0].context
    214         self.student_id = student.student_id
    215         student_pw = student.password
    216         pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number)
    217         code = get_access_code(pin)
    218         if not code:
    219             self.flash('Access code is invalid.')
    220             return
    221         if student_pw and pin == student.adm_code:
    222             self.flash('Password has already been set. Your Student Id is %s'
    223                 % self.student_id)
    224             return
    225         elif student_pw:
    226             self.flash(
    227                 'Password has already been set. You are using the '
    228                 'wrong Access Code.')
    229             return
    230         # Mark pin as used (this also fires a pin related transition)
    231         # and set student password
    232         if code.state == USED:
    233             self.flash('Access code has already been used.')
    234             return
    235         else:
    236             comment = u"AC invalidated for %s" % self.student_id
    237             # Here we know that the ac is in state initialized so we do not
    238             # expect an exception
    239             invalidate_accesscode(pin,comment)
    240             IUserAccount(student).setPassword(self.ac_number)
    241             student.adm_code = pin
    242         self.flash('Password has been set. Your Student Id is %s'
    243             % self.student_id)
    244         return
    245 
    246189class StudentsContainerManagePage(SIRPPage):
    247190    """The manage page for student containers.
     
    18481791        return
    18491792
     1793class SetPasswordPage(SIRPPage):
     1794    grok.context(ISIRPObject)
     1795    grok.name('setpassword')
     1796    grok.require('waeup.Anonymous')
     1797    grok.template('setpassword')
     1798    label = 'Set password for first-time login'
     1799    ac_prefix = 'PWD'
     1800    pnav = 0
     1801
     1802    def update(self, SUBMIT=None):
     1803        self.reg_number = self.request.form.get('reg_number', None)
     1804        self.ac_series = self.request.form.get('ac_series', None)
     1805        self.ac_number = self.request.form.get('ac_number', None)
     1806
     1807        if SUBMIT is None:
     1808            return
     1809        hitlist = search(query=self.reg_number,
     1810            searchtype='reg_number', view=self)
     1811        if not hitlist:
     1812            self.flash('No student found.')
     1813            return
     1814        if len(hitlist) != 1:   # Cannot happen but anyway
     1815            self.flash('More than one student found.')
     1816            return
     1817        student = hitlist[0].context
     1818        self.student_id = student.student_id
     1819        student_pw = student.password
     1820        pin = '%s-%s-%s' % (self.ac_prefix, self.ac_series, self.ac_number)
     1821        code = get_access_code(pin)
     1822        if not code:
     1823            self.flash('Access code is invalid.')
     1824            return
     1825        if student_pw and pin == student.adm_code:
     1826            self.flash('Password has already been set. Your Student Id is %s'
     1827                % self.student_id)
     1828            return
     1829        elif student_pw:
     1830            self.flash(
     1831                'Password has already been set. You are using the '
     1832                'wrong Access Code.')
     1833            return
     1834        # Mark pin as used (this also fires a pin related transition)
     1835        # and set student password
     1836        if code.state == USED:
     1837            self.flash('Access code has already been used.')
     1838            return
     1839        else:
     1840            comment = u"AC invalidated for %s" % self.student_id
     1841            # Here we know that the ac is in state initialized so we do not
     1842            # expect an exception
     1843            invalidate_accesscode(pin,comment)
     1844            IUserAccount(student).setPassword(self.ac_number)
     1845            student.adm_code = pin
     1846        self.flash('Password has been set. Your Student Id is %s'
     1847            % self.student_id)
     1848        return
Note: See TracChangeset for help on using the changeset viewer.