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