Skip to content

Commit

Permalink
feat: remove redundant authenticate method (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
BustDot committed Aug 20, 2023
1 parent 86abe7b commit 8cbc97a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 64 deletions.
46 changes: 0 additions & 46 deletions .github/workflows/lint.yml

This file was deleted.

20 changes: 2 additions & 18 deletions dauthz/backends/casbin_backend.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import BaseBackend
from django.contrib.auth.backends import ModelBackend

from dauthz.core import enforcer, enforcers


UserModel = get_user_model()


class CasbinBackend(BaseBackend):
class CasbinBackend(ModelBackend):
"""
Check permissions with Casbin.
"""

def __init__(self):
self.enforcer = enforcer

def authenticate(self, request, username=None, password=None, **kwargs):
if username is None:
username = kwargs.get(UserModel.USERNAME_FIELD)
if username is None or password is None:
return
try:
user = UserModel._default_manager.get_by_natural_key(username)
except UserModel.DoesNotExist:
# Run the default password hasher once to reduce the timing
# difference between an existing and a nonexistent user (#20760).
UserModel().set_password(password)
else:
if user.check_password(password) and self.user_can_authenticate(user):
return user

def user_can_authenticate(self, user):
"""
Reject users with is_active=False. Custom user models that don't have
Expand Down

0 comments on commit 8cbc97a

Please sign in to comment.