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 |
---|
25 | from waeup.sirp.browser.pages import LoginPage |
---|
26 | from waeup.sirp.applicants.interfaces import IApplicantPrincipal |
---|
27 | from waeup.sirp.applicants.jambtables.util import get_applicant_data |
---|
28 | from waeup.sirp.interfaces import IWAeUPObject |
---|
29 | |
---|
30 | |
---|
31 | class Login_PDE(LoginPage): |
---|
32 | grok.context(IWAeUPObject) |
---|
33 | grok.name('login_pde') |
---|
34 | |
---|
35 | title = 'PDE Login' |
---|
36 | pnav = 1 |
---|
37 | |
---|
38 | def update(self): |
---|
39 | """Validate credentials and redirect or show error. |
---|
40 | |
---|
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. |
---|
47 | """ |
---|
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(): |
---|
57 | return |
---|
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') |
---|
64 | return |
---|
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')) |
---|
72 | return |
---|
73 | |
---|
74 | def getCurrentSession(self): |
---|
75 | """Get the current session. |
---|
76 | |
---|
77 | XXX: This should be computed or retrieved from elsewhere. |
---|
78 | |
---|
79 | `session` here means an academic session, not a browser |
---|
80 | session. |
---|
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``. |
---|
101 | |
---|
102 | See |
---|
103 | :func:`waeup.sirp.jambtables.util.get_applicant_data` |
---|
104 | for details. |
---|
105 | """ |
---|
106 | return get_applicant_data(reg_no, ac) |
---|