Ignore:
Timestamp:
17 Dec 2011, 18:47:57 (13 years ago)
Author:
Henrik Bettermann
Message:

Send email with credentials (including random password) after successful registration instead of redirecting to to a success page. Tests will follow.

File:
1 edited

Legend:

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

    r7364 r7365  
    5151from waeup.sirp.interfaces import (
    5252    ISIRPObject, ILocalRolesAssignable, IExtFileStore,
    53     IFileStoreNameChooser, IPasswordValidator, IUserAccount)
     53    IFileStoreNameChooser, IPasswordValidator, IUserAccount, ISIRPUtils)
    5454from waeup.sirp.permissions import get_users_with_local_roles
    5555from waeup.sirp.students.viewlets import PrimaryStudentNavTab
     
    10891089        return image
    10901090
    1091 class ApplicantRegistrationSuccessful(SIRPPage):
    1092     """Info page when applicant registration was successful.
    1093     """
    1094     grok.context(IApplicantsContainer)
    1095     grok.name('register_success')
    1096     grok.require('waeup.Public')
    1097     grok.template('applicantregister_succ')
    1098     label = 'Applicant Registration Successful'
    1099     title = label
    1100 
    1101     def update(self, app_id=None):
    1102         if app_id is None:
    1103             self.redirect(self.url(self.context, 'register'))
    1104         self.app_id = app_id
    1105         self.login_url = self.url(grok.getSite(), 'login')
    1106 
    11071091class ApplicantRegistrationPage(SIRPAddFormPage):
    11081092    """Captcha'd registration page for applicants.
     
    11311115            # No need to flash something.
    11321116            return
    1133 
    1134         # handle password field manually
    1135         form = self.request.form
    1136         password = form.get('password', None)
    1137         password_ctl = form.get('control_password', None)
    1138         if password:
    1139             validator = getUtility(IPasswordValidator)
    1140             errors = validator.validate_password(password, password_ctl)
    1141             if errors:
    1142                 self.flash( ' '.join(errors))
    1143                 return
    1144 
    1145         # add applicant and redirect to success page
     1117        sirp_utils = getUtility(ISIRPUtils)
     1118        # Add applicant and create password
    11461119        applicant = createObject('waeup.Applicant')
    11471120        self.applyData(applicant, **data)
    11481121        self.context.addApplicant(applicant)
    1149         IUserAccount(applicant).setPassword(password)
    1150         app_id = applicant.applicant_id
    1151         self.redirect(self.url(self.context, 'register_success',
    1152                                data=dict(app_id=app_id)))
    1153         return
     1122        pwd = sirp_utils.genPassword()
     1123        IUserAccount(applicant).setPassword(pwd)
     1124        # Send email with credentials
     1125        username = applicant.applicant_id
     1126        fullname = applicant.display_fullname
     1127        subject = 'Your SIRP credentials'
     1128        msg = 'You have successfully registered for the'
     1129        email_to = applicant.email
     1130        login_url = self.url(grok.getSite(), 'login')
     1131        success = sirp_utils.sendPassword(fullname,msg,username,
     1132            pwd,login_url,email_to,subject)
     1133        if success:
     1134            self.flash('An email with your user name and password' +
     1135                'has been sent to %s.' % email_to)
     1136        else:
     1137            self.flash('An smtp server error occurred.')
     1138        return
Note: See TracChangeset for help on using the changeset viewer.