From 2842fc88e027493dd9ae00e0f8a69a86f3d50680 Mon Sep 17 00:00:00 2001 From: Loic Baron Date: Thu, 14 Aug 2014 16:33:41 +0200 Subject: [PATCH] Auto Validation of PLE enabled users monitor module widget template statistics widget --- manifoldapi/manifoldproxy.py | 9 ++- portal/actions.py | 9 +-- portal/emailactivationview.py | 67 +++++++++---------- portal/registrationview.py | 24 ++++--- .../templates/_widget-stats-top-slices.html | 2 +- portal/templates/email_activation.html | 6 +- .../onelab/onelab_registration_view.html | 4 +- rest/credentials.py | 10 ++- 8 files changed, 73 insertions(+), 58 deletions(-) diff --git a/manifoldapi/manifoldproxy.py b/manifoldapi/manifoldproxy.py index 99959aee..433a854b 100644 --- a/manifoldapi/manifoldproxy.py +++ b/manifoldapi/manifoldproxy.py @@ -55,9 +55,12 @@ with the query passed using POST""" admin_user, admin_password = ConfigEngine().manifold_admin_user_password() manifold_api_session_auth = {'AuthMethod': 'password', 'Username': admin_user, 'AuthString': admin_password} else: - print request.session['manifold'] - manifold_api_session_auth = request.session['manifold']['auth'] - + if 'manifold' in request.session: + manifold_api_session_auth = request.session['manifold']['auth'] + else: + json_answer=json.dumps({'code':0,'value':[]}) + return HttpResponse (json_answer, mimetype="application/json") + if debug_empty and manifold_query.action.lower()=='get': json_answer=json.dumps({'code':0,'value':[]}) print "By-passing : debug_empty & 'get' request : returning a fake empty list" diff --git a/portal/actions.py b/portal/actions.py index 7f073708..8ca3acff 100644 --- a/portal/actions.py +++ b/portal/actions.py @@ -71,7 +71,8 @@ def clear_user_creds(request, user_email): if platform_detail['platform_id'] == account_detail['platform_id']: if 'myslice' in platform_detail['platform']: account_config = json.loads(account_detail['config']) - user_cred = account_config.get('delegated_user_credential','N/A') + #user_cred = account_config.get('delegated_user_credential','N/A') + user_cred = account_config.get('user_credential','N/A') if 'N/A' not in user_cred: user_hrn = account_config.get('user_hrn','N/A') user_pub_key = json.dumps(account_config.get('user_public_key','N/A')) @@ -557,10 +558,11 @@ def sfa_create_user(wsgi_request, request, namespace = None, as_admin = False): query = Query.create('%s:user' % namespace).set(sfa_user_params).select('user_hrn') else: query = Query.create('user').set(sfa_user_params).select('user_hrn') + if as_admin: - results = execute_query(wsgi_request, query) - else: results = execute_admin_query(wsgi_request, query) + else: + results = execute_query(wsgi_request, query) if not results: raise Exception, "Could not create %s. Already exists ?" % sfa_user_params['user_hrn'] @@ -571,7 +573,6 @@ def sfa_create_user(wsgi_request, request, namespace = None, as_admin = False): return results def create_user(wsgi_request, request, namespace = None, as_admin = False): - # XXX This has to be stored centrally USER_STATUS_ENABLED = 2 diff --git a/portal/emailactivationview.py b/portal/emailactivationview.py index adb57e41..a485bc3b 100644 --- a/portal/emailactivationview.py +++ b/portal/emailactivationview.py @@ -38,8 +38,10 @@ class ActivateEmailView(FreeAccessView, ThemeView): #print "%s = %s" % (key, value) if key == "hash_code": hash_code=value - if PendingUser.objects.filter(email_hash__iexact = hash_code).filter(status__iexact = 'False'): + activation = 'success' + PendingUser.objects.filter(email_hash__iexact = hash_code).update(status='True') + # AUTO VALIDATION of PLE enabled users (only for OneLab Portal) if self.theme == "onelab": # Auto-Validation of pending user, which is enabled in a trusted SFA Registry (example: PLE) @@ -51,12 +53,12 @@ class ActivateEmailView(FreeAccessView, ThemeView): if pending_users: pending_user = pending_users[0] pending_user_request = make_request_user(pending_user) - pending_user_email = pending_users[0].user_email + pending_user_email = pending_users[0].email query = Query.get('myplcuser').filter_by('email', '==', pending_user_email).select('enabled') results = execute_admin_query(self.request, query) for result in results: # User is enabled in PLE - if 'user_enabled' in result and result['user_enabled']==True: + if 'enabled' in result and result['enabled']==True: ple_user_enabled = True break else: @@ -67,42 +69,33 @@ class ActivateEmailView(FreeAccessView, ThemeView): # Create user in SFA and Update in Manifold create_user(self.request, pending_user_request, namespace = 'myslice', as_admin = True) # Delete pending user - PendingUser.objects.filter(email_hash__iexact = hash_code).delete() + #PendingUser.objects.filter(email_hash__iexact = hash_code).delete() - #get_user.status= 'True' - #get_user.save() - #for user in PendingUser.objects.all(): - # first_name = user.first_name - # last_name = user.last_name - # authority_hrn = user.authority_hrn - # public_key = user.public_key - # email = user.email - # user_hrn = user.user_hrn - PendingUser.objects.filter(email_hash__iexact = hash_code).update(status='True') - activation = 'success' - # sending email after activation success - #try: - # Send an email: the recipients are the PI of the authority - # If No PI is defined for this Authority, send to a default email (different for each theme) - # recipients = authority_get_pi_emails(wsgi_request, authority_hrn) - # theme.template_name = 'user_request_email.html' - # html_content = render_to_string(theme.template, request) - # theme.template_name = 'user_request_email.txt' - # text_content = render_to_string(theme.template, request) - # theme.template_name = 'user_request_email_subject.txt' - # subject = render_to_string(theme.template, request) - # subject = subject.replace('\n', '') - # theme.template_name = 'email_default_sender.txt' - # sender = render_to_string(theme.template, request) - # sender = sender.replace('\n', '') - # msg = EmailMultiAlternatives(subject, text_content, sender, recipients) - # msg.attach_alternative(html_content, "text/html") - # msg.send() - # except Exception, e: - # print "Failed to send email, please check the mail templates and the SMTP configuration of your server" - # import traceback - # traceback.print_exc() + # template user auto validated + activation = 'validated' + # sending email after activation success + #try: + # # Send an email: the recipient is the user + # recipients = pending_user_eamil + # theme.template_name = 'user_request_email.html' + # html_content = render_to_string(theme.template, request) + # theme.template_name = 'user_request_email.txt' + # text_content = render_to_string(theme.template, request) + # theme.template_name = 'user_request_email_subject.txt' + # subject = render_to_string(theme.template, request) + # subject = subject.replace('\n', '') + # theme.template_name = 'email_default_sender.txt' + # sender = render_to_string(theme.template, request) + # sender = sender.replace('\n', '') + # msg = EmailMultiAlternatives(subject, text_content, sender, recipients) + # msg.attach_alternative(html_content, "text/html") + # msg.send() + #except Exception, e: + # print "Failed to send email, please check the mail templates and the SMTP configuration of your server" + # import traceback + # traceback.print_exc() + else: activation = 'failed' diff --git a/portal/registrationview.py b/portal/registrationview.py index c24fda68..105eccee 100644 --- a/portal/registrationview.py +++ b/portal/registrationview.py @@ -106,17 +106,13 @@ class RegistrationView (FreeAccessView, ThemeView): errors.append('First name may contain only letters, numbers, spaces and @/./+/-/_ characters.') if (re.search(r'^[\w+\s.@+-]+$', user_request['last_name']) == None): errors.append('Last name may contain only letters, numbers, spaces and @/./+/-/_ characters.') - # checking in django_db !! - if PendingUser.objects.filter(email__iexact = user_request['email']): - errors.append('Email is pending for validation. Please provide a new email address.') - if UserModel._default_manager.filter(email__iexact = user_request['email']): - errors.append('This email is not usable. Please contact the administrator or try with another email.') # Does the user exist in Manifold? user_query = Query().get('local:user').select('user_id','email') user_details = execute_admin_query(wsgi_request, user_query) for user_detail in user_details: if user_detail['email'] == user_request['email']: - errors.append('Email already registered in Manifold. Please provide a new email address.') + errors.append('Email already registered. Login with your existing account. Forgot your password?') + # Does the user exist in sfa? [query is very slow!!] #user_query = Query().get('user').select('user_hrn','user_email') # XXX Test based on the user_hrn is quick @@ -125,12 +121,24 @@ class RegistrationView (FreeAccessView, ThemeView): for user in user_details_sfa: if user['user_email'] == user_request['email']: - errors.append('Email already registered in SFA registry. Please use another email.') + errors.append('Email already registered in OneLab registry. Contact OneLab support or use another email.') if user['user_hrn'] == user_request['user_hrn']: # add random number if user_hrn already exists in the registry user_request['user_hrn'] = user_request['authority_hrn'] \ + '.' + split_email + str(randint(1,1000000)) - + + # checking in django unfold db portal application pending users + # sqlite3 /var/unfold/unfold.sqlite3 + # select email from portal_pendinguser; + if PendingUser.objects.filter(email__iexact = user_request['email']): + errors.append('Account pending for validation. Please wait till your account is validated or contact OneLab support.') + + # checking in django_db !! + # sqlite3 /var/unfold/unfold.sqlite3 + # select email from auth_user; + if UserModel._default_manager.filter(email__iexact = user_request['email']): + errors.append('Contact OneLab support or try with another email.') + # XXX TODO: Factorize with portal/accountview.py # XXX TODO: Factorize with portal/registrationview.py # XXX TODO: Factorize with portal/joinview.py diff --git a/portal/templates/_widget-stats-top-slices.html b/portal/templates/_widget-stats-top-slices.html index 4625d7d1..80d9aed1 100644 --- a/portal/templates/_widget-stats-top-slices.html +++ b/portal/templates/_widget-stats-top-slices.html @@ -142,4 +142,4 @@ function drawChart(graph, orderby, period) { - \ No newline at end of file + diff --git a/portal/templates/email_activation.html b/portal/templates/email_activation.html index 43feab20..ce763ba3 100644 --- a/portal/templates/email_activation.html +++ b/portal/templates/email_activation.html @@ -6,10 +6,14 @@

User RegistrationUser sign-up

- {%if activation_status == 'success'%} + {% if activation_status == 'success' %}

Signup request confirmed.

You are currently able to log in to the portal using your email address and the password that you provided, but your access is still limited.

You will have full access as soon as your account is validated by a manager at your organization. We have sent an email to the managers with a validation request.

+ {% elif activation_status == 'validated' %} +

Account validated.

+

We have identified you as a valid PLE user. Your OneLab account has automatically been approved.

+

You have a full access to OneLab testbeds.

{%else%}

Signup confirmation failed.

You have probably arrived at this page by clicking a confirmation link in an email that we have sent to you. However, diff --git a/portal/templates/onelab/onelab_registration_view.html b/portal/templates/onelab/onelab_registration_view.html index 9e763236..3436fa13 100644 --- a/portal/templates/onelab/onelab_registration_view.html +++ b/portal/templates/onelab/onelab_registration_view.html @@ -15,9 +15,9 @@ {% if errors %}

-
    +
      {% for error in errors %} -
    • {{ error }}
    • +
    • {{ error | safe }}
    • {% endfor %}
diff --git a/rest/credentials.py b/rest/credentials.py index d63babfb..632600a3 100644 --- a/rest/credentials.py +++ b/rest/credentials.py @@ -7,15 +7,21 @@ def dispatch(request, action): if (action == 'clear') : res=[] emails = request.POST.getlist('emails[]') + if not emails: + emails = request.GET.getlist('emails[]') + import pdb + pdb.set_trace() if emails : for email in emails : try : - res.append(clear_user_creds(request, email)) + clear = clear_user_creds(request, email) + if clear is not None: + res.append(clear) except : pass if not res : - ret = { "ret" : 1, "emails" : res } + ret = { "ret" : 1, "emails" : emails } else : ret = { "ret" : 0 } -- 2.43.0