- Timestamp:
- 17 Dec 2011, 18:47:57 (13 years ago)
- 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 51 51 from waeup.sirp.interfaces import ( 52 52 ISIRPObject, ILocalRolesAssignable, IExtFileStore, 53 IFileStoreNameChooser, IPasswordValidator, IUserAccount )53 IFileStoreNameChooser, IPasswordValidator, IUserAccount, ISIRPUtils) 54 54 from waeup.sirp.permissions import get_users_with_local_roles 55 55 from waeup.sirp.students.viewlets import PrimaryStudentNavTab … … 1089 1089 return image 1090 1090 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 = label1100 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_id1105 self.login_url = self.url(grok.getSite(), 'login')1106 1107 1091 class ApplicantRegistrationPage(SIRPAddFormPage): 1108 1092 """Captcha'd registration page for applicants. … … 1131 1115 # No need to flash something. 1132 1116 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 1146 1119 applicant = createObject('waeup.Applicant') 1147 1120 self.applyData(applicant, **data) 1148 1121 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 38 38 </tr> 39 39 </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"> 53 41 <td i18n:translate=""> 54 42 Please solve the captcha<br /> 55 to prevent misuse of this service 43 to prevent misuse of this service: 56 44 </td> 57 45 <td> -
main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py
r7358 r7365 186 186 d = {} 187 187 d['error'] = u'' 188 site_conf oguration = grok.getSite()['configuration']189 d['booking_session'] = site_conf oguration.accommodation_session190 d['allowed_states'] = site_conf oguration.accommodation_states188 site_configuration = grok.getSite()['configuration'] 189 d['booking_session'] = site_configuration.accommodation_session 190 d['allowed_states'] = site_configuration.accommodation_states 191 191 # Determine bed type 192 192 studycourse = student['studycourse'] -
main/waeup.sirp/trunk/src/waeup/sirp/utils/utils.py
r7364 r7365 20 20 import grok 21 21 import smtplib 22 from string import capwords 22 import string 23 from random import SystemRandom as r 23 24 from email.mime.text import MIMEText 24 25 from waeup.sirp.interfaces import ISIRPUtils … … 58 59 # We do not necessarily have the middlename attribute 59 60 if middlename: 60 return capwords('%s %s %s' % (firstname, middlename, lastname)) 61 return string.capwords( 62 '%s %s %s' % (firstname, middlename, lastname)) 61 63 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 78 Student Registration and Information Portal of 79 %s 80 81 Your user name is: %s 82 Your password is: %s 83 Login page: %s 84 85 Please remember your user name and keep 86 your password secret! 87 88 Regards 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.