[5324] | 1 | ## |
---|
| 2 | ## util.py |
---|
| 3 | ## Login : <uli@pu.smp.net> |
---|
| 4 | ## Started on Thu Jul 29 09:39:51 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 | """Little helpers for applicant specific stuff. |
---|
| 23 | """ |
---|
| 24 | def get_applicant_data(reg_no, ac): |
---|
| 25 | """Validate credentials and return applicant data. |
---|
| 26 | |
---|
| 27 | Returns tuple ``(<APPLICANT_ENTRY>, <ACCESSCODE>) on |
---|
| 28 | successful validation and ``None`` else. |
---|
| 29 | |
---|
| 30 | We expect a JAMB registration number and an access code in format |
---|
| 31 | like ``PREFIX-XXX-YYYYYYYY`` where ``PREFIX`` is something like |
---|
| 32 | ``APP`` or ``PUDE``, ``XXX`` the access code series and |
---|
| 33 | ``YYYYYYYYYY`` the real accesscode number. |
---|
| 34 | """ |
---|
| 35 | site = grok.getSite() |
---|
| 36 | if reg_no not in site['applications'].keys(): |
---|
| 37 | return None |
---|
| 38 | applicant_data = site['applications'][reg_no] |
---|
| 39 | entries = site['accesscodes'].search(ac, 'pin') |
---|
| 40 | if len(entries) != 1: |
---|
| 41 | # XXX: If entries > 1 then we have a problem! |
---|
| 42 | return None |
---|
| 43 | # XXX: Maybe we have to mark reg_no as used here? |
---|
| 44 | return (applicant_data, entries[0]) |
---|