From 176d400287305ead70a3f1e1cd2e5443c0b9cfb5 Mon Sep 17 00:00:00 2001 From: Horilla Date: Wed, 3 Jul 2024 13:05:21 +0530 Subject: [PATCH] [UPDT] BASE: Updated horilla database initialize by adding authentication --- base/views.py | 19 ++- horilla/horilla_settings.py | 9 ++ .../horilla_department_form.html | 2 +- .../initialize_database/horilla_user.html | 120 +++----------- .../horilla_user_signup.html | 150 ++++++++++++++++++ 5 files changed, 197 insertions(+), 103 deletions(-) create mode 100644 horilla/horilla_settings.py create mode 100644 templates/initialize_database/horilla_user_signup.html diff --git a/base/views.py b/base/views.py index a7328738c..4a61b03b5 100644 --- a/base/views.py +++ b/base/views.py @@ -200,10 +200,18 @@ def initialize_database_condition(): def initialize_database(request): if initialize_database_condition(): - return render( - request, - "initialize_database/horilla_user.html", - ) + if request.method == "POST": + password = request._post.get("password") + from horilla.horilla_settings import DB_INIT_PASSWORD as db_password + + if db_password == password: + return redirect(initialize_database_user) + else: + messages.warning( + request, + _("The password you entered is incorrect. Please try again."), + ) + return HttpResponse("") else: return redirect("/") @@ -238,7 +246,7 @@ def initialize_database_user(request): "initialize_database/horilla_company.html", {"form": CompanyForm(initial={"hq": True})}, ) - return render(request, "initialize_database/horilla_user.html") + return render(request, "initialize_database/horilla_user_signup.html") @hx_request_required @@ -5184,6 +5192,7 @@ def audit_tag_update(request, tag_id): @login_required +@permission_required("base.view_multipleapprovalcondition") def multiple_approval_condition(request): form = MultipleApproveConditionForm() conditions = MultipleApprovalCondition.objects.all().order_by("department")[::-1] diff --git a/horilla/horilla_settings.py b/horilla/horilla_settings.py new file mode 100644 index 000000000..e0f5ed0c7 --- /dev/null +++ b/horilla/horilla_settings.py @@ -0,0 +1,9 @@ +from horilla import settings + +""" +DB_INIT_PASSWORD: str + +The password used for database setup and initialization. This password is a +48-character alphanumeric string generated using a UUID to ensure high entropy and security. +""" +DB_INIT_PASSWORD = "d3f6a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d" \ No newline at end of file diff --git a/templates/initialize_database/horilla_department_form.html b/templates/initialize_database/horilla_department_form.html index 47fbcc732..fafd3d741 100644 --- a/templates/initialize_database/horilla_department_form.html +++ b/templates/initialize_database/horilla_department_form.html @@ -78,7 +78,7 @@ hx-swap="innerHTML" class="oh-btn oh-btn--secondary-outline m-2" role="button" - > + > {% trans "Next Step" %} diff --git a/templates/initialize_database/horilla_user.html b/templates/initialize_database/horilla_user.html index 6481efa1d..4d2995e18 100644 --- a/templates/initialize_database/horilla_user.html +++ b/templates/initialize_database/horilla_user.html @@ -48,7 +48,6 @@ .select2-selection.select2-selection--multiple { height: 46px !important; } -
@@ -61,7 +60,7 @@
@@ -71,18 +70,22 @@ class="oh-onboarding-card__step oh-onboarding-card__step--active" >
1
- Sign Up + Authentication
  • 2
    - Company + Sign Up
  • 3
    + Company +
  • +
  • +
    4
    Department
  • -
    4
    +
    5
    Job Position
  • @@ -90,66 +93,19 @@

    - {% trans "Sign Up" %} + {% trans "Database Authentication" %}

    - {% trans "Please sign up to access the Horilla HRMS." %} + {% trans "Authenticate with your password to initialize the Horilla HRMS database." %}

    {% csrf_token %}
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    -
    -
    -
    -
    - - -
    -
    -
    +
    -
    -
    -
    - - -
    -
    -
    -
    - - -
    -
    -
    - + {% trans "Authenticate" %} + + +
    Horilla @@ -230,6 +156,7 @@ + -