Skip to content

Commit

Permalink
Black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
na-stewart committed Jun 21, 2024
1 parent 4b7d00e commit 8aae20a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
4 changes: 3 additions & 1 deletion sanic_security/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ async def register(
phone=validate_phone(request.form.get("phone"))
).exists()
):
raise CredentialsError("An account with this phone number may already exist.", 409)
raise CredentialsError(
"An account with this phone number may already exist.", 409
)
validate_password(request.form.get("password"))
account = await Account.create(
email=email_lower,
Expand Down
35 changes: 22 additions & 13 deletions sanic_security/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@ def validate(self) -> None:
raise DeletedError("Session has been deleted.")
elif not self.active:
raise DeactivatedError()
elif self.expiration_date and datetime.datetime.now(datetime.timezone.utc) >= self.expiration_date:
elif (
self.expiration_date
and datetime.datetime.now(datetime.timezone.utc) >= self.expiration_date
):
raise ExpiredError()

async def deactivate(self):
Expand Down Expand Up @@ -282,7 +285,9 @@ def encode(self, response: HTTPResponse) -> None:
"date_created": str(self.date_created),
"expiration_date": str(self.expiration_date),
"ip": self.ip,
}, security_config.SECRET, security_config.SESSION_ENCODING_ALGORITHM
},
security_config.SECRET,
security_config.SESSION_ENCODING_ALGORITHM,
)
if isinstance(encoded_session, bytes):
encoded_session = encoded_session.decode()
Expand All @@ -309,7 +314,10 @@ async def location_familiarity(self, request):
UnfamiliarLocationError
"""
client_ip = get_ip(request)
if client_ip != self.ip and not await self.filter(ip=client_ip, deleted=False).exists():
if (
client_ip != self.ip
and not await self.filter(ip=client_ip, deleted=False).exists()
):
raise UnfamiliarLocationError()

@property
Expand All @@ -329,18 +337,18 @@ def json(self) -> dict:
"date_created": str(self.date_created),
"date_updated": str(self.date_updated),
"expiration_date": str(self.expiration_date),
"bearer": self.bearer.username
if isinstance(self.bearer, Account)
else None,
"bearer": (
self.bearer.username if isinstance(self.bearer, Account) else None
),
"active": self.active,
}

@classmethod
async def new(
cls,
request: Request,
account: Account,
**kwargs: Union[int, str, bool, float, list, dict],
cls,
request: Request,
account: Account,
**kwargs: Union[int, str, bool, float, list, dict],
):
"""
Creates session with pre-set values.
Expand Down Expand Up @@ -396,8 +404,9 @@ def decode_raw(cls, request: Request) -> dict:
raise JWTDecodeError("Session token not provided or expired.", 401)
else:
return jwt.decode(
cookie, security_config.PUBLIC_SECRET or security_config.SECRET,
security_config.SESSION_ENCODING_ALGORITHM
cookie,
security_config.PUBLIC_SECRET or security_config.SECRET,
security_config.SESSION_ENCODING_ALGORITHM,
)
except DecodeError as e:
raise JWTDecodeError(str(e))
Expand Down Expand Up @@ -587,7 +596,7 @@ async def new(cls, request: Request, account: Account, **kwargs):
),
refresh_date=get_expiration_date(
security_config.AUTHENTICATION_REFRESH_EXPIRATION
)
),
)

class Meta:
Expand Down
2 changes: 2 additions & 0 deletions sanic_security/test/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@
app = Sanic("sanic-security-test")
password_hasher = PasswordHasher()


# TODO: Testing for new functionality.


@app.post("api/test/auth/register")
async def on_register(request):
"""
Expand Down

0 comments on commit 8aae20a

Please sign in to comment.