[5273] | 1 | ## |
---|
| 2 | ## browser.py |
---|
| 3 | ## Login : <uli@pu.smp.net> |
---|
| 4 | ## Started on Sun Jun 27 11:03:10 2010 Uli Fouquet |
---|
| 5 | ## $Id$ |
---|
| 6 | ## |
---|
| 7 | ## Copyright (C) 2010 Uli Fouquet |
---|
| 8 | ## This program is free software; you can redistribute it and/or modify |
---|
| 9 | ## it under the terms of the GNU General Public License as published by |
---|
| 10 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | ## (at your option) any later version. |
---|
| 12 | ## |
---|
| 13 | ## This program is distributed in the hope that it will be useful, |
---|
| 14 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | ## GNU General Public License for more details. |
---|
| 17 | ## |
---|
| 18 | ## You should have received a copy of the GNU General Public License |
---|
| 19 | ## along with this program; if not, write to the Free Software |
---|
| 20 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 21 | ## |
---|
| 22 | """UI components for JAMB tables. |
---|
| 23 | """ |
---|
| 24 | import grok |
---|
[5442] | 25 | from waeup.sirp.browser.pages import LoginPage |
---|
[5779] | 26 | from waeup.sirp.applicants.interfaces import IApplicantPrincipal |
---|
[5806] | 27 | from waeup.sirp.applicants import get_applicant_data |
---|
[5320] | 28 | from waeup.sirp.interfaces import IWAeUPObject |
---|
| 29 | |
---|
[5273] | 30 | |
---|
[5442] | 31 | class Login_PDE(LoginPage): |
---|
[5320] | 32 | grok.context(IWAeUPObject) |
---|
| 33 | grok.name('login_pde') |
---|
| 34 | |
---|
| 35 | title = 'PDE Login' |
---|
| 36 | pnav = 1 |
---|
| 37 | |
---|
[5453] | 38 | def update(self): |
---|
[5320] | 39 | """Validate credentials and redirect or show error. |
---|
| 40 | |
---|
[5453] | 41 | The real validation is done by an pluggable authentication |
---|
| 42 | utility (PAU). Here we only check, whether correct credentials |
---|
| 43 | were entered by looking up the principal status of the |
---|
| 44 | request: If the user authenticated successfully, we get an |
---|
| 45 | applicant principal. Otherwise we get the unauthenticated |
---|
| 46 | principal. |
---|
[5320] | 47 | """ |
---|
[5453] | 48 | formfields = ['form.ac_number', 'form.jamb_reg_no', |
---|
| 49 | 'form.ac_series', 'form.prefix',] |
---|
| 50 | |
---|
| 51 | self.reg_no = self.request.form.get('form.jamb_reg_no', '') |
---|
| 52 | self.ac_series = self.request.form.get('form.ac_series', '') |
---|
| 53 | self.ac_number = self.request.form.get('form.ac_number', '') |
---|
| 54 | |
---|
| 55 | for required_field in formfields: |
---|
| 56 | if required_field not in self.request.form.keys(): |
---|
[5320] | 57 | return |
---|
[5453] | 58 | self.reg_no = self.request.form['form.jamb_reg_no'] |
---|
| 59 | self.ac_series = self.request.form['form.ac_series'] |
---|
| 60 | self.ac_number = self.request.form['form.ac_number'] |
---|
| 61 | principal = self.request.principal |
---|
| 62 | if not IApplicantPrincipal.providedBy(principal): |
---|
| 63 | self.flash('You entered invalid credentials') |
---|
[5320] | 64 | return |
---|
[5453] | 65 | if hasattr(principal, 'reg_no'): |
---|
| 66 | if not principal.reg_no is None: |
---|
| 67 | |
---|
| 68 | site = grok.getSite() |
---|
| 69 | applications = site['applications'] |
---|
| 70 | application = applications[principal.reg_no] |
---|
| 71 | self.redirect(self.url(application, '@@edit')) |
---|
[5320] | 72 | return |
---|
| 73 | |
---|
| 74 | def getCurrentSession(self): |
---|
| 75 | """Get the current session. |
---|
| 76 | |
---|
| 77 | XXX: This should be computed or retrieved from elsewhere. |
---|
[5453] | 78 | |
---|
| 79 | `session` here means an academic session, not a browser |
---|
| 80 | session. |
---|
[5320] | 81 | """ |
---|
| 82 | return u'2010/2011' |
---|
| 83 | |
---|
| 84 | def getDeadline(self): |
---|
| 85 | """Get application submission deadline. |
---|
| 86 | |
---|
| 87 | XXX: This should be computed or retrieved from elsewhere. |
---|
| 88 | """ |
---|
| 89 | return u"""Application submission deadline is at Midnight on Friday, |
---|
| 90 | 01. October 2010. No application will be treated |
---|
| 91 | after the deadline.""" |
---|
| 92 | |
---|
| 93 | def getApplicantData(self, reg_no, ac): |
---|
| 94 | """Validate credentials and return applicant data. |
---|
| 95 | |
---|
| 96 | Returns tuple ``(<APPLICANT_ENTRY>, <ACCESSCODE>) on |
---|
| 97 | successful validation and ``None`` else. |
---|
| 98 | |
---|
| 99 | We expect a JAMB registration number and an access code in |
---|
| 100 | format ``PUDE-XXX-XXXXXXXXXX``. |
---|
[5325] | 101 | |
---|
| 102 | See |
---|
| 103 | :func:`waeup.sirp.jambtables.util.get_applicant_data` |
---|
| 104 | for details. |
---|
[5320] | 105 | """ |
---|
[5325] | 106 | return get_applicant_data(reg_no, ac) |
---|