Changeset 8346 for main/waeup.kofa/trunk/src/waeup/kofa/browser
- Timestamp:
- 4 May 2012, 20:44:48 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/browser
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset for help on using the changeset viewer.