- Timestamp:
- 20 Dec 2011, 07:39:33 (13 years ago)
- Location:
- main/waeup.sirp/trunk/src/waeup/sirp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser.py
r7392 r7399 1059 1059 self.applyData(applicant, **data) 1060 1060 self.context.addApplicant(applicant) 1061 password = getUtility(ISIRPUtils).genPassword() 1061 sirp_utils = getUtility(ISIRPUtils) 1062 password = sirp_utils.genPassword() 1062 1063 IUserAccount(applicant).setPassword(password) 1063 1064 # Send email with credentials 1064 if self.sendCredentials(applicant, password): 1065 login_url = self.url(grok.getSite(), 'login') 1066 if sirp_utils.sendCredentials(applicant, password, login_url): 1065 1067 self.redirect(self.url(self.context, 'registration_complete', 1066 1068 data = dict(email=applicant.email))) … … 1069 1071 self.flash('Email could not been sent. Please retry later.') 1070 1072 return 1071 1072 def sendCredentials(self, applicant, password):1073 """Send credentials as email.1074 1075 Input is the applicant for which credentials are sent and the1076 password.1077 1078 Returns True or False to indicate successful operation.1079 """1080 sirp_utils = getUtility(ISIRPUtils)1081 username = applicant.applicant_id1082 fullname = applicant.display_fullname1083 subject = 'Your SIRP credentials'1084 msg = 'You have successfully been registered for the'1085 email_to = applicant.email1086 login_url = self.url(grok.getSite(), 'login')1087 success = sirp_utils.sendPassword(fullname,msg,username,1088 password,login_url,email_to,subject)1089 return success1090 1073 1091 1074 class ApplicantRegistrationEmailSent(SIRPPage): -
main/waeup.sirp/trunk/src/waeup/sirp/applicants/browser_templates/applicantregemailsent.pt
r7379 r7399 6 6 <p> 7 7 An email with your user name and password 8 has been sent to <span tal:replace="view/email">user@foo.baz</span> 8 has been sent to <span tal:replace="view/email">user@foo.baz</span>. 9 9 </p> 10 10 <p> … … 12 12 </p> 13 13 <p> 14 Thanks for using SIRP. 14 Thanks for using SIRP! 15 </p> 15 16 </div> -
main/waeup.sirp/trunk/src/waeup/sirp/utils/utils.py
r7382 r7399 27 27 from email.Header import Header 28 28 from email.Utils import parseaddr, formataddr 29 30 def send_mail(from_name,from_email,rcpt_name,rcpt_email,subject,body,config): 31 32 header_charset = 'ISO-8859-1' 33 from_ = '%s <%s>' % (from_name,from_email) 34 to_ = '%s <%s>' % (rcpt_name,rcpt_email) 35 from_name, from_addr = parseaddr(from_) 36 rcpt_name, rcpt_addr = parseaddr(to_) 37 from_name = str(Header(unicode(from_name), header_charset)) 38 rcpt_name = str(Header(unicode(rcpt_name), header_charset)) 39 from_addr = from_addr.encode('ascii') 40 rpct_addr = rcpt_addr.encode('ascii') 41 42 for body_charset in ['US-ASCII', 'ISO-8859-1', 'UTF-8']: 43 try: 44 body.encode(body_charset) 45 except UnicodeError: 46 print "FAILED: ", body_charset, text 47 pass 48 else: 49 break 50 51 msg = MIMEText(body.encode(body_charset), 'plain', body_charset) 52 msg['From'] = formataddr((from_name, from_addr)) 53 msg['To'] = formataddr((rcpt_name, rcpt_addr)) 54 msg['Subject'] = Header(unicode(subject), header_charset) 55 server = smtplib.SMTP(config.smtp_server) 56 if config.smtp_requires_login: 57 server.login(config.smtp_username,config.smtp_password) 58 try: 59 server.sendmail(from_email,rcpt_email,msg.as_string()) 60 except Exception, e: 61 # XXX: log error message 62 return False 63 server.quit() 64 return True 29 65 30 66 … … 72 108 return ''.join([r().choice(chars) for i in range(length)]) 73 109 74 def sendPassword(self,fullname,msg,username,password,login_url, 75 email_to,subject): 76 """Send an email with user credentials. 110 111 def sendCredentials(self, applicant, password, login_url): 112 """Send credentials as email. 113 114 Input is the applicant for which credentials are sent and the 115 password. 116 117 Returns True or False to indicate successful operation. 77 118 78 119 XXX: While this method is unicode-proof (i.e. it can handle … … 81 122 reorganization of SMPT-related code is needed here. 82 123 """ 83 config = grok.getSite()['configuration'] 84 header_charset = 'ISO-8859-1' 124 username = applicant.applicant_id 125 subject = 'Your SIRP credentials' 126 msg = 'You have successfully been registered for the' 85 127 text = """Dear %s, 86 128 … … 100 142 Regards 101 143 """ 102 from_ = '%s <%s>' % (config.name_admin,config.email_admin) 103 from_name, from_addr = parseaddr(from_) 104 rcpt_name, rcpt_addr = parseaddr(email_to) 105 from_name = str(Header(unicode(from_name), header_charset)) 106 rcpt_name = str(Header(unicode(rcpt_name), header_charset)) 107 from_addr = from_addr.encode('ascii') 108 rpct_addr = rcpt_addr.encode('ascii') 144 config = grok.getSite()['configuration'] 145 from_name = config.name_admin 146 from_email = config.email_admin 147 rcpt_name = applicant.display_fullname 148 rcpt_email = applicant.email 149 body = text % ( 150 rcpt_name, msg,config.name,username,password,login_url) 151 return send_mail( 152 from_name,from_email,rcpt_name,rcpt_email,subject,body,config) 109 153 110 body = text % (111 fullname, msg,config.name,username,password,login_url)112 for body_charset in ['US-ASCII', 'ISO-8859-1', 'UTF-8']:113 try:114 body.encode(body_charset)115 except UnicodeError:116 print "FAILED: ", body_charset, text117 pass118 else:119 break120 154 121 msg = MIMEText(body.encode(body_charset), 'plain', body_charset) 122 msg['From'] = formataddr((from_name, from_addr)) 123 msg['To'] = formataddr((rcpt_name, rcpt_addr)) 124 msg['Subject'] = Header(unicode(subject), header_charset) 125 server = smtplib.SMTP(config.smtp_server) 126 if config.smtp_requires_login: 127 server.login(config.smtp_username,config.smtp_password) 128 try: 129 server.sendmail(config.email_admin,email_to,msg.as_string()) 130 except Exception, e: 131 # XXX: log error message 132 return False 133 server.quit() 134 return True 155
Note: See TracChangeset for help on using the changeset viewer.