mirror of
https://github.com/retspen/webvirtcloud
synced 2024-11-01 03:54:15 +00:00
using custom accounts.backends.MyRemoteUserBackend, which adds default instances and attributes for user
create_missing_userattributes removed from accounts view
This commit is contained in:
parent
609651d707
commit
fe89af9d8f
3 changed files with 26 additions and 13 deletions
|
@ -1,7 +1,30 @@
|
|||
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
|
||||
#user.is_superuser = True
|
||||
self.create_missing_userattributes(user)
|
||||
self.add_default_instances(user)
|
||||
return user
|
||||
|
||||
|
|
|
@ -70,21 +70,11 @@ def accounts(request):
|
|||
:param request:
|
||||
:return:
|
||||
"""
|
||||
|
||||
def create_missing_userattributes(users):
|
||||
for user in users:
|
||||
try:
|
||||
userattributes = user.userattributes
|
||||
except UserAttributes.DoesNotExist:
|
||||
userattributes = UserAttributes(user=user)
|
||||
userattributes.save()
|
||||
|
||||
if not request.user.is_superuser:
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
|
||||
error_messages = []
|
||||
users = User.objects.all().order_by('username')
|
||||
create_missing_userattributes(users)
|
||||
allow_empty_password = settings.ALLOW_EMPTY_PASSWORD
|
||||
|
||||
if request.method == 'POST':
|
||||
|
|
|
@ -45,8 +45,8 @@ MIDDLEWARE_CLASSES = (
|
|||
)
|
||||
|
||||
AUTHENTICATION_BACKENDS = (
|
||||
'django.contrib.auth.backends.RemoteUserBackend',
|
||||
#'accounts.backends.MyRemoteUserBackend',
|
||||
#'django.contrib.auth.backends.RemoteUserBackend',
|
||||
'accounts.backends.MyRemoteUserBackend',
|
||||
)
|
||||
|
||||
LOGIN_URL = '/accounts/login'
|
||||
|
|
Loading…
Reference in a new issue