1 | ## $Id: webservices.py 12110 2014-12-02 06:43:10Z henrik $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2013 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | import grok |
---|
19 | from hurry.query.query import Query |
---|
20 | from hurry.query import Eq |
---|
21 | from zope.component import getUtility |
---|
22 | from zope.pluggableauth.interfaces import IAuthenticatorPlugin |
---|
23 | from waeup.kofa.interfaces import IUniversity |
---|
24 | |
---|
25 | |
---|
26 | class ApplicantsXMLRPC(grok.XMLRPC): |
---|
27 | """Applicant related XMLRPC webservices. |
---|
28 | |
---|
29 | Please note, that XMLRPC does not support real keyword arguments |
---|
30 | but positional arguments only. |
---|
31 | """ |
---|
32 | grok.context(IUniversity) |
---|
33 | |
---|
34 | @grok.require('waeup.xmlrpc') |
---|
35 | def check_applicant_credentials(self, username, password): |
---|
36 | """Returns applicant data if username and password are valid, |
---|
37 | None else. |
---|
38 | |
---|
39 | We only query the applicants authenticator plugin in order not |
---|
40 | to mix up with other credentials (admins, staff, etc.). |
---|
41 | |
---|
42 | All additional checks performed by usual applicant |
---|
43 | authentication apply. |
---|
44 | |
---|
45 | This method can be used by CAS to authentify applicants for |
---|
46 | external systems like moodle. |
---|
47 | """ |
---|
48 | auth = getUtility(IAuthenticatorPlugin, name='applicants') |
---|
49 | creds = dict(login=username, password=password) |
---|
50 | principal = auth.authenticateCredentials(creds) |
---|
51 | if principal is None: |
---|
52 | return None |
---|
53 | return dict(email=principal.email, id=principal.id, |
---|
54 | type=principal.user_type, |
---|
55 | description=principal.description) |
---|
56 | |
---|
57 | @grok.require('waeup.xmlrpc') |
---|
58 | def get_applicant_moodle_data(self, identifier=None): |
---|
59 | """Returns applicant data to update user data and enroll user |
---|
60 | in Moodle courses. |
---|
61 | |
---|
62 | """ |
---|
63 | results = Query().searchResults( |
---|
64 | Eq(('applicants_catalog', 'applicant_id'), identifier)) |
---|
65 | if not results: |
---|
66 | return None |
---|
67 | applicant = list(results)[0] |
---|
68 | return dict(email=applicant.email, |
---|
69 | firstname=applicant.firstname, |
---|
70 | lastname=applicant.lastname, |
---|
71 | ) |
---|