2022-08-08 09:43:31 +00:00
|
|
|
from django.contrib.auth.backends import ModelBackend
|
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.contrib import messages
|
|
|
|
from django.conf import settings
|
|
|
|
|
2022-09-16 12:51:56 +00:00
|
|
|
from reportmonster.classes.vessel import Vessel
|
|
|
|
|
2022-08-08 09:43:31 +00:00
|
|
|
from bcrypt import checkpw
|
|
|
|
|
|
|
|
|
|
|
|
class ReportMonsterBackend(ModelBackend):
|
2022-09-16 12:51:56 +00:00
|
|
|
def authenticate(self, request, username: str = None, password: str = None):
|
2022-08-08 09:43:31 +00:00
|
|
|
self.request = request
|
|
|
|
|
2022-08-08 15:18:39 +00:00
|
|
|
monster = settings.MONSTERCONFIG
|
2022-09-16 12:51:56 +00:00
|
|
|
loginvessel = list(
|
|
|
|
filter(lambda x: x.name == settings.LOGIN_VESSEL, monster.vessels)
|
|
|
|
)[0]
|
2022-08-08 09:43:31 +00:00
|
|
|
|
2022-09-16 12:51:56 +00:00
|
|
|
userdata = list(loginvessel.getUsers(username=username).values())[0]
|
2022-08-08 09:43:31 +00:00
|
|
|
|
2022-09-16 12:51:56 +00:00
|
|
|
if checkpw(password.encode(), userdata["password"].encode()):
|
2022-08-08 09:43:31 +00:00
|
|
|
user, _ = get_user_model().objects.get_or_create(email=username)
|
|
|
|
user.save()
|
|
|
|
return user
|