Ignore:
Timestamp:
18 Dec 2011, 08:24:04 (13 years ago)
Author:
Henrik Bettermann
Message:

Implement ChangePasswordRequestPage?.

Catch traceback, if student data are not complete and a test student presses the 'Book accommodation' button (regression test needed).

File:
1 edited

Legend:

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

    r7364 r7369  
    2626from zope.catalog.interfaces import ICatalog
    2727from zope.component import queryUtility, getUtility
     28#from hurry.query import Eq
     29#from hurry.query.query import Query
    2830from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
    2931from zope.component import createObject
     
    3335from waeup.sirp.browser import (
    3436    SIRPPage, SIRPEditFormPage, SIRPAddFormPage, SIRPDisplayFormPage,
    35     ContactAdminForm)
     37    ContactAdminForm, SIRPForm)
     38from waeup.sirp.browser.interfaces import ICaptchaManager
    3639from waeup.sirp.browser.breadcrumbs import Breadcrumb
    3740from waeup.sirp.browser.resources import datepicker, datatable, tabs, warning
     
    4144from waeup.sirp.interfaces import (
    4245    ISIRPObject, IUserAccount, IExtFileStore, IPasswordValidator, IContactForm,
    43     ISIRPUtils)
     46    ISIRPUtils, IUniversity)
    4447from waeup.sirp.widgets.datewidget import (
    4548    FriendlyDateWidget, FriendlyDateDisplayWidget,
     
    5154    IStudentAccommodation, IStudentClearanceEdit, IStudentStudyLevel,
    5255    ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer,
    53     IStudentOnlinePayment, IBedTicket, IStudentsUtils
     56    IStudentOnlinePayment, IBedTicket, IStudentsUtils, IStudentChangePassword
    5457    )
    5558from waeup.sirp.students.catalog import search
     
    193196    grok.context(ISIRPObject)
    194197    grok.name('setpassword')
    195     grok.require('waeup.Public')
     198    grok.require('waeup.Anonymous')
    196199    grok.template('setpassword')
    197200    title = ''
     
    14691472        students_utils = getUtility(IStudentsUtils)
    14701473        acc_details  = students_utils.getAccommodationDetails(student)
     1474        if not acc_details:
     1475            self.flash("Your data are incomplete.")
     1476            self.redirect(self.url(self.context))
     1477            return
    14711478        if not student.state in acc_details['allowed_states']:
    14721479            self.flash("You are in the wrong registration state.")
     
    21862193        self.redirect(self.url(self.context, u'@@edit'))
    21872194        return
     2195
     2196class ChangePasswordRequestPage(SIRPForm):
     2197    """Captcha'd page for students to request a password change.
     2198    """
     2199    grok.context(IUniversity)
     2200    grok.name('changepw')
     2201    grok.require('waeup.Anonymous')
     2202    grok.template('changepw')
     2203    title = 'Change Password Request'
     2204    label = 'Change my password'
     2205    form_fields = grok.AutoFields(IStudentChangePassword)
     2206
     2207    def update(self):
     2208        # Handle captcha
     2209        self.captcha = getUtility(ICaptchaManager).getCaptcha()
     2210        self.captcha_result = self.captcha.verify(self.request)
     2211        self.captcha_code = self.captcha.display(self.captcha_result.error_code)
     2212        return
     2213
     2214    @grok.action('Send request')
     2215    def request(self, **data):
     2216        if not self.captcha_result.is_valid:
     2217            # Captcha will display error messages automatically.
     2218            # No need to flash something.
     2219            return
     2220        # Search student
     2221        cat = queryUtility(ICatalog, name='students_catalog')
     2222        reg_number = data['reg_number']
     2223        email = data['email']
     2224        results = cat.searchResults(
     2225            reg_number=(reg_number, reg_number),
     2226            email=(email,email))
     2227        if len(results) == 0:
     2228            self.flash('No student record found.')
     2229            return
     2230        student = list(results)[0]
     2231        # Change password
     2232        sirp_utils = getUtility(ISIRPUtils)
     2233        pwd = sirp_utils.genPassword()
     2234        IUserAccount(student).setPassword(pwd)
     2235        # Send email with new redentials
     2236        username = student.student_id
     2237        fullname = student.display_fullname
     2238        subject = 'Your SIRP credentials'
     2239        msg = 'You have successfully changed your password for the'
     2240        email_to = student.email
     2241        login_url = self.url(grok.getSite(), 'login')
     2242        success = sirp_utils.sendPassword(fullname,msg,username,
     2243            pwd,login_url,email_to,subject)
     2244        if success:
     2245            self.flash('An email with your user name and password ' +
     2246                'has been sent to %s.' % email_to)
     2247        else:
     2248            self.flash('An smtp server error occurred.')
     2249        return
Note: See TracChangeset for help on using the changeset viewer.