Tuesday, October 24, 2017

LDAP Authentication: Extending User Model to an existing table

I'm currently using 'django_python3_ldap.auth.LDAPBackend' with Django 1.9 and Python 3, which I have working correctly were a user authenticates with their network login / password then a user is created in the data base with username, password, email, first_name, and last_name, user_created_at all extracted from LDAP, which is what I want to stay the same.

Now The network login is the username in the auth_user table. I have another table, which stores user information with a field titled employee_ntname, the table below is a pre-existing table in the database which can not be changed or updated for this use case.

class AllEeActive(models.Model):    employee_ntname = models.CharField(db_column='Employee_NTName',max_length=50)  # Field name made lowercase.  employee_last_name = models.CharField(db_column='Employee_Last_Name', max_length=50, blank=True, null=True)  # Field name made lowercase.  employee_first_name = models.CharField(db_column='Employee_First_Name', max_length=50, blank=True, null=True)  # Field name made lowercase.  b_level = models.CharField(db_column='B_Level', max_length=10, blank=True, null=True)  # Field name made lowercase.  group_name = models.CharField(db_column='Group_Name', max_length=100, blank=True, null=True)  # Field name made lowercase.  r_level = models.CharField(db_column='R_Level', max_length=10, blank=True, null=True)  # Field name made lowercase.  division_name = models.CharField(db_column='Division_Name', max_length=100, blank=True, null=True)  # Field name made lowercase.  d_level = models.CharField(db_column='D_Level', max_length=10, blank=True, null=True)  # Field name made lowercase.  market_name = models.CharField(db_column='Market_Name', max_length=100, blank=True, null=True)  # Field name made lowercase.  coid = models.CharField(db_column='COID', max_length=50, blank=True, null=True)  # Field name made lowercase.  unit_no = models.CharField(db_column='Unit_No', max_length=50, blank=True, null=True)  # Field name made lowercase.  dept_no = models.CharField(db_column='Dept_No', max_length=50, blank=True, null=True)  # Field name made lowercase.  department_desc = models.CharField(db_column='Department_Desc', max_length=50, blank=True, null=True)  # Field name made lowercase.  employee_status = models.CharField(db_column='Employee_Status', max_length=50, blank=True, null=True)  # Field name made lowercase.  job_desc = models.CharField(db_column='Job_Desc', max_length=50, blank=True, null=True)  # Field name made lowercase.  position_desc = models.CharField(db_column='Position_Desc', max_length=50, blank=True, null=True)  # Field name made lowercase.  supervisor_last_name = models.CharField(db_column='Supervisor_Last_Name', max_length=50, blank=True, null=True)  # Field name made lowercase.  supervisor_first_name = models.CharField(db_column='Supervisor_First_Name', max_length=50, blank=True, null=True)  # Field name made lowercase.  supervisor_job_desc = models.CharField(db_column='Supervisor_Job_Desc', max_length=50, blank=True, null=True)  # Field name made lowercase.  cfo = models.CharField(db_column='CFO', max_length=255, blank=True, null=True)  # Field name made lowercase.  email_address = models.CharField(db_column='Email_Address', max_length=250, blank=True, null=True)  # Field name made lowercase.  location_code = models.CharField(db_column='Location_Code', max_length=20, blank=True, null=True)  # Field name made lowercase.  location_code_desc = models.CharField(db_column='Location_Code_Desc', max_length=255, blank=True, null=True)  # Field name made lowercase.  corporate_flag = models.CharField(db_column='Corporate_Flag', max_length=1, blank=True, null=True)  # Field name made lowercase.  hire_date = models.DateTimeField(db_column='Hire_Date', blank=True, null=True)  # Field name made lowercase.  termination_date = models.DateTimeField(db_column='Termination_Date', blank=True, null=True)  # Field name made lowercase.  employee_status_id = models.IntegerField(db_column='Employee_Status_ID', blank=True, null=True)  # Field name made lowercase.  qv_statusid = models.IntegerField(db_column='QV_StatusID', blank=True, null=True)  # Field name made lowercase.  lawson_status_id = models.IntegerField(db_column='Lawson_Status_ID', blank=True, null=True)  # Field name made lowercase.  load_date = models.DateTimeField(db_column='Load_Date', blank=True, null=True)  # Field name made lowercase.    class Meta:      managed = False      def __str__(self):      return self.employee_ntname

I've attempted to use AbstractUser and AUTH_USER_MODEL = 'accounts.AllEeActive', but haven't been able to get it to work correctly to write to the auth_user table in my SQL database. Any ideas as to how to get my username associated with the employee_ntname so when I use a form with both fields on it all them are populated as a one to one relationship?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bd54b080-314f-4810-bbb7-b51e020b4a82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment