prune_captcha 1.12.2__tar.gz → 1.14.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {prune_captcha-1.12.2 → prune_captcha-1.14.0}/PKG-INFO +5 -1
  2. {prune_captcha-1.12.2 → prune_captcha-1.14.0}/README.md +4 -0
  3. prune_captcha-1.14.0/captcha_prune/asgi.py +7 -0
  4. prune_captcha-1.14.0/captcha_prune/utils.py +52 -0
  5. prune_captcha-1.14.0/captcha_prune/wsgi.py +7 -0
  6. {prune_captcha-1.12.2 → prune_captcha-1.14.0}/prune_captcha.egg-info/PKG-INFO +5 -1
  7. prune_captcha-1.14.0/prune_captcha.egg-info/SOURCES.txt +13 -0
  8. {prune_captcha-1.12.2 → prune_captcha-1.14.0}/prune_captcha.egg-info/top_level.txt +0 -2
  9. {prune_captcha-1.12.2 → prune_captcha-1.14.0}/pyproject.toml +1 -1
  10. prune_captcha-1.12.2/captcha_prune/asgi.py +0 -16
  11. prune_captcha-1.12.2/captcha_prune/migrations/0001_initial.py +0 -29
  12. prune_captcha-1.12.2/captcha_prune/migrations/0002_remove_captcha_created_at_remove_captcha_pos_x_and_more.py +0 -73
  13. prune_captcha-1.12.2/captcha_prune/migrations/0003_captcha_created_at_captcha_updated_at.py +0 -25
  14. prune_captcha-1.12.2/captcha_prune/migrations/__init__.py +0 -0
  15. prune_captcha-1.12.2/captcha_prune/models.py +0 -34
  16. prune_captcha-1.12.2/captcha_prune/payloads.py +0 -6
  17. prune_captcha-1.12.2/captcha_prune/utils.py +0 -44
  18. prune_captcha-1.12.2/captcha_prune/wsgi.py +0 -16
  19. prune_captcha-1.12.2/commons/base_model.py +0 -9
  20. prune_captcha-1.12.2/prune_captcha.egg-info/SOURCES.txt +0 -23
  21. prune_captcha-1.12.2/tests/__init__.py +0 -0
  22. prune_captcha-1.12.2/tests/captcha_prune/__init__.py +0 -0
  23. prune_captcha-1.12.2/tests/captcha_prune/test_views.py +0 -67
  24. {prune_captcha-1.12.2 → prune_captcha-1.14.0}/captcha_prune/__init__.py +0 -0
  25. {prune_captcha-1.12.2 → prune_captcha-1.14.0}/captcha_prune/apps.py +0 -0
  26. {prune_captcha-1.12.2 → prune_captcha-1.14.0}/captcha_prune/settings.py +0 -0
  27. {prune_captcha-1.12.2 → prune_captcha-1.14.0}/prune_captcha.egg-info/dependency_links.txt +0 -0
  28. {prune_captcha-1.12.2 → prune_captcha-1.14.0}/prune_captcha.egg-info/requires.txt +0 -0
  29. {prune_captcha-1.12.2 → prune_captcha-1.14.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: prune_captcha
3
- Version: 1.12.2
3
+ Version: 1.14.0
4
4
  Summary: A tool to protect formulaire from spam.
5
5
  Author-email: Arnout <bastien@prune.sh>
6
6
  Project-URL: Made_by, https://prune.sh/
@@ -64,6 +64,8 @@ In `settings.py`, set the path to the images used for the puzzle:
64
64
  PUZZLE_IMAGE_STATIC_PATH = "website/static/website/images/puzzles/"
65
65
  ```
66
66
 
67
+ Important: You must import the static files (css, js) present in "captcha_prune/static/".
68
+
67
69
  ### Utilisation
68
70
 
69
71
  - GET request (form display)
@@ -114,6 +116,8 @@ PUZZLE_IMAGE_STATIC_PATH = "website/static/website/images/puzzles/"
114
116
 
115
117
  | Version | Date | Notes |
116
118
  | ------- | ---------- | ---------------------------------- |
119
+ | 1.14.0 | 2025-05-21 | fix static and templates dirs |
120
+ | 1.13.0 | 2025-05-21 | use session, add static |
117
121
  | 1.12.2 | 2025-05-21 | doc fixed |
118
122
  | 1.12.1 | 2025-05-21 | doc fixed |
119
123
  | 1.12.0 | 2025-05-21 | removed views, added utils, ... |
@@ -46,6 +46,8 @@ In `settings.py`, set the path to the images used for the puzzle:
46
46
  PUZZLE_IMAGE_STATIC_PATH = "website/static/website/images/puzzles/"
47
47
  ```
48
48
 
49
+ Important: You must import the static files (css, js) present in "captcha_prune/static/".
50
+
49
51
  ### Utilisation
50
52
 
51
53
  - GET request (form display)
@@ -96,6 +98,8 @@ PUZZLE_IMAGE_STATIC_PATH = "website/static/website/images/puzzles/"
96
98
 
97
99
  | Version | Date | Notes |
98
100
  | ------- | ---------- | ---------------------------------- |
101
+ | 1.14.0 | 2025-05-21 | fix static and templates dirs |
102
+ | 1.13.0 | 2025-05-21 | use session, add static |
99
103
  | 1.12.2 | 2025-05-21 | doc fixed |
100
104
  | 1.12.1 | 2025-05-21 | doc fixed |
101
105
  | 1.12.0 | 2025-05-21 | removed views, added utils, ... |
@@ -0,0 +1,7 @@
1
+ import os
2
+
3
+ from django.core.asgi import get_asgi_application
4
+
5
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "captcha_prune.settings")
6
+
7
+ application = get_asgi_application()
@@ -0,0 +1,52 @@
1
+ import os
2
+ import random
3
+
4
+ from django.conf import settings
5
+ from django.http import HttpRequest
6
+
7
+
8
+ def create_and_get_captcha(
9
+ request, *, width=350, height=200, piece_width=80, piece_height=50, precision=2
10
+ ) -> dict:
11
+ pos_x_solution = random.randint(0, width - piece_width)
12
+ pos_y_solution = random.randint(0, height - piece_height)
13
+ piece_pos_x = random.randint(0, width - piece_width)
14
+ piece_pos_y = random.randint(0, height - piece_height)
15
+ _, _, puzzle_images_path = settings.PUZZLE_IMAGE_STATIC_PATH.rpartition("static/")
16
+ puzzle_images = [
17
+ f
18
+ for f in os.listdir(settings.PUZZLE_IMAGE_STATIC_PATH)
19
+ if f.lower().endswith((".jpg", ".jpeg", ".png", ".gif", ".webp"))
20
+ ]
21
+ selected_image = random.choice(puzzle_images)
22
+ request.session["pos_x_solution"] = pos_x_solution
23
+ request.session["pos_y_solution"] = pos_y_solution
24
+ request.session["precision"] = precision
25
+ return {
26
+ "width": width,
27
+ "height": height,
28
+ "piece_width": piece_width,
29
+ "piece_height": piece_height,
30
+ "pos_x_solution": pos_x_solution,
31
+ "pos_y_solution": pos_y_solution,
32
+ "piece_pos_x": piece_pos_x,
33
+ "piece_pos_y": piece_pos_y,
34
+ "image": f"{puzzle_images_path}{selected_image}",
35
+ }
36
+
37
+
38
+ def verify_captcha(request: HttpRequest) -> bool:
39
+ pos_x_answer = request.POST.get("pos_x_answer")
40
+ pos_y_answer = request.POST.get("pos_Y_answer")
41
+ if pos_x_answer is None or pos_y_answer is None:
42
+ return False
43
+ pos_x_solution = request.session.get("pos_x_solution")
44
+ pos_y_solution = request.session.get("pos_y_solution")
45
+ precision = request.session.get("precision")
46
+ if (
47
+ abs(pos_x_solution - pos_x_answer) <= precision
48
+ and abs(pos_y_solution - pos_y_answer) <= precision
49
+ ):
50
+ return True
51
+ else:
52
+ return False
@@ -0,0 +1,7 @@
1
+ import os
2
+
3
+ from django.core.wsgi import get_wsgi_application
4
+
5
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "captcha_prune.settings")
6
+
7
+ application = get_wsgi_application()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: prune_captcha
3
- Version: 1.12.2
3
+ Version: 1.14.0
4
4
  Summary: A tool to protect formulaire from spam.
5
5
  Author-email: Arnout <bastien@prune.sh>
6
6
  Project-URL: Made_by, https://prune.sh/
@@ -64,6 +64,8 @@ In `settings.py`, set the path to the images used for the puzzle:
64
64
  PUZZLE_IMAGE_STATIC_PATH = "website/static/website/images/puzzles/"
65
65
  ```
66
66
 
67
+ Important: You must import the static files (css, js) present in "captcha_prune/static/".
68
+
67
69
  ### Utilisation
68
70
 
69
71
  - GET request (form display)
@@ -114,6 +116,8 @@ PUZZLE_IMAGE_STATIC_PATH = "website/static/website/images/puzzles/"
114
116
 
115
117
  | Version | Date | Notes |
116
118
  | ------- | ---------- | ---------------------------------- |
119
+ | 1.14.0 | 2025-05-21 | fix static and templates dirs |
120
+ | 1.13.0 | 2025-05-21 | use session, add static |
117
121
  | 1.12.2 | 2025-05-21 | doc fixed |
118
122
  | 1.12.1 | 2025-05-21 | doc fixed |
119
123
  | 1.12.0 | 2025-05-21 | removed views, added utils, ... |
@@ -0,0 +1,13 @@
1
+ README.md
2
+ pyproject.toml
3
+ captcha_prune/__init__.py
4
+ captcha_prune/apps.py
5
+ captcha_prune/asgi.py
6
+ captcha_prune/settings.py
7
+ captcha_prune/utils.py
8
+ captcha_prune/wsgi.py
9
+ prune_captcha.egg-info/PKG-INFO
10
+ prune_captcha.egg-info/SOURCES.txt
11
+ prune_captcha.egg-info/dependency_links.txt
12
+ prune_captcha.egg-info/requires.txt
13
+ prune_captcha.egg-info/top_level.txt
@@ -1,4 +1,2 @@
1
1
  captcha_prune
2
- commons
3
2
  dist
4
- tests
@@ -20,7 +20,7 @@ classifiers = [
20
20
  keywords = ["captcha", "django", "code-quality"]
21
21
  urls = {Made_by = "https://prune.sh/"}
22
22
  name = "prune_captcha"
23
- version = "1.12.2"
23
+ version = "1.14.0"
24
24
  description = "A tool to protect formulaire from spam."
25
25
  readme = "README.md"
26
26
  dependencies = [
@@ -1,16 +0,0 @@
1
- """
2
- ASGI config for captcha_prune project.
3
-
4
- It exposes the ASGI callable as a module-level variable named ``application``.
5
-
6
- For more information on this file, see
7
- https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/
8
- """
9
-
10
- import os
11
-
12
- from django.core.asgi import get_asgi_application
13
-
14
- os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'captcha_prune.settings')
15
-
16
- application = get_asgi_application()
@@ -1,29 +0,0 @@
1
- # Generated by Django 5.2 on 2025-04-28 10:19
2
-
3
- import uuid
4
- from django.db import migrations, models
5
-
6
-
7
- class Migration(migrations.Migration):
8
-
9
- initial = True
10
-
11
- dependencies = [
12
- ]
13
-
14
- operations = [
15
- migrations.CreateModel(
16
- name='Captcha',
17
- fields=[
18
- ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19
- ('created_at', models.DateTimeField(auto_now_add=True)),
20
- ('updated_at', models.DateTimeField(auto_now=True)),
21
- ('uuid', models.UUIDField(default=uuid.uuid4, unique=True)),
22
- ('pos_x', models.IntegerField()),
23
- ('pos_y', models.IntegerField()),
24
- ],
25
- options={
26
- 'abstract': False,
27
- },
28
- ),
29
- ]
@@ -1,73 +0,0 @@
1
- # Generated by Django 5.2 on 2025-04-29 07:55
2
-
3
- from django.db import migrations, models
4
-
5
-
6
- class Migration(migrations.Migration):
7
- dependencies = [
8
- ("captcha_prune", "0001_initial"),
9
- ]
10
-
11
- operations = [
12
- migrations.RemoveField(
13
- model_name="captcha",
14
- name="created_at",
15
- ),
16
- migrations.RemoveField(
17
- model_name="captcha",
18
- name="pos_x",
19
- ),
20
- migrations.RemoveField(
21
- model_name="captcha",
22
- name="pos_y",
23
- ),
24
- migrations.RemoveField(
25
- model_name="captcha",
26
- name="updated_at",
27
- ),
28
- migrations.AddField(
29
- model_name="captcha",
30
- name="height",
31
- field=models.IntegerField(default=200),
32
- ),
33
- migrations.AddField(
34
- model_name="captcha",
35
- name="piece_height",
36
- field=models.IntegerField(default=50),
37
- ),
38
- migrations.AddField(
39
- model_name="captcha",
40
- name="piece_pos_x",
41
- field=models.IntegerField(blank=True, null=True),
42
- ),
43
- migrations.AddField(
44
- model_name="captcha",
45
- name="piece_pos_y",
46
- field=models.IntegerField(blank=True, null=True),
47
- ),
48
- migrations.AddField(
49
- model_name="captcha",
50
- name="piece_width",
51
- field=models.IntegerField(default=80),
52
- ),
53
- migrations.AddField(
54
- model_name="captcha",
55
- name="pos_x_solution",
56
- field=models.IntegerField(blank=True, null=True),
57
- ),
58
- migrations.AddField(
59
- model_name="captcha",
60
- name="pos_y_solution",
61
- field=models.IntegerField(blank=True, null=True),
62
- ),
63
- migrations.AddField(
64
- model_name="captcha",
65
- name="precision",
66
- field=models.IntegerField(default=2),
67
- ),
68
- migrations.AddField(
69
- model_name="captcha",
70
- name="width",
71
- field=models.IntegerField(default=350),
72
- ),
73
- ]
@@ -1,25 +0,0 @@
1
- # Generated by Django 5.2 on 2025-05-20 09:12
2
-
3
- import django.utils.timezone
4
- from django.db import migrations, models
5
-
6
-
7
- class Migration(migrations.Migration):
8
-
9
- dependencies = [
10
- ('captcha_prune', '0002_remove_captcha_created_at_remove_captcha_pos_x_and_more'),
11
- ]
12
-
13
- operations = [
14
- migrations.AddField(
15
- model_name='captcha',
16
- name='created_at',
17
- field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
18
- preserve_default=False,
19
- ),
20
- migrations.AddField(
21
- model_name='captcha',
22
- name='updated_at',
23
- field=models.DateTimeField(auto_now=True),
24
- ),
25
- ]
File without changes
@@ -1,34 +0,0 @@
1
- import random
2
- import uuid
3
-
4
- from django.db import models
5
-
6
- from commons.base_model import BaseModel
7
-
8
-
9
- class Captcha(BaseModel):
10
- uuid = models.UUIDField(default=uuid.uuid4, unique=True)
11
- width = models.IntegerField(default=350)
12
- height = models.IntegerField(default=200)
13
- pos_x_solution = models.IntegerField(null=True, blank=True)
14
- pos_y_solution = models.IntegerField(null=True, blank=True)
15
- piece_pos_x = models.IntegerField(null=True, blank=True)
16
- piece_pos_y = models.IntegerField(null=True, blank=True)
17
- piece_width = models.IntegerField(default=80)
18
- piece_height = models.IntegerField(default=50)
19
- precision = models.IntegerField(default=2)
20
-
21
- def save(self, *args, **kwargs):
22
- if self.pos_x_solution is None:
23
- self.pos_x_solution = random.randint(0, self.width - self.piece_width)
24
-
25
- if self.pos_y_solution is None:
26
- self.pos_y_solution = random.randint(0, self.height - self.piece_height)
27
-
28
- if self.piece_pos_x is None:
29
- self.piece_pos_x = random.randint(0, self.width - self.piece_width)
30
-
31
- if self.piece_pos_y is None:
32
- self.piece_pos_y = random.randint(0, self.height - self.piece_height)
33
-
34
- super().save(*args, **kwargs)
@@ -1,6 +0,0 @@
1
- from pydantic import BaseModel
2
-
3
-
4
- class PuzzleAnswerPayload(BaseModel):
5
- pos_x_answer: int
6
- pos_y_answer: int
@@ -1,44 +0,0 @@
1
- import os
2
- import random
3
-
4
- from django.conf import settings
5
- from django.shortcuts import get_object_or_404
6
-
7
- from captcha_prune.models import Captcha
8
-
9
-
10
- def create_and_get_captcha() -> dict:
11
- captcha = Captcha.objects.create()
12
-
13
- _, _, puzzle_images_path = settings.PUZZLE_IMAGE_STATIC_PATH.rpartition("static/")
14
- puzzle_images = [
15
- f
16
- for f in os.listdir(settings.PUZZLE_IMAGE_STATIC_PATH)
17
- if f.lower().endswith((".jpg", ".jpeg", ".png", ".gif", ".webp"))
18
- ]
19
- selected_image = random.choice(puzzle_images)
20
-
21
- return {
22
- "uuid": captcha.uuid,
23
- "width": captcha.width,
24
- "height": captcha.height,
25
- "piece_width": captcha.piece_width,
26
- "piece_height": captcha.piece_height,
27
- "pos_x_solution": captcha.pos_x_solution,
28
- "pos_y_solution": captcha.pos_y_solution,
29
- "piece_pos_x": captcha.piece_pos_x,
30
- "piece_pos_y": captcha.piece_pos_y,
31
- "image": f"{puzzle_images_path}{selected_image}",
32
- }
33
-
34
-
35
- def verify_captcha(puzzle_uuid: str, pos_x_answer: int, pos_y_answer: int) -> bool:
36
- captcha = get_object_or_404(Captcha, uuid=puzzle_uuid)
37
-
38
- if (
39
- abs(captcha.pos_x_solution - pos_x_answer) <= captcha.precision
40
- and abs(captcha.pos_y_solution - pos_y_answer) <= captcha.precision
41
- ):
42
- return True
43
- else:
44
- return False
@@ -1,16 +0,0 @@
1
- """
2
- WSGI config for captcha_prune project.
3
-
4
- It exposes the WSGI callable as a module-level variable named ``application``.
5
-
6
- For more information on this file, see
7
- https://docs.djangoproject.com/en/5.2/howto/deployment/wsgi/
8
- """
9
-
10
- import os
11
-
12
- from django.core.wsgi import get_wsgi_application
13
-
14
- os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'captcha_prune.settings')
15
-
16
- application = get_wsgi_application()
@@ -1,9 +0,0 @@
1
- from django.db import models
2
-
3
-
4
- class BaseModel(models.Model):
5
- created_at = models.DateTimeField(auto_now_add=True)
6
- updated_at = models.DateTimeField(auto_now=True)
7
-
8
- class Meta:
9
- abstract = True
@@ -1,23 +0,0 @@
1
- README.md
2
- pyproject.toml
3
- captcha_prune/__init__.py
4
- captcha_prune/apps.py
5
- captcha_prune/asgi.py
6
- captcha_prune/models.py
7
- captcha_prune/payloads.py
8
- captcha_prune/settings.py
9
- captcha_prune/utils.py
10
- captcha_prune/wsgi.py
11
- captcha_prune/migrations/0001_initial.py
12
- captcha_prune/migrations/0002_remove_captcha_created_at_remove_captcha_pos_x_and_more.py
13
- captcha_prune/migrations/0003_captcha_created_at_captcha_updated_at.py
14
- captcha_prune/migrations/__init__.py
15
- commons/base_model.py
16
- prune_captcha.egg-info/PKG-INFO
17
- prune_captcha.egg-info/SOURCES.txt
18
- prune_captcha.egg-info/dependency_links.txt
19
- prune_captcha.egg-info/requires.txt
20
- prune_captcha.egg-info/top_level.txt
21
- tests/__init__.py
22
- tests/captcha_prune/__init__.py
23
- tests/captcha_prune/test_views.py
File without changes
File without changes
@@ -1,67 +0,0 @@
1
- import uuid
2
-
3
- from django.test import TestCase
4
- from django.urls import reverse
5
-
6
- from captcha_prune.models import Captcha
7
-
8
-
9
- class CreateCaptchaViewTestCase(TestCase):
10
- def test_create_captcha_with_GET_method(self):
11
- response = self.client.get(reverse("create-captcha"))
12
- self.assertEqual(response.status_code, 405)
13
-
14
- def test_create_captcha_with_POST_method(self):
15
- response = self.client.post(reverse("create-captcha"))
16
- self.assertEqual(response.status_code, 201)
17
-
18
- data = response.json()
19
- captcha = Captcha.objects.get(uuid=data["uuid"])
20
- self.assertIsNotNone(captcha)
21
-
22
-
23
- class VerifyCaptchaViewTestCase(TestCase):
24
- def setUp(self):
25
- self.captcha = Captcha.objects.create()
26
- self.pos_x_solution = self.captcha.pos_x_solution
27
- self.pos_y_solution = self.captcha.pos_y_solution
28
-
29
- def test_verify_captcha_with_POST_method(self):
30
- response = self.client.post(
31
- reverse("verify-captcha", kwargs={"uuid": str(uuid.uuid4())}),
32
- data={
33
- "pos_x_answer": self.pos_x_solution,
34
- "pos_y_answer": self.pos_y_solution,
35
- },
36
- )
37
- self.assertEqual(response.status_code, 405)
38
-
39
- def test_verify_captcha_with_bad_uuid(self):
40
- response = self.client.get(
41
- reverse("verify-captcha", kwargs={"uuid": str(uuid.uuid4())}),
42
- data={
43
- "pos_x_answer": self.pos_x_solution,
44
- "pos_y_answer": self.pos_y_solution,
45
- },
46
- )
47
- self.assertEqual(response.status_code, 404)
48
-
49
- def test_verify_captcha_with_good_uuid_but_bad_answer(self):
50
- response = self.client.get(
51
- reverse("verify-captcha", kwargs={"uuid": str(self.captcha.uuid)}),
52
- data={
53
- "pos_x_answer": self.pos_x_solution - 20,
54
- "pos_y_answer": self.pos_y_solution - 20,
55
- },
56
- )
57
- self.assertEqual(response.status_code, 401)
58
-
59
- def test_verify_captcha_with_good_uuid_and_good_answer(self):
60
- response = self.client.get(
61
- reverse("verify-captcha", kwargs={"uuid": str(self.captcha.uuid)}),
62
- data={
63
- "pos_x_answer": self.pos_x_solution,
64
- "pos_y_answer": self.pos_y_solution,
65
- },
66
- )
67
- self.assertEqual(response.status_code, 304)
File without changes