简体   繁体   中英

Django LDAP Authentication in Production

I'm using an LDAP authentication module for logging into my django app. This works fine to log-in but I am having trouble with a function that use's:

request.user.is_authenticated():

This works fine on my dev machine (also using ldap), but on production will not return the information associated to the user. In particular, I am retrieving a set of events based on the users primary key.

eventList = Event.objects.filter(employee_id = request.user.pk)

The events exist (they are rendered within another view) and I'm quite sure it is that one statement. It is worth noting that although I've sub-classed User as follows, but the employees are created (I've checked in the admin interface):

class Employee(models.Model):
    # This field is required.
    user = models.OneToOneField(User)
    manager_id = models.ForeignKey('self', related_name = 'employees', null = True)

    def __unicode__(self):
     return self.user.username

def create_user_profile(sender, **kwargs):
    """When creating a new user, make an employee profile too."""
    u = kwargs["instance"]
    if not Employee.objects.filter(user = u):
        Employee(user=u).save()

post_save.connect(create_user_profile, sender = User)

Could anyone help?

This was down to my query. Basically, the original query was assuming that each Employee and User object has the same PK. This was OK in development, but didn't work in production as the keys didn't match.

Replacing the original query with the one below resolved things:

    employee = request.user.employee
    eventList = Event.objects.filter(employee_id = employee.pk)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM