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).

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/browser/templates/loginpage.pt

    r7198 r7369  
    3030  Acquire a Password Access Code (PWD) and inititialize your student account
    3131  <strong><a href  ="setpassword"> here</a></strong>.
     32  </p> <p> Or simply forgot your student id or password? Then request a new password
     33  <strong><a href  ="changepw"> here</a></strong>.
    3234  </p>
    3335
     36
     37
    3438</form>
  • 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
  • main/waeup.sirp/trunk/src/waeup/sirp/students/catalog.py

    r7364 r7369  
    3838    student_id = index.Field(attribute='student_id')
    3939    fullname = index.Text(attribute='fullname')
     40    email = index.Field(attribute='email')
    4041    reg_number = index.Field(attribute='reg_number')
    4142    matric_number = index.Field(attribute='matric_number')
  • main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py

    r7364 r7369  
    453453
    454454    """
     455
     456class IStudentChangePassword(ISIRPObject):
     457    """Interface needed for change pasword page.
     458
     459    """
     460
     461    reg_number = schema.TextLine(
     462        title = u'Registration Number',
     463        default = None,
     464        required = True,
     465        readonly = False,
     466        )
     467
     468    email = schema.ASCIILine(
     469        title = u'Email',
     470        required = True,
     471        constraint=validate_email,
     472        )
  • main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py

    r7365 r7369  
    191191        # Determine bed type
    192192        studycourse = student['studycourse']
     193        certificate = getattr(studycourse,'certificate',None)
    193194        entry_session = studycourse.entry_session
    194195        current_level = studycourse.current_level
    195         end_level = studycourse.certificate.end_level
     196        if not (entry_session and current_level and certificate):
     197            return
     198        end_level = certificate.end_level
    196199        if entry_session == grok.getSite()['configuration'].accommodation_session:
    197200            bt = 'fr'
Note: See TracChangeset for help on using the changeset viewer.