Changeset 7369 for main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
- Timestamp:
- 18 Dec 2011, 08:24:04 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/browser.py
r7364 r7369 26 26 from zope.catalog.interfaces import ICatalog 27 27 from zope.component import queryUtility, getUtility 28 #from hurry.query import Eq 29 #from hurry.query.query import Query 28 30 from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState 29 31 from zope.component import createObject … … 33 35 from waeup.sirp.browser import ( 34 36 SIRPPage, SIRPEditFormPage, SIRPAddFormPage, SIRPDisplayFormPage, 35 ContactAdminForm) 37 ContactAdminForm, SIRPForm) 38 from waeup.sirp.browser.interfaces import ICaptchaManager 36 39 from waeup.sirp.browser.breadcrumbs import Breadcrumb 37 40 from waeup.sirp.browser.resources import datepicker, datatable, tabs, warning … … 41 44 from waeup.sirp.interfaces import ( 42 45 ISIRPObject, IUserAccount, IExtFileStore, IPasswordValidator, IContactForm, 43 ISIRPUtils )46 ISIRPUtils, IUniversity) 44 47 from waeup.sirp.widgets.datewidget import ( 45 48 FriendlyDateWidget, FriendlyDateDisplayWidget, … … 51 54 IStudentAccommodation, IStudentClearanceEdit, IStudentStudyLevel, 52 55 ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer, 53 IStudentOnlinePayment, IBedTicket, IStudentsUtils 56 IStudentOnlinePayment, IBedTicket, IStudentsUtils, IStudentChangePassword 54 57 ) 55 58 from waeup.sirp.students.catalog import search … … 193 196 grok.context(ISIRPObject) 194 197 grok.name('setpassword') 195 grok.require('waeup. Public')198 grok.require('waeup.Anonymous') 196 199 grok.template('setpassword') 197 200 title = '' … … 1469 1472 students_utils = getUtility(IStudentsUtils) 1470 1473 acc_details = students_utils.getAccommodationDetails(student) 1474 if not acc_details: 1475 self.flash("Your data are incomplete.") 1476 self.redirect(self.url(self.context)) 1477 return 1471 1478 if not student.state in acc_details['allowed_states']: 1472 1479 self.flash("You are in the wrong registration state.") … … 2186 2193 self.redirect(self.url(self.context, u'@@edit')) 2187 2194 return 2195 2196 class ChangePasswordRequestPage(SIRPForm): 2197 """Captcha'd page for students to request a password change. 2198 """ 2199 grok.context(IUniversity) 2200 grok.name('changepw') 2201 grok.require('waeup.Anonymous') 2202 grok.template('changepw') 2203 title = 'Change Password Request' 2204 label = 'Change my password' 2205 form_fields = grok.AutoFields(IStudentChangePassword) 2206 2207 def update(self): 2208 # Handle captcha 2209 self.captcha = getUtility(ICaptchaManager).getCaptcha() 2210 self.captcha_result = self.captcha.verify(self.request) 2211 self.captcha_code = self.captcha.display(self.captcha_result.error_code) 2212 return 2213 2214 @grok.action('Send request') 2215 def request(self, **data): 2216 if not self.captcha_result.is_valid: 2217 # Captcha will display error messages automatically. 2218 # No need to flash something. 2219 return 2220 # Search student 2221 cat = queryUtility(ICatalog, name='students_catalog') 2222 reg_number = data['reg_number'] 2223 email = data['email'] 2224 results = cat.searchResults( 2225 reg_number=(reg_number, reg_number), 2226 email=(email,email)) 2227 if len(results) == 0: 2228 self.flash('No student record found.') 2229 return 2230 student = list(results)[0] 2231 # Change password 2232 sirp_utils = getUtility(ISIRPUtils) 2233 pwd = sirp_utils.genPassword() 2234 IUserAccount(student).setPassword(pwd) 2235 # Send email with new redentials 2236 username = student.student_id 2237 fullname = student.display_fullname 2238 subject = 'Your SIRP credentials' 2239 msg = 'You have successfully changed your password for the' 2240 email_to = student.email 2241 login_url = self.url(grok.getSite(), 'login') 2242 success = sirp_utils.sendPassword(fullname,msg,username, 2243 pwd,login_url,email_to,subject) 2244 if success: 2245 self.flash('An email with your user name and password ' + 2246 'has been sent to %s.' % email_to) 2247 else: 2248 self.flash('An smtp server error occurred.') 2249 return
Note: See TracChangeset for help on using the changeset viewer.