From 3737376bd0a6878888bb9079646df0b2796efafa Mon Sep 17 00:00:00 2001 From: Muhammad Faraz Maqsood Date: Thu, 19 Oct 2023 14:09:46 +0500 Subject: [PATCH] finalizing the nafath flow code --- .../nafath_openedx_integration/base.html | 22 +++++++++++++++++++ .../useractivationmessage/email/body.html | 13 +++++++++++ .../useractivationmessage/email/body.txt | 2 ++ .../useractivationmessage/email/from_name.txt | 1 + .../useractivationmessage/email/head.html | 1 + .../useractivationmessage/email/subject.txt | 4 ++++ .../core/djangoapps/user_authn/views/login.py | 7 ++++++ 7 files changed, 50 insertions(+) create mode 100644 lms/templates/nafath_openedx_integration/base.html create mode 100644 lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/body.html create mode 100644 lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/body.txt create mode 100644 lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/from_name.txt create mode 100644 lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/head.html create mode 100644 lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/subject.txt diff --git a/lms/templates/nafath_openedx_integration/base.html b/lms/templates/nafath_openedx_integration/base.html new file mode 100644 index 000000000000..d13a13ed43ab --- /dev/null +++ b/lms/templates/nafath_openedx_integration/base.html @@ -0,0 +1,22 @@ + +{% comment %} +As the developer of this package, don't place anything here if you can help it +since this allows developers to have interoperability between your template +structure and their own. + +Example: Developer melding the 2SoD pattern to fit inside with another pattern:: + + {% extends "base.html" %} + {% load static %} + + + {% block extra_js %} + + + {% block javascript %} + + {% endblock javascript %} + + {% endblock extra_js %} +{% endcomment %} + diff --git a/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/body.html b/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/body.html new file mode 100644 index 000000000000..876d582afd7e --- /dev/null +++ b/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/body.html @@ -0,0 +1,13 @@ + + +{% load i18n %} +{% load static %} +{% block content %} +

+ {% autoescape off %} + {# xss-lint: disable=django-blocktrans-missing-escape-filter #} + {% blocktrans %}This is one time OTP {{ activation_code }}. Kindly use this to complete nafath authentication with SDAIA.{% endblocktrans %} + {% endautoescape %} +
+

+{% endblock %} diff --git a/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/body.txt b/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/body.txt new file mode 100644 index 000000000000..01ac74599df1 --- /dev/null +++ b/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/body.txt @@ -0,0 +1,2 @@ +{% load i18n %}{% autoescape off %}{% blocktrans %}This is one time OTP {{ activation_code }}. Kindly use this to complete nafath authentication with SDAIA.{% endblocktrans %} +{% endautoescape %} diff --git a/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/from_name.txt b/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/from_name.txt new file mode 100644 index 000000000000..dcbc23c00480 --- /dev/null +++ b/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/from_name.txt @@ -0,0 +1 @@ +{{ platform_name }} diff --git a/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/head.html b/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/head.html new file mode 100644 index 000000000000..83d045ed4c69 --- /dev/null +++ b/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/head.html @@ -0,0 +1 @@ + diff --git a/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/subject.txt b/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/subject.txt new file mode 100644 index 000000000000..80037dcd1a41 --- /dev/null +++ b/lms/templates/nafath_openedx_integration/edx_ace/useractivationmessage/email/subject.txt @@ -0,0 +1,4 @@ +{% load i18n %} +{% autoescape off %} +{% blocktrans %}SDAIA - Complete Nafath Authentication{% endblocktrans %} +{% endautoescape %} diff --git a/openedx/core/djangoapps/user_authn/views/login.py b/openedx/core/djangoapps/user_authn/views/login.py index 79cb78a2727c..472790859e4c 100644 --- a/openedx/core/djangoapps/user_authn/views/login.py +++ b/openedx/core/djangoapps/user_authn/views/login.py @@ -129,6 +129,8 @@ def _get_user_by_email_or_username(request, api_version): login_fields = ['email', 'password'] if is_api_v2: login_fields = ['email_or_username', 'password'] + if request.POST.get('is_nafath_user', False): + login_fields.remove('password') if any(f not in request.POST.keys() for f in login_fields): raise AuthFailedError(_('There was an error receiving your login information. Please email us.')) @@ -239,6 +241,11 @@ def _authenticate_first_party(request, unauthenticated_user, third_party_auth_re if not third_party_auth_requested: _check_user_auth_flow(request.site, unauthenticated_user) + if request.POST.get('is_nafath_user', False): + return authenticate( + username=username, + request=request + ) password = normalize_password(request.POST['password']) return authenticate( username=username,