Ignore:
Timestamp:
18 Dec 2011, 15:26:41 (13 years ago)
Author:
uli
Message:

Split overlong register method: put sendmail stuff into separate
method.

File:
1 edited

Legend:

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

    r7378 r7380  
    11341134        return
    11351135
    1136     @grok.action('Send login credentials')
     1136    @grok.action('Get login credentials')
    11371137    def register(self, **data):
    11381138        if not self.captcha_result.is_valid:
     
    11401140            # No need to flash something.
    11411141            return
    1142         sirp_utils = getUtility(ISIRPUtils)
    11431142        # Add applicant and create password
    11441143        applicant = createObject('waeup.Applicant')
    11451144        self.applyData(applicant, **data)
    11461145        self.context.addApplicant(applicant)
    1147         pwd = sirp_utils.genPassword()
    1148         IUserAccount(applicant).setPassword(pwd)
     1146        password = getUtility(ISIRPUtils).genPassword()
     1147        IUserAccount(applicant).setPassword(password)
    11491148        # Send email with credentials
     1149        if self.sendCredentials(applicant, password):
     1150            self.redirect(self.url(self.context, 'registration_complete',
     1151                                   data = dict(email=applicant.email)))
     1152            return
     1153        else:
     1154            self.flash('Email could not been sent. Please retry later.')
     1155        return
     1156
     1157    def sendCredentials(self, applicant, password):
     1158        """Send credentials as email.
     1159
     1160        Input is the applicant for which credentials are sent and the
     1161        password.
     1162
     1163        Returns True or False to indicate successful operation.
     1164        """
     1165        sirp_utils = getUtility(ISIRPUtils)
    11501166        username = applicant.applicant_id
    11511167        fullname = applicant.display_fullname
    11521168        subject = 'Your SIRP credentials'
    1153         msg = 'You have successfully registered for the'
     1169        msg = 'You have successfully been registered for the'
    11541170        email_to = applicant.email
    11551171        login_url = self.url(grok.getSite(), 'login')
    11561172        success = sirp_utils.sendPassword(fullname,msg,username,
    1157             pwd,login_url,email_to,subject)
    1158         if success:
    1159             self.flash('An email with your user name and password ' +
    1160                 'has been sent to %s.' % email_to)
    1161         else:
    1162             self.flash('An smtp server error occurred.')
    1163         return
     1173            password,login_url,email_to,subject)
     1174        return success
     1175
     1176class ApplicantRegistrationEmailSent(SIRPPage):
     1177    """Landing page after successful registration.
     1178    """
     1179    grok.name('registration_complete')
     1180    grok.require('waeup.Public')
     1181    grok.template('applicantregemailsent')
     1182    title = 'Registration Completed'
     1183    label = 'Your registration was successful'
     1184
     1185    def update(self, email=None):
     1186        self.email = email
     1187        return
Note: See TracChangeset for help on using the changeset viewer.