1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 23:25:24 +00:00
webvirtcloud/accounts/backends.py
Ing. Jan KRCMAR fe89af9d8f using custom accounts.backends.MyRemoteUserBackend, which adds default instances and attributes for user
create_missing_userattributes removed from accounts view
2017-03-31 14:29:27 +02:00

30 lines
1.1 KiB
Python

from django.contrib.auth.backends import RemoteUserBackend
from accounts.models import UserInstance, UserAttributes
from instances.models import Instance
class MyRemoteUserBackend(RemoteUserBackend):
#create_unknown_user = True
default_instances = [ 'debian8-template' ]
def create_missing_userattributes(self, user):
try:
userattributes = user.userattributes
except UserAttributes.DoesNotExist:
userattributes = UserAttributes(user=user)
userattributes.save()
def add_default_instances(self, user):
existing_instances = UserInstance.objects.filter(user=user)
if not existing_instances:
for instance_name in self.default_instances:
instance = Instance.objects.get(name=instance_name)
user_instance = UserInstance(user=user, instance=instance)
user_instance.save()
def configure_user(self, user):
#user.is_superuser = True
self.create_missing_userattributes(user)
self.add_default_instances(user)
return user