Merge pull request #16950 from edx/asadiqbal08/ENT-772-Update-singin-UI

ENT-772 - UI Updated to Support Ent Data Synchronization message
This commit is contained in:
Asad Iqbal
2018-01-08 12:55:24 +05:00
committed by GitHub
10 changed files with 109 additions and 48 deletions

View File

@@ -62,7 +62,7 @@ def get_password_reset_form():
return form_desc
def get_login_session_form():
def get_login_session_form(request):
"""Return a description of the login form.
This decouples clients from the API definition:
@@ -77,6 +77,7 @@ def get_login_session_form():
"""
form_desc = FormDescription("post", reverse("user_api_login_session"))
_apply_third_party_auth_overrides(request, form_desc)
# Translators: This label appears above a field on the login form
# meant to hold the user's email address.
@@ -128,6 +129,38 @@ def get_login_session_form():
return form_desc
def _apply_third_party_auth_overrides(request, form_desc):
"""Modify the login form if the user has authenticated with a third-party provider.
If a user has successfully authenticated with a third-party provider,
and an email is associated with it then we fill in the email field with readonly property.
Arguments:
request (HttpRequest): The request for the registration form, used
to determine if the user has successfully authenticated
with a third-party provider.
form_desc (FormDescription): The registration form description
"""
if third_party_auth.is_enabled():
running_pipeline = third_party_auth.pipeline.get(request)
if running_pipeline:
current_provider = third_party_auth.provider.Registry.get_from_pipeline(running_pipeline)
if current_provider and enterprise_customer_for_request(request):
pipeline_kwargs = running_pipeline.get('kwargs')
# Details about the user sent back from the provider.
details = pipeline_kwargs.get('details')
email = details.get('email', '')
# override the email field.
form_desc.override_field_properties(
"email",
default=email,
restrictions={"readonly": "readonly"} if email else {
"min_length": accounts.EMAIL_MIN_LENGTH,
"max_length": accounts.EMAIL_MAX_LENGTH,
}
)
class RegistrationFormFactory(object):
"""HTTP end-points for creating a new user. """

View File

@@ -126,7 +126,7 @@ class FormDescription(object):
ALLOWED_RESTRICTIONS = {
"text": ["min_length", "max_length"],
"password": ["min_length", "max_length"],
"email": ["min_length", "max_length"],
"email": ["min_length", "max_length", "readonly"],
}
FIELD_TYPE_MAP = {

View File

@@ -43,7 +43,7 @@ class LoginSessionView(APIView):
@method_decorator(ensure_csrf_cookie)
def get(self, request):
return HttpResponse(get_login_session_form().to_json(), content_type="application/json")
return HttpResponse(get_login_session_form(request).to_json(), content_type="application/json")
@method_decorator(require_post_params(["email", "password"]))
@method_decorator(csrf_protect)

View File

@@ -61,6 +61,7 @@ def update_logistration_context_for_enterprise(request, context, enterprise_cust
context.update(sidebar_context)
context['enable_enterprise_sidebar'] = True
context['data']['hide_auth_warnings'] = True
context['data']['enterprise_name'] = enterprise_customer['name']
else:
context['enable_enterprise_sidebar'] = False