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.

Location:
main/waeup.sirp/trunk/src/waeup/sirp
Files:
1 deleted
4 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
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser_templates/applicantregister.pt

    r7361 r7365  
    3838        </tr>
    3939      </tal:block>
    40       <tr>
    41         <td class="label"><label i18n:translate="">Password:</label></td>
    42         <td>
    43           <input name="password" type="password"  />
    44         </td>
    45       </tr>
    46       <tr>
    47         <td class="label"><label i18n:translate="">Retype password:</label></td>
    48         <td>
    49           <input name="control_password" type="password" />
    50         </td>
    51       </tr>
    52       <tr>
     40      <tr tal:condition="view/captcha_code">
    5341        <td i18n:translate="">
    5442          Please solve the captcha<br />
    55           to prevent misuse of this service
     43          to prevent misuse of this service:
    5644        </td>
    5745        <td>
  • main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py

    r7358 r7365  
    186186        d = {}
    187187        d['error'] = u''
    188         site_confoguration = grok.getSite()['configuration']
    189         d['booking_session'] = site_confoguration.accommodation_session
    190         d['allowed_states'] = site_confoguration.accommodation_states
     188        site_configuration = grok.getSite()['configuration']
     189        d['booking_session'] = site_configuration.accommodation_session
     190        d['allowed_states'] = site_configuration.accommodation_states
    191191        # Determine bed type
    192192        studycourse = student['studycourse']
  • main/waeup.sirp/trunk/src/waeup/sirp/utils/utils.py

    r7364 r7365  
    2020import grok
    2121import smtplib
    22 from string import capwords
     22import string
     23from random import SystemRandom as r
    2324from email.mime.text import MIMEText
    2425from waeup.sirp.interfaces import ISIRPUtils
     
    5859        # We do not necessarily have the middlename attribute
    5960        if middlename:
    60             return capwords('%s %s %s' % (firstname, middlename, lastname))
     61            return string.capwords(
     62                '%s %s %s' % (firstname, middlename, lastname))
    6163        else:
    62             return capwords('%s %s' % (firstname, lastname))
     64            return string.capwords(
     65                '%s %s' % (firstname, lastname))
     66
     67    def genPassword(self, length=8, chars=string.letters + string.digits):
     68        return ''.join([r().choice(chars) for i in range(length)])
     69
     70    def sendPassword(self,fullname,msg,username,password,login_url,
     71                 email_to,subject):
     72        """Send an email with user credentials.
     73        """
     74        config = grok.getSite()['configuration']
     75        text = """Dear %s,
     76
     77%s
     78Student Registration and Information Portal of
     79%s
     80
     81Your user name is: %s
     82Your password is: %s
     83Login page: %s
     84
     85Please remember your user name and keep
     86your password secret!
     87
     88Regards
     89"""
     90        msg = MIMEText(text % (fullname,msg,config.name,username,password,login_url))
     91        msg['From'] = '%s <%s>' % (config.name_admin,config.email_admin)
     92        msg['To'] = email_to
     93        msg['Subject'] = subject
     94        server = smtplib.SMTP(config.smtp_server)
     95        if config.smtp_requires_login:
     96            server.login(config.smtp_username,config.smtp_password)
     97        try:
     98            server.sendmail(config.email_admin,email_to,msg.as_string())
     99        except:
     100            return False
     101        server.quit()
     102        return True
     103
Note: See TracChangeset for help on using the changeset viewer.