Changeset 8346 for main/waeup.kofa/trunk/src
- Timestamp:
- 4 May 2012, 20:44:48 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 1 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/tests/test_browser.py
r8311 r8346 869 869 def test_change_password_request(self): 870 870 self.browser.open('http://localhost/app/sendpw') 871 self.browser.getControl(name="form. reg_number").value = '1234'871 self.browser.getControl(name="form.identifier").value = '1234' 872 872 self.browser.getControl(name="form.email").value = 'aa@aa.ng' 873 self.browser.getControl("Get newlogin credentials").click()873 self.browser.getControl("Get login credentials").click() 874 874 self.assertTrue('No record found' in self.browser.contents) 875 875 self.applicant.email = 'aa@aa.ng' … … 877 877 notify(grok.ObjectModifiedEvent(self.applicant)) 878 878 self.browser.open('http://localhost/app/sendpw') 879 self.browser.getControl(name="form. reg_number").value = '1234'879 self.browser.getControl(name="form.identifier").value = '1234' 880 880 self.browser.getControl(name="form.email").value = 'aa@aa.ng' 881 self.browser.getControl("Get newlogin credentials").click()881 self.browser.getControl("Get login credentials").click() 882 882 self.assertTrue( 883 883 'An email with your user name and password has been sent' -
main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py
r8176 r8346 45 45 IUniversity, IFacultiesContainer, IFaculty, IFacultyAdd, 46 46 IDepartment, IDepartmentAdd, ICourse, ICourseAdd, ICertificate, 47 ICertificateAdd, ICertificateCourse, ICertificateCourseAdd) 47 ICertificateAdd, ICertificateCourse, ICertificateCourseAdd, 48 ICaptchaManager) 48 49 from waeup.kofa.browser.layout import jsaction, action, UtilityView 49 50 from waeup.kofa.browser.resources import warning, datepicker, tabs, datatable … … 54 55 ILocalRolesAssignable, DuplicationError, IConfigurationContainer, 55 56 ISessionConfiguration, ISessionConfigurationAdd, 56 IPasswordValidator, IContactForm, IKofaUtils, ICSVExporter) 57 IPasswordValidator, IContactForm, IKofaUtils, ICSVExporter, 58 IChangePassword) 57 59 from waeup.kofa.permissions import get_users_with_local_roles, get_all_roles 58 60 from waeup.kofa.students.catalog import search as searchstudents … … 1957 1959 return 1958 1960 1961 class ChangePasswordRequestPage(KofaForm): 1962 """Captcha'd page for all kind of users to request a password change. 1963 """ 1964 grok.context(IUniversity) 1965 grok.name('sendpw') 1966 grok.require('waeup.Anonymous') 1967 grok.template('sendpassword') 1968 label = _('Send me a new password') 1969 form_fields = grok.AutoFields(IChangePassword) 1970 1971 def update(self): 1972 # Handle captcha 1973 self.captcha = getUtility(ICaptchaManager).getCaptcha() 1974 self.captcha_result = self.captcha.verify(self.request) 1975 self.captcha_code = self.captcha.display(self.captcha_result.error_code) 1976 return 1977 1978 def _searchUser(self, identifier, email): 1979 # Search student 1980 cat = queryUtility(ICatalog, name='students_catalog') 1981 results = cat.searchResults( 1982 #reg_number=(identifier, identifier), 1983 email=(email,email)) 1984 for result in results: 1985 if result.student_id == identifier or \ 1986 result.reg_number == identifier or \ 1987 result.matric_number == identifier: 1988 return result 1989 # Search applicant 1990 cat = queryUtility(ICatalog, name='applicants_catalog') 1991 if cat is not None: 1992 results = cat.searchResults( 1993 #reg_number=(identifier, identifier), 1994 email=(email,email)) 1995 for result in results: 1996 if result.applicant_id == identifier or \ 1997 result.reg_number == identifier: 1998 return result 1999 # Search portal user 2000 user = grok.getSite()['users'].get(identifier, None) 2001 if user is not None and user.email == email: 2002 return user 2003 return None 2004 2005 @action(_('Get login credentials'), style='primary') 2006 def request(self, **data): 2007 if not self.captcha_result.is_valid: 2008 # Captcha will display error messages automatically. 2009 # No need to flash something. 2010 return 2011 # Search student or applicant 2012 identifier = data['identifier'] 2013 email = data['email'] 2014 user = self._searchUser(identifier, email) 2015 if user is None: 2016 self.flash(_('No record found.')) 2017 return 2018 # Change password 2019 kofa_utils = getUtility(IKofaUtils) 2020 pwd = kofa_utils.genPassword() 2021 IUserAccount(user).setPassword(pwd) 2022 # Send email with new redentials 2023 msg = _('You have successfully changed your password for the') 2024 login_url = self.url(grok.getSite(), 'login') 2025 success = kofa_utils.sendCredentials( 2026 IUserAccount(user),pwd,login_url,msg) 2027 if success: 2028 self.flash(_('An email with your user name and password ' + 2029 'has been sent to ${a}.', mapping = {'a':email})) 2030 else: 2031 self.flash(_('An smtp server error occurred.')) 2032 return -
main/waeup.kofa/trunk/src/waeup/kofa/interfaces.py
r8307 r8346 1043 1043 required = True, 1044 1044 ) 1045 1046 class IChangePassword(IKofaObject): 1047 """Interface needed for change pasword page. 1048 1049 """ 1050 identifier = schema.TextLine( 1051 title = _(u'Unique Identifier'), 1052 description = _(u'User Name, Student or Applicant Id, Matriculation or Registration Number'), 1053 required = True, 1054 readonly = False, 1055 ) 1056 1057 email = schema.ASCIILine( 1058 title = _(u'Email Address'), 1059 required = True, 1060 constraint=validate_email, 1061 ) -
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.