Merge remote-tracking branch 'origin/auth' into razrab
This commit is contained in:
commit
1e5d62675e
2 files changed
+47
-25
No files matched your search
+46
-24
@@ -13,21 +13,30 @@ from rest_framework_simplejwt.views import TokenObtainPairView
|
|||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
myDEBUG=True
|
myDEBUG=True
|
||||||
|
|
||||||
|
# class Authexception(Exception):
|
||||||
|
# def __init__(self, *args):
|
||||||
|
# self.message = args[0] if args else "None"
|
||||||
|
|
||||||
class MyTokenObtainPairSerializer(TokenObtainPairSerializer):
|
class MyTokenObtainPairSerializer(TokenObtainPairSerializer):
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_token(cls, user):
|
def get_token(cls, user):
|
||||||
|
try:
|
||||||
|
token = super().get_token(user.userinfo)
|
||||||
|
|
||||||
token = super().get_token(user.userinfo)
|
# TODO В зависимости от базы Алексея, добавить поля или нет - надо подумать
|
||||||
|
|
||||||
# TODO В зависимости от базы Алексея, добавить поля или нет - надо подумать
|
|
||||||
|
|
||||||
|
|
||||||
token['user']=model_to_dict(user.userinfo)
|
token['user']=model_to_dict(user.userinfo)
|
||||||
token['user']['is_active']=user.is_active
|
token['user']['is_active']=user.is_active
|
||||||
token['user']['is_staff']=user.is_staff
|
token['user']['is_staff']=user.is_staff
|
||||||
# !ТУТ СДЕЛАТь ФОТО НАВЕРНОЕ
|
# !ТУТ СДЕЛАТь ФОТО НАВЕРНОЕ
|
||||||
# token['user']['last_login']= user.last_login
|
# token['user']['last_login']= user.last_login
|
||||||
return token
|
# print(token)
|
||||||
|
return token
|
||||||
|
except Exception as e:
|
||||||
|
print("ERRRORRRRRRRR")
|
||||||
|
print (e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -41,29 +50,42 @@ class CustomAuth(ModelBackend):
|
|||||||
username = kwargs['username']
|
username = kwargs['username']
|
||||||
password = kwargs['password']
|
password = kwargs['password']
|
||||||
status_code=0
|
status_code=0
|
||||||
|
|
||||||
# !ТУт стучим в AD, потом к Алексею
|
# !ТУт стучим в AD, потом к Алексею
|
||||||
if myDEBUG!=True:
|
if myDEBUG!=True:
|
||||||
|
|
||||||
resp= requests.post('http://10.252.44.13:8005/getAD', json.dumps({'user': username, 'password':password, 'usercheck': username}))
|
resp= requests.post('http://10.252.44.13:8005/getAD', json.dumps({'user': username, 'password':password, 'usercheck': username}))
|
||||||
|
|
||||||
# if True:
|
# if True:
|
||||||
status_code=resp.status_code
|
status_code=resp.status_code
|
||||||
else:
|
else:
|
||||||
status_code=200
|
status_code=200
|
||||||
|
|
||||||
if status_code==200:
|
if status_code==200:
|
||||||
try:
|
# try:
|
||||||
|
|
||||||
|
user = DictEmployee.objects.using('user_directory').get(login=username)
|
||||||
|
|
||||||
|
if user.deleted!=1:
|
||||||
|
homeuser, created = User.objects.get_or_create(username=username)
|
||||||
|
if created:
|
||||||
|
homeuser.set_unusable_password()
|
||||||
|
|
||||||
|
homeuser.last_login= timezone.now()
|
||||||
|
user.is_active=homeuser.is_active
|
||||||
|
user.is_staff=homeuser.is_staff
|
||||||
|
user.last_login=homeuser.last_login.strftime('%Y-%d-%m %H:%M:%S')
|
||||||
|
homeuser.save()
|
||||||
|
homeuser.last_login=user.last_login
|
||||||
|
user.id=homeuser.id
|
||||||
|
homeuser.userinfo = user
|
||||||
|
# print("OOOOOOOOOOOOOOOOOOOO")
|
||||||
|
# print(homeuser)
|
||||||
|
return homeuser
|
||||||
|
|
||||||
|
# except Exception as e:
|
||||||
|
# print (e)
|
||||||
|
elif status_code==403:
|
||||||
|
return None
|
||||||
|
|
||||||
user = DictEmployee.objects.using('user_directory').get(login=username)
|
|
||||||
if user.deleted!=1:
|
|
||||||
homeuser, created = User.objects.get_or_create(username=username)
|
|
||||||
homeuser.last_login= timezone.now()
|
|
||||||
user.is_active=homeuser.is_active
|
|
||||||
user.is_staff=homeuser.is_staff
|
|
||||||
user.last_login=homeuser.last_login.strftime('%Y-%d-%m %H:%M:%S')
|
|
||||||
homeuser.save()
|
|
||||||
homeuser.last_login=user.last_login
|
|
||||||
user.id=homeuser.id
|
|
||||||
homeuser.userinfo = user
|
|
||||||
return homeuser
|
|
||||||
|
|
||||||
except User.DoesNotExist:
|
|
||||||
pass
|
|
||||||
@@ -60,7 +60,7 @@ class User(AbstractBaseUser, PermissionsMixin):
|
|||||||
updated_at = models.DateTimeField(auto_now=True)
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
# last_login = models.DateTimeField(auto_now=True, null=True)
|
# last_login = models.DateTimeField(auto_now=True, null=True)
|
||||||
# external=models.ForeignKey(DictEmployee,db_constraint=False, null=True, on_delete=models.PROTECT)
|
# external=models.ForeignKey(DictEmployee,db_constraint=False, null=True, on_delete=models.PROTECT)
|
||||||
objects = UserManager()
|
# objects = UserManager()
|
||||||
USERNAME_FIELD = 'username'
|
USERNAME_FIELD = 'username'
|
||||||
# REQUIRED_FIELDS = ['username']
|
# REQUIRED_FIELDS = ['username']
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|||||||
Reference in new issue
Block a user