Projet

Général

Profil

Télécharger (8,79 ko) Statistiques
| Branche: | Tag: | Révision:

mandayejs / mandayejs / applications / __init__.py @ c23f4a3b

1
# mandayejs - saml reverse proxy
2
# Copyright (C) 2015  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

    
17
from __future__ import unicode_literals
18

    
19
import os
20
from importlib import import_module
21

    
22
from django.conf import settings
23
from django.conf.urls import url
24
from django.http import Http404
25
from django.core.exceptions import ImproperlyConfigured
26
from django.core.urlresolvers import resolve
27
from django.utils.text import slugify
28

    
29
from mandayejs.applications import views
30

    
31

    
32
def get_app_settings():
33
    module_name, app_settings = tuple(settings.SITE_APP.rsplit('.', 1))
34
    module = import_module(module_name)
35
    return getattr(module, app_settings)()
36

    
37

    
38
def app_web_services(request, path):
39
    app = get_app_settings()
40
    if hasattr(app, 'urlpatterns'):
41
        view, args, kwargs = resolve(request.path, urlconf=app)
42
        return view(request, *args, **kwargs)
43
    raise Http404
44

    
45

    
46
# App Settings
47
class AppSettingsMeta(type):
48

    
49
    REQUIRED_KEYS = [
50
        'SITE_LOGIN_PATH',
51
        'SITE_LOCATORS',
52
        'SITE_AUTH_CHECKER',
53
        'SITE_AUTH_COOKIE_KEYS',
54
    ]
55

    
56
    def __new__(cls, name, bases, dct):
57
        if name != 'AppSettings':
58
            if AppSettings in bases:  # Avoid checking keys for inherited classes
59

    
60
                missing_key = set(cls.REQUIRED_KEYS).difference(set(dct.keys())) or None
61
                if missing_key:
62
                    raise ImproperlyConfigured('{} is mandatory'.format(missing_key.pop()))
63

    
64
                if not set(('SITE_FORCE_REDIRECT_URL', 'SITE_FORCE_REDIRECT_LOCATOR')).intersection(set(dct.keys())):
65
                    raise ImproperlyConfigured(
66
                        'one of these settings ({}) must be defined'
67
                        .format(('SITE_FORCE_REDIRECT_URL', 'SITE_FORCE_REDIRECT_LOCATOR')))
68

    
69
                # Default form submit element
70
                if not dct.get('SITE_FORM_SUBMIT_ELEMENT', None):
71
                    dct['SITE_FORM_SUBMIT_ELEMENT'] = 'input[type=submit], button'
72

    
73
        return super(AppSettingsMeta, cls).__new__(cls, name, bases, dct)
74

    
75

    
76
class AppSettings(object):
77
    __metaclass__ = AppSettingsMeta
78

    
79
    def __getattribute__(self, name):
80
        value = getattr(settings, name, None)
81
        if value is not None:
82
            return value
83
        return super(AppSettings, self).__getattribute__(name)
84

    
85
    def get_name(self):
86
        name = getattr(settings, 'SITE_APP_NAME', None)
87
        if name:
88
            return name
89
        return type(self).__name__
90

    
91
    def get_slug(self):
92
        return slugify(type(self).__name__)
93

    
94

    
95
# Test App Settings
96
class Test(AppSettings):
97
    SITE_LOGIN_PATH = '/'
98
    SITE_LOCATORS = [
99
        {
100
            'id': '#login',
101
            'label': 'Login',
102
            'name': 'login',
103
            'kind': 'string',
104
        },
105
        {
106
            'id': '#password',
107
            'label': 'Password',
108
            'name': 'password',
109
            'kind': 'password'
110
        }
111
    ]
112
    SITE_AUTH_CHECKER = 'js/test/auth.checker.js'
113
    SITE_AUTH_COOKIE_KEYS = ['test']
114
    SITE_FORCE_REDIRECT_URL = '/whatever'
115

    
116

    
117
# Duonet App Settings
118
class Duonet(AppSettings):
119
    SITE_LOGIN_PATH = '/'
120
    SITE_LOCATORS = [
121
        {
122
            'id': '#txtNomFoyer',
123
            'label': 'Nom de famille',
124
            'name': 'txtNomFoyer',
125
            'kind': 'string',
126
            'required': True,
127
            'help': '',
128
        },
129
        {
130
            'id': '#txtDateNaissance',
131
            'label': 'Date de naissance',
132
            'name': 'txtDateNaissance',
133
            'kind': 'date',
134
            'required': True,
135
            'help': 'exemple 16/06/2008'
136
        },
137
        {
138
            'id': '#txtCode',
139
            'label': 'Mot de passe',
140
            'name': 'txtCode',
141
            'kind': 'password',
142
            'required': True,
143
            'help': ''
144
        },
145
    ]
146
    SITE_AUTH_CHECKER = 'duonet/js/auth.checker.js'
147
    SITE_AUTH_COOKIE_KEYS = [
148
        'ASP.NET_SessionId',
149
    ]
150
    SITE_APP_SCRIPTS = [
151
        'duonet/js/duonet.js',
152
    ]
153

    
154
    SITE_FORCE_REDIRECT_URL = '/Connect.aspx'
155

    
156
    SITE_FORM_SUBMIT_ELEMENT = 'input[type=submit]'
157

    
158
    SITE_LOGOUT_LOCATOR = '#lnkDisconnect'
159

    
160

    
161
# Archimed App Settings
162
class Archimed(AppSettings):
163
    SITE_LOGIN_PATH = '/'
164
    SITE_LOCATORS = [
165
        {
166
            'id': '#carte',
167
            'label': 'Identifiant',
168
            'name': 'carte',
169
            'kind': 'string',
170
            'required': True,
171
            'help': '',
172
        },
173
        {
174
            'id': '#code',
175
            'label': 'Mot de passe',
176
            'name': 'code',
177
            'kind': 'password',
178
            'required': True,
179
            'help': ''
180
        },
181
    ]
182
    SITE_AUTH_CHECKER = 'archimed/js/auth.checker.js'
183
    SITE_AUTH_COOKIE_KEYS = [
184
        'S_ARCHIMED_CRYSTAL_AUTH'
185
    ]
186

    
187
    SITE_APP_SCRIPTS = [
188
        'archimed/js/archimed.js'
189
    ]
190

    
191
    SITE_FORCE_REDIRECT_LOCATOR = '.connectBox'
192

    
193
    SITE_WS_ENDPOINT = {
194
        'account_details': '/DEFAULT/Ermes/Services/ILSClient.svc/RetrieveAccount',
195
    }
196

    
197
    urlpatterns = [
198
        url(
199
            r'account/(?P<username>\w+)/$',
200
            views.archimed_account_details,
201
            name='archimed-account-details'),
202
    ]
203

    
204
    SITE_LOGOUT_LOCATOR = '.account_logoff'
205

    
206

    
207
# Arpege App Settings
208
class Arpege(AppSettings):
209
    SITE_LOGIN_PATH = '/index.do'
210
    SITE_LOCATORS = [
211
        {
212
            'id': '#cdfmll',
213
            'label': 'Code famille',
214
            'name': 'cdfmll',
215
            'kind': 'string',
216
            'required': True,
217
            'help': '',
218
        },
219
        {
220
            'id': '#mtdpss',
221
            'label': 'Mot de passe',
222
            'name': 'mtdpss',
223
            'kind': 'password',
224
            'required': True,
225
            'help': '',
226
        }
227
    ]
228
    SITE_AUTH_CHECKER = 'arpege/js/auth.checker.js'
229
    SITE_AUTH_COOKIE_KEYS = [
230
        'JSESSIONID',
231
    ]
232

    
233
    SITE_APP_SCRIPTS = [
234
        'arpege/js/arpege.js',
235
    ]
236

    
237
    SITE_FORCE_REDIRECT_LOCATOR = '.formulaire'
238

    
239
    SITE_LOGOUT_LOCATOR = '#espace-login form input[type=submit]'
240

    
241

    
242
class Imuse(AppSettings):
243
    SITE_LOGIN_PATH = 'extranet/login/gen_index_groupe.php?nav=autre'
244

    
245
    SITE_LOCATORS = [
246
        {
247
            'id': '#INDEX_USER_ID',
248
            'label': 'Identifiant',
249
            'name': 'INDEX_USER_ID',
250
            'kind': 'string',
251
            'required': True,
252
            'help': ''
253
        },
254
        {
255
            'id': '#INDEX_USER_PWD',
256
            'label': 'Mot de passe',
257
            'name': 'INDEX_USER_PWD',
258
            'kind': 'password',
259
            'required': True,
260
            'help': ''
261
        }
262
    ]
263

    
264
    SITE_AUTH_CHECKER = 'imuse/js/auth.checker.js'
265

    
266
    SITE_AUTH_COOKIE_KEYS = [
267
        'iMuse-extranet'
268
    ]
269

    
270
    SITE_FORCE_REDIRECT_LOCATOR = '#INDEX_TBL_LOGIN'
271

    
272
    SITE_FORM_SUBMIT_ELEMENT = '#INDEX_BT_LOGIN'
273

    
274

    
275
class Sezhame(AppSettings):
276
    SITE_LOGIN_PATH = '/sezhame/page/connexion-abonne?destination=user'
277

    
278
    SITE_LOCATORS = [
279
        {
280
            'id': '#edit-user',
281
            'label': 'Numero de cqrte',
282
            'name': 'edit-user',
283
            'kind': 'string',
284
            'required': True,
285
            'help': ''
286
        },
287
        {
288
            'id': '#edit-password',
289
            'label': 'Mot de passe',
290
            'name': 'edit-password',
291
            'kind': 'password',
292
            'required': True,
293
            'help': ''
294
        }
295
    ]
296

    
297
    SITE_AUTH_CHECKER = 'sezhame/js/auth.checker.js'
298

    
299
    SITE_AUTH_COOKIE_KEYS = [
300
        'SESSf36da25307ad6240a58ddd4f4b138952',
301
        'ASPSESSIONIDQSDRASTR'
302
    ]
303

    
304
    SITE_FORCE_REDIRECT_LOCATOR = '#dk-opac15-login-form'
305

    
306

    
307
class Teamnet(AppSettings):
308
    SITE_LOGIN_PATH = '/auth/teamnetauth'
309

    
310
    SITE_LOCATORS = [
311
        {
312
            'id': '#login',
313
            'label': 'Mon identifiant',
314
            'name': 'login',
315
            'kind': 'string',
316
            'required': True,
317
            'help': ''
318
        },
319
        {
320
            'id': '#mdp',
321
            'label': 'Mon mot de passe',
322
            'name': 'mdp',
323
            'kind': 'password',
324
            'required': True,
325
            'help': ''
326
        }
327
    ]
328

    
329
    SITE_FORM_SUBMIT_ELEMENT = "input[type=submit][value='Me connecter']"
330

    
331
    SITE_AUTH_CHECKER = 'teamnet/js/auth.checker.js'
332

    
333
    SITE_AUTH_COOKIE_KEYS = [
334
        'JSESSIONID',
335
    ]
336

    
337
    SITE_FORCE_REDIRECT_LOCATOR = '#loginForm'
338

    
339
    SITE_LOGOUT_LOCATOR = ".infoUtilisateur[alt=Deconnexion]"
(1-1/2)