Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] (captcha_refresh) - Add previous code for captcha refresh #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions frontend/js/components/captcha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export function captcha() {
const load_new_captcha_image = document.getElementById("load-new-img");

// ? Disabled for now - Must be use if we had 'Data confidentiality policy'
// const id_data_confidentiality_policy = document.getElementById(
// "id_data_confidentiality_policy"
// );
// const btn_send_contact_form = document.getElementById("send-contact-form");

if (load_new_captcha_image) {
load_new_captcha_image.addEventListener("click", async function (ev) {
ev.preventDefault();

let reqHeader = new Headers();
reqHeader.append("x-requested-with", "XMLHttpRequest");

let initObject = {
method: "GET",
headers: reqHeader,
};

const response = await fetch(
`${window.location.origin}/code-check/refresh/`,
initObject
);
const new_img = await response.json();

document.getElementById("id_captcha_0").value = new_img.key;
document.getElementsByClassName("captcha")[0].src =
new_img.image_url;
});
}

// ? Disabled for now - Must be use if we had 'Data confidentiality policy'
// if (id_data_confidentiality_policy) {
// if (id_data_confidentiality_policy.checked) {
// btn_send_contact_form.disabled = false;
// }

// id_data_confidentiality_policy.addEventListener(
// "change",
// function (ev) {
// if (ev.target.checked) {
// btn_send_contact_form.disabled = false;
// } else {
// btn_send_contact_form.disabled = true;
// }
// }
// );
// }
}
16 changes: 15 additions & 1 deletion frontend/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Note than jQuery is not required by Bootstrap and just loaded for convenience for
* developers which can't or don't want to develop in vanilla Javascript.
*/
*/

//
// Make jQuery object usable inside modules
Expand Down Expand Up @@ -39,8 +39,22 @@ import {
Tooltip,
} from "bootstrap/dist/js/bootstrap.bundle.js";

import { captcha } from "./components/captcha";

//
// NOTE: Sample how to instanciate a Bootstrap component object.
//
// var myModal = new Modal(document.getElementById("exampleModalDefault"));
// myModal.show();

/**
* Run the application
*/

const run = () => {
captcha();
};

document.addEventListener("DOMContentLoaded", function () {
run();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{% block body-content %}
{% block app_content %}
{% spaceless %}
<div class="sample-index p-5">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li {% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}

<h2>{% trans "Contact form" %}</h2>

<div class="fobi-front">
<div class="content">
<form method="POST">
{% csrf_token %}

{{ form.non_field_errors }}
<div class="fieldWrapper">
{{ form.first_name.errors }}
<label for="{{ form.first_name.id_for_label }}">{% trans "First name" %}* :</label>
{{ form.first_name }}
</div>
<div class="fieldWrapper">
{{ form.last_name.errors }}
<label for="{{ form.last_name.id_for_label }}">{% trans "Last name" %}* :</label>
{{ form.last_name }}
</div>
<div class="fieldWrapper">
{{ form.phone.errors }}
<label for="{{ form.phone.id_for_label }}">{% trans "Phone" %} :</label>
{{ form.phone }}
</div>
<div class="fieldWrapper">
{{ form.email.errors }}
<label for="{{ form.email.id_for_label }}">{% trans "E-mail" %}* :</label>
{{ form.email }}
</div>
<div class="fieldWrapper">
{{ form.message.errors }}
<label for="{{ form.message.id_for_label }}">{% trans "Message" %}* :</label>
{{ form.message }}
</div>
<div class="fieldWrapper">
{{ form.data_confidentiality_policy.errors }}
<label for="{{ form.data_confidentiality_policy.id_for_label }}">
{% trans "Data confidentiality policy" %}* :
</label>
{{ form.data_confidentiality_policy }}

{% comment %} {% page_url "data_confidentiality_policy" as data_confidentiality_policy_page %}
{% if data_confidentiality_policy_page %}
{% include "privacy_policy/terms.html" with data_policy_url=data_confidentiality_policy_page %}
{% endif %} {% endcomment %}
</div>
<div class="fieldWrapper mb-5">
{{ form.captcha.errors }}
<label for="{{ form.captcha.id_for_label }}">{% trans "Captcha" %}* :</label>
{{ form.captcha }}
</div>

<button id="load-new-img">{% trans "New image" %}</button>
<input type="submit" id="send-contact-form" disabled/>
</form>
</div>
</div>

</div>
{% endspaceless %}
{% endblock app_content %}
{% endblock body-content %}