0002-misc-move-AppConfing-in-apps-module-69739.patch
setup.py | ||
---|---|---|
100 | 100 |
], |
101 | 101 |
entry_points={ |
102 | 102 |
'authentic2.plugin': [ |
103 |
'authentic2-auth-fedict = authentic2_auth_fedict:Plugin', |
|
103 |
'authentic2-auth-fedict = authentic2_auth_fedict.apps:Plugin',
|
|
104 | 104 |
], |
105 | 105 |
}, |
106 | 106 |
cmdclass={ |
src/authentic2_auth_fedict/__init__.py | ||
---|---|---|
1 | 1 |
# authentic2_auth_fedict - Fedict authentication for Authentic |
2 |
# Copyright (C) 2016 Entr'ouvert |
|
2 |
# Copyright (C) 2016-2022 Entr'ouvert
|
|
3 | 3 |
# |
4 | 4 |
# This program is free software: you can redistribute it and/or modify it |
5 | 5 |
# under the terms of the GNU Affero General Public License as published |
... | ... | |
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import json |
|
17 |
default_app_config = '%s.apps.AppConfig' % __name__ |
|
18 | 18 | |
19 |
import django.apps |
|
20 |
from django.contrib.auth.signals import user_logged_in |
|
21 |
from django.utils.translation import ugettext_lazy as _ |
|
22 | ||
23 | ||
24 |
class AppConfig(django.apps.AppConfig): |
|
25 |
name = 'authentic2_auth_fedict' |
|
26 | ||
27 |
def ready(self): |
|
28 |
from . import signals |
|
29 | ||
30 |
user_logged_in.connect(signals.on_user_logged_in) |
|
31 | ||
32 |
def a2_hook_event(self, name, **kwargs): |
|
33 |
if name == 'registration': |
|
34 |
if kwargs.get('authentication_method') == 'fedict': |
|
35 |
user = kwargs.get('user') |
|
36 |
user.backend = 'authentic2_auth_fedict.backends.FedictBackend' |
|
37 | ||
38 | ||
39 |
default_app_config = 'authentic2_auth_fedict.AppConfig' |
|
40 | ||
41 | ||
42 |
class Plugin: |
|
43 |
def get_before_urls(self): |
|
44 |
from . import urls |
|
45 | ||
46 |
return urls.urlpatterns |
|
47 | ||
48 |
def get_apps(self): |
|
49 |
return ['mellon', __name__] |
|
50 | ||
51 |
def get_authentication_backends(self): |
|
52 |
return ['authentic2_auth_fedict.backends.FedictBackend'] |
|
53 | ||
54 |
def redirect_logout_list(self, request, next_url=None): |
|
55 |
from mellon.views import logout |
|
56 | ||
57 |
if 'mellon_session' in request.session: |
|
58 |
response = logout(request) |
|
59 |
if 'Location' in response: |
|
60 |
return [response['Location']] |
|
61 |
return [] |
|
62 | ||
63 |
def registration_form_prefill(self, request): |
|
64 |
if request.token.get('first_name'): |
|
65 |
return [ |
|
66 |
{ |
|
67 |
'first_name': [request.token.get('first_name')], |
|
68 |
'last_name': [request.token.get('last_name')], |
|
69 |
} |
|
70 |
] |
|
71 |
else: |
|
72 |
return [{'first_name': [], 'last_name': []}] |
|
73 | ||
74 |
def attribute_kinds(self): |
|
75 |
from . import fields |
|
76 | ||
77 |
def attribute_json_loads(x): |
|
78 |
if not x: |
|
79 |
return x |
|
80 |
try: |
|
81 |
return json.loads(x) |
|
82 |
except json.JSONDecodeError: |
|
83 |
# "compatibility" with native date/phone kinds |
|
84 |
return x |
|
85 | ||
86 |
return [ |
|
87 |
{ |
|
88 |
'label': _('National Register Number'), |
|
89 |
'name': 'nrn', |
|
90 |
'serialize': json.dumps, |
|
91 |
'deserialize': attribute_json_loads, |
|
92 |
'field_class': fields.NrnField, |
|
93 |
}, |
|
94 |
{ |
|
95 |
'label': _('Date'), |
|
96 |
'serialize': json.dumps, |
|
97 |
'deserialize': attribute_json_loads, |
|
98 |
'name': 'date', |
|
99 |
'field_class': fields.DateField, |
|
100 |
}, |
|
101 |
{ |
|
102 |
'label': _('Date'), |
|
103 |
'serialize': json.dumps, |
|
104 |
'deserialize': attribute_json_loads, |
|
105 |
'name': 'fedict_date', |
|
106 |
'field_class': fields.DateField, |
|
107 |
}, |
|
108 |
{ |
|
109 |
'label': _('Street'), |
|
110 |
'serialize': json.dumps, |
|
111 |
'deserialize': attribute_json_loads, |
|
112 |
'name': 'street', |
|
113 |
'field_class': fields.StreetField, |
|
114 |
}, |
|
115 |
{ |
|
116 |
'label': _('House number'), |
|
117 |
'serialize': json.dumps, |
|
118 |
'deserialize': attribute_json_loads, |
|
119 |
'name': 'num_house', |
|
120 |
'field_class': fields.NumHouseField, |
|
121 |
}, |
|
122 |
{ |
|
123 |
'label': _('Phone number'), |
|
124 |
'serialize': json.dumps, |
|
125 |
'deserialize': attribute_json_loads, |
|
126 |
'name': 'phone', |
|
127 |
'field_class': fields.NumPhoneField, |
|
128 |
}, |
|
129 |
{ |
|
130 |
'label': _('Phone number'), |
|
131 |
'serialize': json.dumps, |
|
132 |
'deserialize': attribute_json_loads, |
|
133 |
'name': 'fedict_phone', |
|
134 |
'field_class': fields.NumPhoneField, |
|
135 |
}, |
|
136 |
{ |
|
137 |
'label': _('Country'), |
|
138 |
'serialize': json.dumps, |
|
139 |
'deserialize': attribute_json_loads, |
|
140 |
'name': 'country', |
|
141 |
'field_class': fields.CountryField, |
|
142 |
}, |
|
143 |
] |
src/authentic2_auth_fedict/apps.py | ||
---|---|---|
1 |
# authentic2_auth_fedict - Fedict authentication for Authentic |
|
2 |
# Copyright (C) 2016-2022 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 |
import json |
|
18 | ||
19 |
import django.apps |
|
20 |
from django.contrib.auth.signals import user_logged_in |
|
21 |
from django.utils.translation import ugettext_lazy as _ |
|
22 | ||
23 | ||
24 |
class AppConfig(django.apps.AppConfig): |
|
25 |
name = 'authentic2_auth_fedict' |
|
26 | ||
27 |
def ready(self): |
|
28 |
from . import signals |
|
29 | ||
30 |
user_logged_in.connect(signals.on_user_logged_in) |
|
31 | ||
32 |
def a2_hook_event(self, name, **kwargs): |
|
33 |
if name == 'registration': |
|
34 |
if kwargs.get('authentication_method') == 'fedict': |
|
35 |
user = kwargs.get('user') |
|
36 |
user.backend = 'authentic2_auth_fedict.backends.FedictBackend' |
|
37 | ||
38 | ||
39 |
class Plugin: |
|
40 |
def get_before_urls(self): |
|
41 |
from . import urls |
|
42 | ||
43 |
return urls.urlpatterns |
|
44 | ||
45 |
def get_apps(self): |
|
46 |
return ['mellon', 'authentic2_auth_fedict'] |
|
47 | ||
48 |
def get_authentication_backends(self): |
|
49 |
return ['authentic2_auth_fedict.backends.FedictBackend'] |
|
50 | ||
51 |
def redirect_logout_list(self, request, next_url=None): |
|
52 |
from mellon.views import logout |
|
53 | ||
54 |
if 'mellon_session' in request.session: |
|
55 |
response = logout(request) |
|
56 |
if 'Location' in response: |
|
57 |
return [response['Location']] |
|
58 |
return [] |
|
59 | ||
60 |
def registration_form_prefill(self, request): |
|
61 |
if request.token.get('first_name'): |
|
62 |
return [ |
|
63 |
{ |
|
64 |
'first_name': [request.token.get('first_name')], |
|
65 |
'last_name': [request.token.get('last_name')], |
|
66 |
} |
|
67 |
] |
|
68 |
else: |
|
69 |
return [{'first_name': [], 'last_name': []}] |
|
70 | ||
71 |
def attribute_kinds(self): |
|
72 |
from . import fields |
|
73 | ||
74 |
def attribute_json_loads(x): |
|
75 |
if not x: |
|
76 |
return x |
|
77 |
try: |
|
78 |
return json.loads(x) |
|
79 |
except json.JSONDecodeError: |
|
80 |
# "compatibility" with native date/phone kinds |
|
81 |
return x |
|
82 | ||
83 |
return [ |
|
84 |
{ |
|
85 |
'label': _('National Register Number'), |
|
86 |
'name': 'nrn', |
|
87 |
'serialize': json.dumps, |
|
88 |
'deserialize': attribute_json_loads, |
|
89 |
'field_class': fields.NrnField, |
|
90 |
}, |
|
91 |
{ |
|
92 |
'label': _('Date'), |
|
93 |
'serialize': json.dumps, |
|
94 |
'deserialize': attribute_json_loads, |
|
95 |
'name': 'date', |
|
96 |
'field_class': fields.DateField, |
|
97 |
}, |
|
98 |
{ |
|
99 |
'label': _('Date'), |
|
100 |
'serialize': json.dumps, |
|
101 |
'deserialize': attribute_json_loads, |
|
102 |
'name': 'fedict_date', |
|
103 |
'field_class': fields.DateField, |
|
104 |
}, |
|
105 |
{ |
|
106 |
'label': _('Street'), |
|
107 |
'serialize': json.dumps, |
|
108 |
'deserialize': attribute_json_loads, |
|
109 |
'name': 'street', |
|
110 |
'field_class': fields.StreetField, |
|
111 |
}, |
|
112 |
{ |
|
113 |
'label': _('House number'), |
|
114 |
'serialize': json.dumps, |
|
115 |
'deserialize': attribute_json_loads, |
|
116 |
'name': 'num_house', |
|
117 |
'field_class': fields.NumHouseField, |
|
118 |
}, |
|
119 |
{ |
|
120 |
'label': _('Phone number'), |
|
121 |
'serialize': json.dumps, |
|
122 |
'deserialize': attribute_json_loads, |
|
123 |
'name': 'phone', |
|
124 |
'field_class': fields.NumPhoneField, |
|
125 |
}, |
|
126 |
{ |
|
127 |
'label': _('Phone number'), |
|
128 |
'serialize': json.dumps, |
|
129 |
'deserialize': attribute_json_loads, |
|
130 |
'name': 'fedict_phone', |
|
131 |
'field_class': fields.NumPhoneField, |
|
132 |
}, |
|
133 |
{ |
|
134 |
'label': _('Country'), |
|
135 |
'serialize': json.dumps, |
|
136 |
'deserialize': attribute_json_loads, |
|
137 |
'name': 'country', |
|
138 |
'field_class': fields.CountryField, |
|
139 |
}, |
|
140 |
] |
|
0 |
- |