I want to create an App for Customers where every customer has its own DB. So as Login information they need to enter three different fields: customernumber, username, password.
The username and password should do the normal authentication stuff and the customernumber is there to go to the right database user table for authentication i can go to other databases through the using() function.
class CustomAuthBackend(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
user = CustomUser.objects.using(request.POST['kundennr']).get(username=username)
if user.check_password(password) and self.user_can_authenticate(user) :
try:
user = CustomUser.objects.using(request.POST['kundennr']).get(username=username)
return user
except User.DoesNotExist:
return None
def get_user(self, user_id):
try:
return CustomUser.objects.get(pk=user_id)
except User.DoesNotExist:
return None
The authentication function works fine that way the problem i have is the get_user function i guess because the get_user function has no request where i can define which database it should call on. because everytime i call {% if user.is_authenticated %}
it goes to the default database and says user is Anonymous.
I dont know the right way to solve this problem is my solution just wrong?