Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated utcnow() by now() #1711

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions asreview/webapp/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@ def token_valid(self, provided_token, max_hours=24):
"""Checks whether provided token is correct and still valid"""
# there must be a token and a timestamp
if bool(self.token) and bool(self.token_created_at):
# what is now
now = dt.datetime.utcnow()
# get time-difference in hours
now = dt.datetime.now(dt.timezone.utc)
diff = (now - self.token_created_at).total_seconds()
# return if token is correct and we are still before deadline
return self.token == provided_token and diff <= max_hours * 3600
Expand All @@ -200,8 +198,7 @@ def generate_token_data(cls, secret, salt, email):
"""Generate a token for verification by email"""
serializer = URLSafeTimedSerializer(secret)
token = serializer.dumps(email, salt=salt)
created_at = dt.datetime.utcnow()
return token, created_at
return token, dt.datetime.now(dt.timezone.utc)

@classmethod
def valid_password(cls, password):
Expand Down