You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/chapter-16.rst
+209-1Lines changed: 209 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -816,7 +816,6 @@ You need to style the tags. For example:
816
816
line-height:1.2em;
817
817
margin:2px;
818
818
cursor: pointer;
819
-
opacity:0.2;
820
819
text-transform: capitalize;
821
820
}
822
821
ul.tags-list li[data-selected=true] {
@@ -873,3 +872,212 @@ but the entire page will be redirected.
873
872
874
873
The contents of the component html can contain `<script>...</script>` and they can modify global page variables
875
874
as well as modify other components.
875
+
876
+
.. _altcha_captcha:
877
+
878
+
Adding a Captcha Solution with Altcha
879
+
-------------------------------------
880
+
881
+
This section provides a simple captcha implementation for your py4web applications using the **Altcha** library. While not exhaustively tested, it serves as a practical example for integrating a robust, client-side captcha solution.
882
+
More information in https://altcha.org
883
+
884
+
Prerequisites
885
+
^^^^^^^^^^^^^
886
+
887
+
First, you need to install the Altcha library. You can do this using pip:
888
+
889
+
.. code-block:: bash
890
+
891
+
python3 -m pip install --upgrade altcha
892
+
893
+
You also need a secret key for HMAC verification. It's recommended to store this in your application's settings. For this example, we'll assume you have a file like ``.settings.py`` with the following variable:
894
+
895
+
.. code-block:: python
896
+
897
+
# .settings.py
898
+
ALTCHA_HMAC_KEY = "your-very-secret-key-here"
899
+
900
+
Controller Logic
901
+
^^^^^^^^^^^^^^^^
902
+
903
+
Next, you need to add the necessary actions to your controller file. The following code provides two actions: one to generate the captcha challenge (``altcha``) and another to handle a form with the captcha (``some_form``).
904
+
905
+
.. code-block:: python
906
+
907
+
# controllers/default.py
908
+
from altcha import (
909
+
create_challenge,
910
+
verify_solution,
911
+
ChallengeOptions,
912
+
)
913
+
from py4web import action, response, request, URL, Field, flash, Form
You need to include the Altcha JavaScript library and configure the widget in your HTML templates.
968
+
969
+
``form_altcha.html``
970
+
""""""""""""""""""""
971
+
972
+
This template works with the ``some_form``action. It loads the Altcha script and sets the ``challengeurl`` attribute to point to our ``altcha`` action.
For a custom authentication form, you can follow a similar approach. Make sure to insert the ``<altcha-widget>`` tag into the form's structure and include the necessary JavaScript.
0 commit comments