logo
down
shadow

django-ldap-auth user profile in django > 1.7


django-ldap-auth user profile in django > 1.7

By : Mac6288
Date : November 21 2020, 11:01 PM
around this issue I solved this using one-to-one User profile model and populate_user signal emitted by django-ldap-auth.
code :
from __future__ import unicode_literals
import django_auth_ldap.backend
from fences.models import Profile
from django.db import models

def populate_user_profile(sender, user=None, ldap_user=None, **kwargs):
  temp_profile = None
  bucket = {}

  try:
      temp_profile = user.profile
  except:
      temp_profile = Profile.objects.create(user=user)

  bucket['street_address'] = ldap_user.attrs.get('streetAddress')
  bucket['telephone_number'] = ldap_user.attrs.get('telephoneNumber')
  bucket['title'] = ldap_user.attrs.get('title')

  for key, value in bucket.items():
      if value:
          setattr(user.profile, key, value[0].encode('utf-8'))
  user.profile.save()

django_auth_ldap.backend.populate_user.connect(populate_user_profile)


Share : facebook icon twitter icon
django auth ldap with custom user model

django auth ldap with custom user model


By : Ljiljana Bystedt
Date : March 29 2020, 07:55 AM
To fix this issue This is the part of django_auth_ldap's models.py -
code :
class TestProfile(models.Model):
    """
    A user profile model for use by unit tests. This has nothing to do with the
    authentication backend itself.
    """
    user = models.OneToOneField('auth.User')  # <-- here is the trouble
    is_special = models.BooleanField(default=False)
    populated = models.BooleanField(default=False)
django-auth-ldap - Display user information from LDAP in custom view

django-auth-ldap - Display user information from LDAP in custom view


By : Winnie Simango
Date : March 29 2020, 07:55 AM
wish helps you in the end auth.authenticate was missing and i had to rtfm:
Storing additional information about users this is the preferred way to get user information instead the way i was looking for.
code :
AUTH_LDAP_PROFILE_ATTR_MAP = {
    "uid": "uid",
    "cn": "cn",
    "sn": "sn",
    "givenName": "givenName",
    "userPassword": "userPassword",
    "shadowLastChange": "shadowLastChange",
    "shadowMax": "shadowMax",
    "shadowWarning": "shadowWarning",
    "loginShell": "loginShell",
    "uidNumber": "uidNumber",
    "gidNumber": "gidNumber",
    "homeDirectory": "homeDirectory",
    "gecos": "gecos",
    "mail": "mail",
    "l": "l",
    "telephoneNumber": "telephoneNumber",
}
AUTH_PROFILE_MODULE = 'myapp.UserProfile'
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save

class UserProfile(models.Model):
    # This field is required.
    user = models.OneToOneField(User)
    # Other fields here
    uid = models.CharField(max_length=254)
    cn = models.CharField(max_length=254)
    sn = models.CharField(max_length=254)
    givenName = models.CharField(max_length=254)
    userPassword = models.CharField(max_length=254)
    shadowLastChange = models.IntegerField(null=True)
    shadowMax = models.IntegerField(null=True)
    shadowWarning = models.IntegerField(null=True)
    loginShell = models.CharField(max_length=254)
    uidNumber = models.IntegerField(null=True)
    gidNumber = models.IntegerField(null=True)
    homeDirectory = models.CharField(max_length=254)
    gecos = models.CharField(max_length=254)
    mail = models.EmailField(max_length=254)
    l = models.CharField(max_length=254)
    telephoneNumber = models.CharField(max_length=254)

def create_user_profile(sender, instance, created, **kwargs):
    #if created:
    #    UserProfile.objects.create(user=instance)
    UserProfile.objects.get_or_create(user=instance)

post_save.connect(create_user_profile, sender=User)
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseRedirect
from django.shortcuts import render
from myapp.models import UserProfile

@login_required
def userinfo(request):
    try:
        ldapuserprofile = UserProfile.objects.get(uid=request.user.username)
    except UserProfile.DoesNotExist:
        return HttpResponseRedirect('/login/')
    context = {'request': request, 'ldapuser': ldapuserprofile,}
    return render(request, 'myapp/userinfo.html', context)
Django Auth is not finding User Account in LDAP

Django Auth is not finding User Account in LDAP


By : Nishi
Date : March 29 2020, 07:55 AM
help you fix your problem Finally... I must to use samAccountName instead of CN. I hope it help you all. guys.
Django edit auth user profile

Django edit auth user profile


By : MikeMahaffey
Date : March 29 2020, 07:55 AM
Any of those help I'm new to Django and writing an application in Django 1.11.
code :
class UpdateProfile(UpdateView):
    model = User
    fields = ['first_name', 'last_name']

    template_name = 'accounts/update.html'

    def get_object(self):
        return self.request.user
url(r'^update/(?P<pk>\d+)', views.UpdateProfile.as_view(), name='update')
django-auth-ldap - find if user belongs to a ldap group

django-auth-ldap - find if user belongs to a ldap group


By : Даша Котеленец
Date : March 29 2020, 07:55 AM
it fixes the issue I am trying to configure ldap authentication for a django project. Where all users should be able to access the web services ( I achieved this ). I would like to make few people (part of ldap group) as admins. I need to verify if logged in user belongs to a ldap group. , My problem is solved.
Related Posts Related Posts :
  • Why for loop is splitting strings of user input?
  • How can I add two variable and assign to result variable in Python?
  • Error when parsing timestamp with pandas read_csv
  • Slicing arrays based on boolean array in python
  • Feeding scipy.sparse() sparse matrices into CVXOPT
  • How to separate a irregularly cased string to get the words? - Python
  • Pandas: replace some values in column if that contain a substring
  • Fabric does not close the ssh connection
  • Python Creating Classes Code
  • When will train() method in easy_seq2seq stop?
  • How to split each element of the RDD in spark with python?
  • Read in csv file in python, round the values and write back to file
  • How to properly close a QWidget-window in an API with PythonQt
  • How to know which segment a value reside in
  • pandas: convert multiple categories to dummies
  • 'Options' object has no attribute 'get_all_field_names'
  • Customize django filter model field
  • NLTK tag Dutch sentence
  • How to assign a column in 2d-array to some repetitive range using Python?
  • Is there any way to use one static folder for all apps in django project
  • Python Websockets Module has no attribute
  • Python generator next method
  • Is it possible to make pygame work with a slightly newer version of python?
  • to show the weights of edges in a projected network
  • as the missing method of QTabWidget of this code is written?
  • Python - return multiple values using tuple (AWS lambda function)
  • How can I get the text use xpath from the text?
  • Python generator function - is there an excel equivalent?
  • Pandas: fastest way to resolve IP to country
  • Saving huge amount of data (nearly 20 billion entries) in django postgresql
  • Is there a difference between != and <> operators in Python?
  • How to move pointer to specific bytes and read using Pickle Library in Python?
  • Create 2-d array with column keys and row keys in Python
  • Detect match failure in JMESPath
  • python3 django1.8 mysql5.5 gives page not found (404) while sqlite works fine
  • Django forms: List of checkboxes populated from a model
  • Deploying django static files in production
  • How to find the alignment of two data sets in pandas
  • antlr4 + python: debug token match
  • How to 'blit' sprites onto window for a set time
  • Program that checks if a number is prime number
  • python pandas time line graph
  • Reading a text file with OpenCV in Python
  • PyGame in MacOSX: CGContextDrawImage: invalid context 0x0
  • Twisted chat server demo exits immediately
  • How to calculate block averages in pandas DataFrame
  • how to change a list to a specific string.
  • Overlapping text when saving multiple Matplotlib images with text in a loop
  • How do I scrape ONLY <div class ='quotetext'> from a website using python?
  • Python: Float Object is not Iterable
  • ValueError: need more than 3 values to unpack
  • Evaluate while loop at certain point?
  • RxPy - Why are emissions interleaved with merging operators?
  • Spyder - hints disappear too fast
  • Creating a |N| x |M| matrix from a hash-table
  • daily data, resample every 3 days, calculate over trailing 5 days efficiently
  • How to do this program without a counter?
  • Saving a data frame with a column of list in python
  • Python newbie - refactor string function
  • TypeError: deafultdict must have first arguments callable
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com