-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
95 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
import typing as t | ||
|
||
from django.contrib.auth.backends import BaseBackend | ||
from django.http.request import HttpRequest | ||
|
||
from ....request import WSGIRequest | ||
from ...models import User | ||
|
||
|
||
class EmailAndPasswordBackend(BaseBackend): | ||
"""Authenticates if the password belongs to the anon user's email.""" | ||
|
||
def authenticate( | ||
self, | ||
request: WSGIRequest, | ||
request: t.Optional[HttpRequest], | ||
email: t.Optional[str] = None, | ||
password: t.Optional[str] = None, | ||
**kwargs | ||
): | ||
if email is None or password is None: | ||
return | ||
return None | ||
|
||
try: | ||
user = User.objects.get(email=email) | ||
if user.check_password(password): | ||
return user | ||
except User.DoesNotExist: | ||
return | ||
return None | ||
|
||
return None | ||
|
||
def get_user(self, user_id: int): | ||
try: | ||
return User.objects.get(id=user_id) | ||
except User.DoesNotExist: | ||
return | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,11 @@ | |
"pk": 1, | ||
"fields": { | ||
"last_saved_at": "2023-01-01 00:00:00.0+00:00", | ||
"is_active": true, | ||
"first_name": "John", | ||
"last_name": "Doe", | ||
"email": "[email protected]", | ||
"password": "password", | ||
"password": "pbkdf2_sha256$260000$a2nFLqpwD88sOeZ7wsQskW$WIJACyDluEJWKMPsO/jawrR0sHXHmYebDJoyUihKJxU=", | ||
"teacher": 1 | ||
} | ||
}, | ||
|
@@ -16,10 +17,11 @@ | |
"pk": 2, | ||
"fields": { | ||
"last_saved_at": "2023-01-01 00:00:00.0+00:00", | ||
"is_active": true, | ||
"first_name": "Jane", | ||
"last_name": "Doe", | ||
"email": "[email protected]", | ||
"password": "password", | ||
"password": "pbkdf2_sha256$260000$a2nFLqpwD88sOeZ7wsQskW$WIJACyDluEJWKMPsO/jawrR0sHXHmYebDJoyUihKJxU=", | ||
"teacher": 2 | ||
} | ||
}, | ||
|
@@ -28,8 +30,9 @@ | |
"pk": 3, | ||
"fields": { | ||
"last_saved_at": "2023-01-01 00:00:00.0+00:00", | ||
"is_active": true, | ||
"first_name": "SpongeBob", | ||
"password": "password", | ||
"password": "pbkdf2_sha256$260000$a2nFLqpwD88sOeZ7wsQskW$WIJACyDluEJWKMPsO/jawrR0sHXHmYebDJoyUihKJxU=", | ||
"student": 1 | ||
} | ||
}, | ||
|
@@ -38,8 +41,9 @@ | |
"pk": 4, | ||
"fields": { | ||
"last_saved_at": "2023-01-01 00:00:00.0+00:00", | ||
"is_active": true, | ||
"first_name": "Patrick", | ||
"password": "password", | ||
"password": "pbkdf2_sha256$260000$a2nFLqpwD88sOeZ7wsQskW$WIJACyDluEJWKMPsO/jawrR0sHXHmYebDJoyUihKJxU=", | ||
"student": 2 | ||
} | ||
}, | ||
|
@@ -48,10 +52,11 @@ | |
"pk": 5, | ||
"fields": { | ||
"last_saved_at": "2023-01-01 00:00:00.0+00:00", | ||
"is_active": true, | ||
"first_name": "Indiana", | ||
"last_name": "Jones", | ||
"email": "[email protected]", | ||
"password": "password" | ||
"password": "pbkdf2_sha256$260000$a2nFLqpwD88sOeZ7wsQskW$WIJACyDluEJWKMPsO/jawrR0sHXHmYebDJoyUihKJxU=" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters