Ignore:
Timestamp:
4 May 2012, 20:44:48 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement a ChangePasswordRequestPage? for all portal users (more tests will follow).

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students
Files:
1 deleted
3 edited

Legend:

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

    r8325 r8346  
    3737    KofaPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage,
    3838    ContactAdminForm, KofaForm, NullValidator)
    39 from waeup.kofa.browser.interfaces import ICaptchaManager
    4039from waeup.kofa.browser.breadcrumbs import Breadcrumb
    4140from waeup.kofa.browser.resources import datepicker, datatable, tabs, warning
     
    5554    IStudentAccommodation, IStudentStudyLevel,
    5655    ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer,
    57     IStudentOnlinePayment, IBedTicket, IStudentsUtils, IStudentChangePassword
     56    IStudentOnlinePayment, IBedTicket, IStudentsUtils
    5857    )
    5958from waeup.kofa.students.catalog import search
     
    19071906        return
    19081907
    1909 class ChangePasswordRequestPage(KofaForm):
    1910     """Captcha'd page for students to request a password change.
    1911     """
    1912     grok.context(IUniversity)
    1913     grok.name('sendpw')
    1914     grok.require('waeup.Anonymous')
    1915     grok.template('sendpassword')
    1916     label = _('Send me a new password')
    1917     form_fields = grok.AutoFields(IStudentChangePassword)
    1918 
    1919     def update(self):
    1920         # Handle captcha
    1921         self.captcha = getUtility(ICaptchaManager).getCaptcha()
    1922         self.captcha_result = self.captcha.verify(self.request)
    1923         self.captcha_code = self.captcha.display(self.captcha_result.error_code)
    1924         return
    1925 
    1926     @action(_('Get new login credentials'), style='primary')
    1927     def request(self, **data):
    1928         if not self.captcha_result.is_valid:
    1929             # Captcha will display error messages automatically.
    1930             # No need to flash something.
    1931             return
    1932         # Search student or applicant
    1933         reg_number = data['reg_number']
    1934         email = data['email']
    1935         cat = queryUtility(ICatalog, name='students_catalog')
    1936         results = cat.searchResults(
    1937             reg_number=(reg_number, reg_number),
    1938             email=(email,email))
    1939         if len(results) == 0:
    1940             # Try also the applicants_catalog if no student record was found.
    1941             cat = queryUtility(ICatalog, name='applicants_catalog')
    1942             if cat is None:
    1943                 self.flash(_('Application package not installed.'))
    1944                 return
    1945             results = cat.searchResults(
    1946                 reg_number=(reg_number, reg_number),
    1947                 email=(email,email))
    1948         if len(results) == 0:
    1949             self.flash(_('No record found.'))
    1950             return
    1951         student = list(results)[0]
    1952         # Change password
    1953         kofa_utils = getUtility(IKofaUtils)
    1954         pwd = kofa_utils.genPassword()
    1955         IUserAccount(student).setPassword(pwd)
    1956         # Send email with new redentials
    1957         msg = _('You have successfully changed your password for the')
    1958         login_url = self.url(grok.getSite(), 'login')
    1959         success = kofa_utils.sendCredentials(
    1960             IUserAccount(student),pwd,login_url,msg)
    1961         if success:
    1962             self.flash(_('An email with your user name and password ' +
    1963                 'has been sent to ${a}.', mapping = {'a':email}))
    1964         else:
    1965             self.flash(_('An smtp server error occurred.'))
    1966         return
    19671908
    19681909class SetPasswordPage(KofaPage):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py

    r8268 r8346  
    510510IStudentOnlinePayment['p_level'].order = IStudentOnlinePayment[
    511511    'p_session'].order
    512 
    513 
    514 class IStudentChangePassword(IKofaObject):
    515     """Interface needed for change pasword page.
    516 
    517     """
    518     reg_number = schema.TextLine(
    519         title = _(u'Registration Number'),
    520         required = True,
    521         readonly = False,
    522         )
    523 
    524     email = schema.ASCIILine(
    525         title = _(u'Email Address'),
    526         required = True,
    527         constraint=validate_email,
    528         )
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py

    r8322 r8346  
    16951695    def test_change_password_request(self):
    16961696        self.browser.open('http://localhost/app/sendpw')
    1697         self.browser.getControl(name="form.reg_number").value = '123'
     1697        self.browser.getControl(name="form.identifier").value = '123'
    16981698        self.browser.getControl(name="form.email").value = 'aa@aa.ng'
    1699         self.browser.getControl("Get new login credentials").click()
     1699        self.browser.getControl("Get login credentials").click()
    17001700        self.assertTrue('An email with' in self.browser.contents)
    17011701
Note: See TracChangeset for help on using the changeset viewer.