Changeset 8346 for main/waeup.kofa/trunk/src/waeup/kofa/students
- Timestamp:
- 4 May 2012, 20:44:48 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/students
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/students/browser.py
r8325 r8346 37 37 KofaPage, KofaEditFormPage, KofaAddFormPage, KofaDisplayFormPage, 38 38 ContactAdminForm, KofaForm, NullValidator) 39 from waeup.kofa.browser.interfaces import ICaptchaManager40 39 from waeup.kofa.browser.breadcrumbs import Breadcrumb 41 40 from waeup.kofa.browser.resources import datepicker, datatable, tabs, warning … … 55 54 IStudentAccommodation, IStudentStudyLevel, 56 55 ICourseTicket, ICourseTicketAdd, IStudentPaymentsContainer, 57 IStudentOnlinePayment, IBedTicket, IStudentsUtils , IStudentChangePassword56 IStudentOnlinePayment, IBedTicket, IStudentsUtils 58 57 ) 59 58 from waeup.kofa.students.catalog import search … … 1907 1906 return 1908 1907 1909 class ChangePasswordRequestPage(KofaForm):1910 """Captcha'd page for students to request a password change.1911 """1912 grok.context(IUniversity)1913 grok.name('sendpw')1914 grok.require('waeup.Anonymous')1915 grok.template('sendpassword')1916 label = _('Send me a new password')1917 form_fields = grok.AutoFields(IStudentChangePassword)1918 1919 def update(self):1920 # Handle captcha1921 self.captcha = getUtility(ICaptchaManager).getCaptcha()1922 self.captcha_result = self.captcha.verify(self.request)1923 self.captcha_code = self.captcha.display(self.captcha_result.error_code)1924 return1925 1926 @action(_('Get new login credentials'), style='primary')1927 def request(self, **data):1928 if not self.captcha_result.is_valid:1929 # Captcha will display error messages automatically.1930 # No need to flash something.1931 return1932 # Search student or applicant1933 reg_number = data['reg_number']1934 email = data['email']1935 cat = queryUtility(ICatalog, name='students_catalog')1936 results = cat.searchResults(1937 reg_number=(reg_number, reg_number),1938 email=(email,email))1939 if len(results) == 0:1940 # Try also the applicants_catalog if no student record was found.1941 cat = queryUtility(ICatalog, name='applicants_catalog')1942 if cat is None:1943 self.flash(_('Application package not installed.'))1944 return1945 results = cat.searchResults(1946 reg_number=(reg_number, reg_number),1947 email=(email,email))1948 if len(results) == 0:1949 self.flash(_('No record found.'))1950 return1951 student = list(results)[0]1952 # Change password1953 kofa_utils = getUtility(IKofaUtils)1954 pwd = kofa_utils.genPassword()1955 IUserAccount(student).setPassword(pwd)1956 # Send email with new redentials1957 msg = _('You have successfully changed your password for the')1958 login_url = self.url(grok.getSite(), 'login')1959 success = kofa_utils.sendCredentials(1960 IUserAccount(student),pwd,login_url,msg)1961 if success:1962 self.flash(_('An email with your user name and password ' +1963 'has been sent to ${a}.', mapping = {'a':email}))1964 else:1965 self.flash(_('An smtp server error occurred.'))1966 return1967 1908 1968 1909 class SetPasswordPage(KofaPage): -
main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py
r8268 r8346 510 510 IStudentOnlinePayment['p_level'].order = IStudentOnlinePayment[ 511 511 'p_session'].order 512 513 514 class IStudentChangePassword(IKofaObject):515 """Interface needed for change pasword page.516 517 """518 reg_number = schema.TextLine(519 title = _(u'Registration Number'),520 required = True,521 readonly = False,522 )523 524 email = schema.ASCIILine(525 title = _(u'Email Address'),526 required = True,527 constraint=validate_email,528 ) -
main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
r8322 r8346 1695 1695 def test_change_password_request(self): 1696 1696 self.browser.open('http://localhost/app/sendpw') 1697 self.browser.getControl(name="form. reg_number").value = '123'1697 self.browser.getControl(name="form.identifier").value = '123' 1698 1698 self.browser.getControl(name="form.email").value = 'aa@aa.ng' 1699 self.browser.getControl("Get newlogin credentials").click()1699 self.browser.getControl("Get login credentials").click() 1700 1700 self.assertTrue('An email with' in self.browser.contents) 1701 1701
Note: See TracChangeset for help on using the changeset viewer.