forked from yahyaaly151989/Mastering_Django
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Building a custom authentication backend
- Loading branch information
1 parent
1f2763b
commit a6540ef
Showing
5 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
Binary file added
BIN
+1.39 KB
Module04/bookmarks/account/__pycache__/authentication.cpython-311.pyc
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django.contrib.auth.models import User | ||
|
||
class EmailAuthBackend(): | ||
def authenticate(self, request, username=None, password=None): | ||
try: | ||
user = User.objects.get(email=username) | ||
if user.check_password(password): | ||
return user | ||
return None | ||
except (User.DoesNotExist, User.MultipleObjectsReturned): | ||
return None | ||
|
||
def get_user(self, user_id): | ||
try: | ||
return User.objects.get(pk=user_id) | ||
except User.DoesNotExist: | ||
return None |
Binary file modified
BIN
+135 Bytes
(100%)
Module04/bookmarks/bookmarks/__pycache__/settings.cpython-311.pyc
Binary file not shown.
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
Binary file not shown.