sanic-security 1.15.0__py3-none-any.whl → 1.15.2__py3-none-any.whl
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.
- sanic_security/models.py +12 -8
- sanic_security/utils.py +7 -14
- {sanic_security-1.15.0.dist-info → sanic_security-1.15.2.dist-info}/METADATA +1 -1
- {sanic_security-1.15.0.dist-info → sanic_security-1.15.2.dist-info}/RECORD +7 -7
- {sanic_security-1.15.0.dist-info → sanic_security-1.15.2.dist-info}/LICENSE +0 -0
- {sanic_security-1.15.0.dist-info → sanic_security-1.15.2.dist-info}/WHEEL +0 -0
- {sanic_security-1.15.0.dist-info → sanic_security-1.15.2.dist-info}/top_level.txt +0 -0
sanic_security/models.py
CHANGED
@@ -2,6 +2,7 @@ import base64
|
|
2
2
|
import datetime
|
3
3
|
import logging
|
4
4
|
import re
|
5
|
+
import uuid
|
5
6
|
from typing import Union
|
6
7
|
|
7
8
|
import jwt
|
@@ -20,7 +21,6 @@ from sanic_security.utils import (
|
|
20
21
|
get_expiration_date,
|
21
22
|
image_generator,
|
22
23
|
audio_generator,
|
23
|
-
get_id,
|
24
24
|
is_expired,
|
25
25
|
)
|
26
26
|
|
@@ -58,7 +58,9 @@ class BaseModel(Model):
|
|
58
58
|
deleted (bool): Renders the model filterable without removing from the database.
|
59
59
|
"""
|
60
60
|
|
61
|
-
id: str = fields.CharField(
|
61
|
+
id: str = fields.CharField(
|
62
|
+
pk=True, max_length=36, default=lambda: str(uuid.uuid4())
|
63
|
+
)
|
62
64
|
date_created: datetime.datetime = fields.DatetimeField(auto_now_add=True)
|
63
65
|
date_updated: datetime.datetime = fields.DatetimeField(auto_now=True)
|
64
66
|
deleted: bool = fields.BooleanField(default=False)
|
@@ -196,7 +198,7 @@ class Account(BaseModel):
|
|
196
198
|
NotFoundError
|
197
199
|
"""
|
198
200
|
try:
|
199
|
-
return await Account.filter(email=email, deleted=False).get()
|
201
|
+
return await Account.filter(email=email.lower(), deleted=False).get()
|
200
202
|
except (DoesNotExist, ValidationError):
|
201
203
|
raise NotFoundError("Account with this email does not exist.")
|
202
204
|
|
@@ -504,7 +506,7 @@ class VerificationSession(Session):
|
|
504
506
|
"""
|
505
507
|
|
506
508
|
attempts: int = fields.IntField(default=0)
|
507
|
-
code: str = fields.CharField(max_length=6,
|
509
|
+
code: str = fields.CharField(max_length=6, null=True)
|
508
510
|
|
509
511
|
async def check_code(self, code: str) -> None:
|
510
512
|
"""
|
@@ -542,13 +544,14 @@ class TwoStepSession(VerificationSession):
|
|
542
544
|
|
543
545
|
@classmethod
|
544
546
|
async def new(cls, request: Request, account: Account, **kwargs):
|
545
|
-
return await
|
547
|
+
return await cls.create(
|
546
548
|
**kwargs,
|
547
549
|
ip=get_ip(request),
|
548
550
|
bearer=account,
|
549
551
|
expiration_date=get_expiration_date(
|
550
552
|
security_config.TWO_STEP_SESSION_EXPIRATION
|
551
553
|
),
|
554
|
+
code=get_code(True),
|
552
555
|
)
|
553
556
|
|
554
557
|
class Meta:
|
@@ -560,9 +563,10 @@ class CaptchaSession(VerificationSession):
|
|
560
563
|
|
561
564
|
@classmethod
|
562
565
|
async def new(cls, request: Request, **kwargs):
|
563
|
-
return await
|
566
|
+
return await cls.create(
|
564
567
|
**kwargs,
|
565
568
|
ip=get_ip(request),
|
569
|
+
code=get_code(),
|
566
570
|
expiration_date=get_expiration_date(
|
567
571
|
security_config.CAPTCHA_SESSION_EXPIRATION
|
568
572
|
),
|
@@ -639,7 +643,7 @@ class AuthenticationSession(Session):
|
|
639
643
|
if not is_expired(self.refresh_expiration_date):
|
640
644
|
self.active = False
|
641
645
|
await self.save(update_fields=["active"])
|
642
|
-
logging.
|
646
|
+
logging.info(
|
643
647
|
f"Client {get_ip(request)} has refreshed authentication session {self.id}."
|
644
648
|
)
|
645
649
|
return await self.new(request, self.bearer, True)
|
@@ -650,7 +654,7 @@ class AuthenticationSession(Session):
|
|
650
654
|
async def new(
|
651
655
|
cls, request: Request, account: Account = None, is_refresh=False, **kwargs
|
652
656
|
):
|
653
|
-
authentication_session = await
|
657
|
+
authentication_session = await cls.create(
|
654
658
|
**kwargs,
|
655
659
|
bearer=account,
|
656
660
|
ip=get_ip(request),
|
sanic_security/utils.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import datetime
|
2
2
|
import random
|
3
|
-
import
|
4
|
-
import uuid
|
3
|
+
from string import ascii_uppercase, digits
|
5
4
|
|
6
5
|
from argon2 import PasswordHasher
|
7
6
|
from captcha.audio import AudioCaptcha
|
@@ -53,28 +52,22 @@ def get_ip(request: Request) -> str:
|
|
53
52
|
return request.remote_addr or request.ip
|
54
53
|
|
55
54
|
|
56
|
-
def get_code() -> str:
|
55
|
+
def get_code(digits_only: bool = False) -> str:
|
57
56
|
"""
|
58
57
|
Generates random code to be used for verification.
|
59
58
|
|
59
|
+
Args:
|
60
|
+
digits_only: Determines if code should only contain digits.
|
61
|
+
|
60
62
|
Returns:
|
61
63
|
code
|
62
64
|
"""
|
63
65
|
return "".join(
|
64
|
-
random.choice(
|
66
|
+
random.choice(("" if digits_only else ascii_uppercase) + digits)
|
67
|
+
for _ in range(6)
|
65
68
|
)
|
66
69
|
|
67
70
|
|
68
|
-
def get_id() -> str:
|
69
|
-
"""
|
70
|
-
Generates uuid to be used for primary key.
|
71
|
-
|
72
|
-
Returns:
|
73
|
-
id
|
74
|
-
"""
|
75
|
-
return str(uuid.uuid4())
|
76
|
-
|
77
|
-
|
78
71
|
def is_expired(date):
|
79
72
|
"""
|
80
73
|
Checks if current date has surpassed the date passed into the function.
|
@@ -3,14 +3,14 @@ sanic_security/authentication.py,sha256=3Pit1B4PN_MRvwAlhYPHl_6DGD9JVpdPjgjiyKQJ
|
|
3
3
|
sanic_security/authorization.py,sha256=jAxfDT9cHN_zpMKcA3oYFZ5Eu2KItnMJZ7oPcqmMwrw,7537
|
4
4
|
sanic_security/configuration.py,sha256=_E66ts5g9t_XHW9ZAnr48rWVcZmGNu_DWGDxm_AVVWE,5681
|
5
5
|
sanic_security/exceptions.py,sha256=9zISLyAvP6qN8sNR8e5qxKP__FA4NLIXCun_fEKndOw,5297
|
6
|
-
sanic_security/models.py,sha256=
|
7
|
-
sanic_security/utils.py,sha256=
|
6
|
+
sanic_security/models.py,sha256=1gMoPnzA9cpJaZXJ1GtgAzsXxGO-rts-f3YyVgcd7lY,22475
|
7
|
+
sanic_security/utils.py,sha256=Il5MjFzVe975yx_CV2HV_LVQYl2W3XYDRGtCG5CQA8Q,3531
|
8
8
|
sanic_security/verification.py,sha256=9bi8-NZ8GE3rcuELZ63yh18zDg8RxvxGPkhAu5SzLn0,8692
|
9
9
|
sanic_security/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
10
|
sanic_security/test/server.py,sha256=RjL9Kfvkfqpm5TXWwFQKKa0J4hfTKgwI6U0s_TAKO8w,11984
|
11
11
|
sanic_security/test/tests.py,sha256=bW5fHJfsCrg8eBmcSqVMLm0R5XRL1ou-XJJRgz09GOE,21993
|
12
|
-
sanic_security-1.15.
|
13
|
-
sanic_security-1.15.
|
14
|
-
sanic_security-1.15.
|
15
|
-
sanic_security-1.15.
|
16
|
-
sanic_security-1.15.
|
12
|
+
sanic_security-1.15.2.dist-info/LICENSE,sha256=sXlJs9_mG-dCkPfWsDnuzydJWagS82E2gYtkVH9enHA,1100
|
13
|
+
sanic_security-1.15.2.dist-info/METADATA,sha256=PNjYIu36zcUqehxfO0Zg7X98CwHSzGbPc1FYXsXo7qs,23247
|
14
|
+
sanic_security-1.15.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
15
|
+
sanic_security-1.15.2.dist-info/top_level.txt,sha256=ZybkhHXSjfzhmv8XeqLvnNmLmv21Z0oPX6Ep4DJN8b0,15
|
16
|
+
sanic_security-1.15.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|