def create_user(username, password, is_superuser=True): if ENABLE_ORGANIZATIONS.get(): organization = get_organization(email=username) lookup = {'email': username, 'organization': organization} else: lookup = {'username': username} LOG.info("Materializing user %s in the database" % lookup) user = User(**lookup) if password is None: user.set_unusable_password() else: user.set_password(password) user.is_superuser = is_superuser user.save() if ENABLE_ORGANIZATIONS.get(): user.is_admin = is_superuser or not organization.organizationuser_set.exists( ) or not organization.is_multi_user ensure_has_a_group(user) return user
def userAdmin(request): if request.method == 'GET': userList = User.objects.all() return HttpResponse(userList) if request.method == 'POST': name = request.POST.get('name', '') password = request.POST.get('password', '') active = request.POST.get('active', '') user = User(name=name, password=password, active=active) user.save() return HttpResponse('success')
def find_or_create_user(username, password=None): try: user = User.objects.get(username=username) LOG.debug("Found user %s in the db" % username) except User.DoesNotExist: LOG.info("Materializing user %s in the database" % username) user = User(username=username) if password is None: user.set_unusable_password() else: user.set_password(password) user.is_superuser = True user.save() return user
def create_user(username, password, is_superuser=True): if ENABLE_ORGANIZATIONS.get(): organization = get_organization(email=username) lookup = {'email': username, 'organization': organization} else: lookup = {'username': username} LOG.info("Materializing user %s in the database" % lookup) user = User(**lookup) if password is None: user.set_unusable_password() else: user.set_password(password) user.is_superuser = is_superuser user.save() return user
def create_user(username, password, is_superuser=True): if ENABLE_ORGANIZATIONS.get(): organization = get_organization(email=username) attrs = {'email': username, 'organization': organization} else: attrs = {'username': username} user = User(**attrs) if password is None: user.set_unusable_password() else: user.set_password(password) user.is_superuser = is_superuser if ENABLE_ORGANIZATIONS.get(): user.is_admin = is_superuser or not organization.organizationuser_set.exists() or not organization.is_multi_user user.save() ensure_has_a_group(user) user.save() LOG.info("User %s was created." % username) return user