POC Campus Condorcet : gestion eppn vides
This commit is contained in:
parent
5db264a513
commit
4aaddaa8e1
|
@ -3,6 +3,7 @@ import json
|
|||
import logging
|
||||
|
||||
from urllib2 import build_opener, HTTPHandler, Request, HTTPError
|
||||
from random import randint
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
rootdn = 'dc=condorcet,dc=dev,dc=entrouvert,dc=org'
|
||||
|
@ -29,6 +30,10 @@ sso_attributes = ['prenom',
|
|||
's_emp_corps',
|
||||
's_liste_rouge']
|
||||
|
||||
|
||||
def generate_eppn(lastname):
|
||||
return "%s-%06d@campus-condorcet.fr"%(lastname, randint(0,pow(10,6)))
|
||||
|
||||
def craft_user_nickname(mellon_dict):
|
||||
prenom = mellon_dict.get('prenom')[0]
|
||||
nom = mellon_dict.get('nom')[0]
|
||||
|
|
|
@ -5,7 +5,8 @@ from django.utils.translation import ugettext as _
|
|||
|
||||
from .forms import RegistrationForm
|
||||
from .utils import ldap_contains_user, wcs_submit, \
|
||||
sso_attributes, craft_user_nickname
|
||||
sso_attributes, craft_user_nickname \
|
||||
generate_eppn
|
||||
|
||||
logger = logging.getLogger('django')
|
||||
|
||||
|
@ -61,8 +62,9 @@ class RegistrationFormView(FormView):
|
|||
return initial
|
||||
|
||||
def form_valid(self, form):
|
||||
post_dict = self.request.POST
|
||||
form_adequate_data = {}
|
||||
form_adequate_data['ep_principal_name'] = self.request.POST.get('ep_principal_name')
|
||||
form_adequate_data['ep_principal_name'] = post_dict.get('ep_principal_name') or generate_eppn(post_dict.get('lastname', 'undefined'))
|
||||
|
||||
if ldap_contains_user(form_adequate_data):
|
||||
return usernone(self.request)
|
||||
|
@ -71,11 +73,11 @@ class RegistrationFormView(FormView):
|
|||
wcs_rest_data = {}
|
||||
|
||||
for field in wcs_fields:
|
||||
sanitized_form_entry = str(self.request.POST.get(field, False))
|
||||
sanitized_form_entry = str(post_dict.get(field, False))
|
||||
wcs_rest_data[field] = sanitized_form_entry
|
||||
|
||||
for multiple_field in wcs_multiple_fields:
|
||||
sanizted_form_list = self.request.POST.getlist(multiple_field, [])
|
||||
sanizted_form_list = post_dict.getlist(multiple_field, [])
|
||||
wcs_rest_data[multiple_field] = delimiter.join(sanizted_form_list)
|
||||
|
||||
wcs_submit(wcs_rest_data)
|
||||
|
|
Reference in New Issue