5 |
5 |
import ckan.plugins.toolkit as toolkit
|
6 |
6 |
from ckan.common import session, c, request, response
|
7 |
7 |
from ckan import model
|
|
8 |
from ckan.logic.action.create import user_create, member_create
|
8 |
9 |
import ckan.lib.base as base
|
9 |
10 |
|
10 |
11 |
from pylons import config
|
... | ... | |
134 |
135 |
locale = None
|
135 |
136 |
log.info('Received userinfo: %s' % userinfo)
|
136 |
137 |
|
137 |
|
if 'sub' in userinfo:
|
|
138 |
if 'locale' in userinfo:
|
138 |
139 |
locale = userinfo.get('locale', '')
|
139 |
140 |
if '-' in locale:
|
140 |
141 |
locale, country = locale.split('-')
|
141 |
142 |
|
|
143 |
org_url = str(toolkit.url_for(host=request.host,
|
|
144 |
controller="organization",
|
|
145 |
action='read',
|
|
146 |
id=g.name,
|
|
147 |
locale=locale,
|
|
148 |
qualified=True))
|
|
149 |
if 'sub' in userinfo:
|
|
150 |
|
142 |
151 |
userobj = model.User.get(userinfo['sub'])
|
|
152 |
if not userobj:
|
|
153 |
user_dict = {'id': userinfo['sub'],
|
|
154 |
'name': userinfo['sub'].replace('-', ''),
|
|
155 |
'email': userinfo['email'],
|
|
156 |
'password': userinfo['sub']
|
|
157 |
}
|
|
158 |
context = {'ignore_auth': True, 'model': model,
|
|
159 |
'session': model.Session}
|
|
160 |
user_create(context, user_dict)
|
|
161 |
userobj = model.User.get(userinfo['sub'])
|
|
162 |
if client.app_admin or client.app_user:
|
|
163 |
member_dict = {
|
|
164 |
'id': g.id,
|
|
165 |
'object': userinfo['sub'],
|
|
166 |
'object_type': 'user',
|
|
167 |
'capacity': 'admin',
|
|
168 |
}
|
|
169 |
|
|
170 |
member_create_context = {
|
|
171 |
'model': model,
|
|
172 |
'user': userobj.name,
|
|
173 |
'ignore_auth': True,
|
|
174 |
'session': session
|
|
175 |
}
|
|
176 |
|
|
177 |
member_create(member_create_context, member_dict)
|
|
178 |
|
|
179 |
if 'nickname' in userinfo:
|
|
180 |
userobj.name = userinfo['nickname']
|
|
181 |
try:
|
|
182 |
userobj.save()
|
|
183 |
except Exception, e:
|
|
184 |
log.warning('Error while saving user name: %s' % e)
|
|
185 |
|
143 |
186 |
if 'given_name' in userinfo:
|
144 |
187 |
userobj.fullname = userinfo['given_name']
|
145 |
188 |
if 'family_name' in userinfo:
|
146 |
|
userobj.fullname += userinfo['family_name']
|
|
189 |
userobj.fullname += ' ' + userinfo['family_name']
|
147 |
190 |
userobj.save()
|
148 |
191 |
session['user'] = userobj.id
|
149 |
192 |
session.save()
|
150 |
193 |
|
151 |
|
org_url = toolkit.url_for(host=request.host,
|
152 |
|
controller="organization",
|
153 |
|
action='read',
|
154 |
|
id=g.name,
|
155 |
|
locale=locale,
|
156 |
|
qualified=True)
|
157 |
|
redirect_to(str(org_url))
|
|
194 |
redirect_to(org_url)
|
158 |
195 |
|
159 |
196 |
def logout(self):
|
160 |
197 |
toolkit.c.slo_url = toolkit.url_for(host=request.host,
|
user provisionning (#6718)
user create or update on sso