Skip to content

Commit 857d6dd

Browse files
authored
Merge pull request #24 from akirachix/develop
Develop
2 parents 56d302a + 07776f3 commit 857d6dd

File tree

4 files changed

+73
-6
lines changed

4 files changed

+73
-6
lines changed

api/views.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from django.shortcuts import render
2525
from rest_framework.authtoken.models import Token
2626
from django.contrib.auth import authenticate
27+
from django.core.cache import cache
2728

2829
from users.permissions import IsAdmin, IsUser
2930

@@ -174,8 +175,7 @@ def post(self, request):
174175
return Response({"detail": "User with this email does not exist."}, status=status.HTTP_400_BAD_REQUEST)
175176

176177
otp = str(random.randint(1000, 9999))
177-
otp_storage[email] = otp
178-
178+
cache.set(f'otp_{email}', otp, timeout=300)
179179
send_mail(
180180
'Your OTP for password reset',
181181
f'Your OTP is {otp}',
@@ -195,8 +195,12 @@ def post(self, request):
195195
email = serializer.validated_data['email']
196196
otp = serializer.validated_data['otp']
197197

198-
if otp_storage.get(email) != otp:
199-
return Response({"detail": "Invalid OTP."}, status=status.HTTP_400_BAD_REQUEST)
198+
cached_otp = cache.get(f'otp_{email}')
199+
if cached_otp is None:
200+
return Response({"detail": "OTP has expired, please request a new one."}, status=status.HTTP_400_BAD_REQUEST)
201+
elif cached_otp != otp:
202+
return Response({"detail": "Invalid OTP."}, status=status.HTTP_400_BAD_REQUEST)
203+
cache.delete(f'otp_{email}')
200204

201205
return Response({"detail": "OTP verified."})
202206

@@ -216,7 +220,7 @@ def post(self, request):
216220

217221
user.set_password(password)
218222
user.save()
219-
otp_storage.pop(email, None)
223+
cache.delete(f'otp_{email}')
220224
return Response({"detail": "Password reset successful."})
221225

222226

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Generated by Django 5.2.6 on 2025-09-19 06:56
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("cases", "0004_remove_caseassignment_lawyer_id_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="case",
15+
name="predicted_case_type",
16+
field=models.CharField(
17+
blank=True,
18+
choices=[
19+
("criminal", "Criminal"),
20+
("Environment", "environment"),
21+
("Employment", "employment"),
22+
("civil", "Civil"),
23+
(
24+
"constitutional and human rights",
25+
"Constitutional and Human Rights",
26+
),
27+
("family", "Family"),
28+
("labor", "Labor"),
29+
("property", "Property"),
30+
("other", "Other"),
31+
],
32+
max_length=50,
33+
null=True,
34+
),
35+
),
36+
]

cases/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Case(models.Model):
6565
case_description = models.TextField()
6666
predicted_case_type = models.CharField(
6767
max_length=50,
68-
choices=[('criminal', 'Criminal'), ('civil', 'Civil'), ('constitutional and human rights', 'Constitutional and Human Rights'), ('family', 'Family'), ('labor', 'Labor'), ('property', 'Property'), ('other', 'Other')],
68+
choices=[('criminal', 'Criminal'),('Environment','environment'),('Employment','employment'), ('civil', 'Civil'), ('constitutional and human rights', 'Constitutional and Human Rights'), ('family', 'Family'), ('labor', 'Labor'), ('property', 'Property'), ('other', 'Other')],
6969
null=True,
7070
blank=True
7171
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Generated by Django 5.2.6 on 2025-09-19 06:56
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("users", "0001_initial"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="user",
15+
name="role",
16+
field=models.CharField(
17+
choices=[
18+
("applicant", "Applicant"),
19+
("lawyer", "Lawyer"),
20+
("lsk_admin", "LSK Admin"),
21+
("admin", "Admin"),
22+
],
23+
default="applicant",
24+
max_length=100,
25+
),
26+
),
27+
]

0 commit comments

Comments
 (0)