Commit 1fa5c38a by asadiqbal

UI Updates to Support Ent Data Synchronization

parent 79d95e9c
......@@ -123,6 +123,14 @@ def login_and_registration_form(request, initial_mode="login"):
} for message in messages.get_messages(request) if 'account-activation' in message.tags
]
# add user details from running pipeline
pipeline_user_details = {}
running_pipeline = pipeline.get(request)
if running_pipeline:
pipeline_user_details = running_pipeline['kwargs']['details']
enterprise_customer = enterprise_customer_for_request(request)
# Otherwise, render the combined login/registration page
context = {
'data': {
......@@ -145,7 +153,9 @@ def login_and_registration_form(request, initial_mode="login"):
'registration_form_desc': json.loads(form_descriptions['registration']),
'password_reset_form_desc': json.loads(form_descriptions['password_reset']),
'account_creation_allowed': configuration_helpers.get_value(
'ALLOW_PUBLIC_ACCOUNT_CREATION', settings.FEATURES.get('ALLOW_PUBLIC_ACCOUNT_CREATION', True))
'ALLOW_PUBLIC_ACCOUNT_CREATION', settings.FEATURES.get('ALLOW_PUBLIC_ACCOUNT_CREATION', True)),
'pipeline_user_details': pipeline_user_details,
'enterprise_name': enterprise_customer.get('name') if enterprise_customer else None
},
'login_redirect_url': redirect_to, # This gets added to the query string of the "Sign In" button in header
'responsive': True,
......@@ -399,7 +409,7 @@ def _get_form_descriptions(request):
return {
'password_reset': get_password_reset_form().to_json(),
'login': get_login_session_form().to_json(),
'login': get_login_session_form(request).to_json(),
'registration': RegistrationFormFactory().get_registration_form(request).to_json()
}
......
......@@ -75,6 +75,8 @@
this.passwordResetSupportUrl = options.password_reset_support_link;
this.createAccountOption = options.account_creation_allowed;
this.hideAuthWarnings = options.hide_auth_warnings || false;
this.pipelineUserDetails = options.pipeline_user_details;
this.enterpriseName = options.enterprise_name || '';
// The login view listens for 'sync' events from the reset model
this.resetModel = new PasswordResetModel({}, {
......@@ -133,7 +135,9 @@
supportURL: this.supportURL,
passwordResetSupportUrl: this.passwordResetSupportUrl,
createAccountOption: this.createAccountOption,
hideAuthWarnings: this.hideAuthWarnings
hideAuthWarnings: this.hideAuthWarnings,
pipelineUserDetails: this.pipelineUserDetails,
enterpriseName: this.enterpriseName
});
// Listen for 'password-help' event to toggle sub-views
......
......@@ -50,6 +50,8 @@
this.createAccountOption = data.createAccountOption;
this.accountActivationMessages = data.accountActivationMessages;
this.hideAuthWarnings = data.hideAuthWarnings;
this.pipelineUserDetails = data.pipelineUserDetails;
this.enterpriseName = data.enterpriseName;
this.listenTo(this.model, 'sync', this.saveSuccess);
this.listenTo(this.resetModel, 'sync', this.resetEmail);
......@@ -68,7 +70,9 @@
providers: this.providers,
hasSecondaryProviders: this.hasSecondaryProviders,
platformName: this.platformName,
createAccountOption: this.createAccountOption
createAccountOption: this.createAccountOption,
pipelineUserDetails: this.pipelineUserDetails,
enterpriseName: this.enterpriseName
}
}));
......
<div class="js-form-feedback" aria-live="assertive" tabindex="-1">
</div>
<% if ( context.createAccountOption !== false && !context.syncLearnerProfileData) { %>
<% if ( context.createAccountOption !== false && context.enterpriseName == "") { %>
<div class="toggle-form">
<span class="text"><%- gettext("First time here?") %></span>
<a href="#login" class="form-toggle" data-type="register"><%- gettext("Create an Account.") %></a>
</div>
<% } %>
<h2><%- gettext("Sign In") %></h2>
<% if (context.enterpriseName) { %>
<% if (context.pipelineUserDetails.email) { %>
<h2><%- gettext("Sign in to continue learning as {email}").replace("{email}", context.pipelineUserDetails.email) %></h2>
<% } else { %>
<h2><%- gettext("Sign in to continue learning") %></h2>
<% } %>
<p><%- gettext("You already have an edX account with your {enterprise_name} email address. Going forward, your account information will be updated and maintained by {enterprise_name}. You can view your information or unlink from {enterprise_name} anytime in your Account Settings.").replace(/{enterprise_name}/g, context.enterpriseName) %> </p>
<p><%- gettext("To continue learning with this account, sign in below.") %></p>
<% } else { %>
<h2><%- gettext("Sign In") %></h2>
<% } %>
<form id="login" class="login-form" tabindex="-1" method="POST">
......
......@@ -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:
......@@ -92,16 +92,33 @@ def get_login_session_form():
platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME)
)
email = ''
email_field_restrictions = {
"min_length": accounts.EMAIL_MIN_LENGTH,
"max_length": accounts.EMAIL_MAX_LENGTH,
}
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').copy()
email = details.get('email', '')
if email:
email_field_restrictions.update({"readonly": True})
form_desc.add_field(
"email",
field_type="email",
label=email_label,
placeholder=email_placeholder,
instructions=email_instructions,
restrictions={
"min_length": accounts.EMAIL_MIN_LENGTH,
"max_length": accounts.EMAIL_MAX_LENGTH,
}
default=email,
restrictions=email_field_restrictions
)
# Translators: This label appears above a field on the login form
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment