Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I woud avoid subclassing User. Instead, you might want to create a custom authenticator that allows you to check group membership for login capability.</p> <pre><code>""" DummyBackend.py """ from django.contrib.auth.models import User, check_password from django.contrib.auth.backends import RemoteUserBackend from lecture_feedback.daily.models import Student class DummyBackend(RemoteUserBackend): """ Dummy authentication module that takes a username and password. The password must match the username. """ def authenticate(self, username=None, password=None): """ The username passed as ``remote_user`` is considered trusted. This method simply returns the ``User`` object with the given username, creating a new ``User`` object if ``create_unknown_user`` is ``True``. Returns None if ``create_unknown_user`` is ``False`` and a ``User`` object with the given username is not found in the database. """ try: student = Student.objects.get(globalid=username) except Student.DoesNotExist: return None if username != password: return user = None # Note that this could be accomplished in one try-except clause, but # instead we use get_or_create when creating unknown users since it has # built-in safeguards for multiple threads. if self.create_unknown_user: user, created = User.objects.get_or_create(username=username) if created: user = self.configure_user(user) else: try: user = User.objects.get(username=username) except User.DoesNotExist: pass return user def configure_user(self, user): """ Configures a user after creation and returns the updated user. By default, returns the user unmodified. """ student = Student.objects.get(globalid=user.username) user.first_name = student.first_name user.last_name = student.last_name return user </code></pre> <p>The Student model could contain a field that indicates if the student is allowed to log in. Also take a look at <a href="http://docs.djangoproject.com/en/dev/howto/auth-remote-user/#attributes" rel="nofollow noreferrer">http://docs.djangoproject.com/en/dev/howto/auth-remote-user/#attributes</a>. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload