Posts

Showing posts with the label UserProfile

Moodle user keeps being redirected to user profile page after login and how to fix

One day you noticed a user keeps being redirected to the Moodle's user profile page after she successfully log in and you cannot do anything. I got that problem too and it took me a while to figure out how to fix it. Login to Moodle using an administrator account and update all the required field of that user. Save it and everything will be ok. It's because for some reason your user missing some required information (such as email address in my case). You will wonder how this happens because you cannot create a user if you don't input all the required information. But, there is one scenario this will happen, It's LDAP. When a user login into Moodle the first time, Moodle will create the user as long as it has username. In my case, the user has everything it needs except for the email address. Interesting right? :D

Duplicate entry error with the Django's User Profile model

I wrote a User Profile model which extends the Django's User authentication model as following: class TeacherProfile (models.Model):     user = models.OneToOneField(User, related_name="teacher_profile", \                         related_query_name="profile")     teacher_number = models.CharField(max_length=255, blank=True, null=True) # Office     desc = models.CharField(max_length=255, blank=True, null=True) # Description     title = models.CharField(max_length=255, blank=True, null=True)     school = models.ForeignKey('School', null=True,                          related_name="steacher_profiles",                         related_query_name="steacher_profile",             )     def __unicode__(self): ...

Auto create and populate UserProfile in Django 1.7 with django-auth-ldap

To map some extra information of the Active Directory user into my Django's StudentProfile (UserProfile) model (Django 1.7 and django-auth-ldap 1.2.5), I have to call a post_save signal: In my models.py: from django.db import models from django.contrib.auth.models import User from django.db.models.signals import post_save from django_auth_ldap.backend import LDAPBackend class StudentProfile (models.Model): user = models.OneToOneField(User, related_name="student_profile", related_query_name="profile") student_number = models.CharField(max_length=255) # Office class_of = models.CharField(max_length=255) # Description def create_student_profile (sender, instance, created, **kwargs): if created: new_profile = StudentProfile.objects.create(user=instance) user = LDAPBackend().populate_user(instance.username) if user: desc = user.ldap_user.attrs.get("description", [])[0] office = user.ldap_user.attrs.get("physicalDel...