jhuapl-boss / boss-oidc

Django Auth plugin specific to the Boss SSO Server
Apache License 2.0
13 stars 22 forks source link

Username is too long for Django #6

Closed toninospiderman123 closed 6 years ago

toninospiderman123 commented 6 years ago

auth

I have that problem!

def check_username(username): if len(username) > 30: # Django User username is 30 character limited raise AuthenticationFailed(_('Username is too long for Django')) Is there a reason why you have used a constant number?

Is there any way to change that constants dynamically?

derek-pryor commented 6 years ago

Right now it is hardcoded because in our deployment the default Django model has a 30 character limit to the username field. It is possible to lookup the length of the username field for the User model so that the check is more flexible if a custom User model is used.

You are welcome to make the change and submit a PR, as I am not sure when we would get around to making such a change.

Allan-Nava commented 6 years ago

I use this snippet @derek-pryor


#OVERRIDE MAX LENGTH FOR USERNAME AUTH USER
from django.db.models.signals import class_prepared
def longer_username(sender, *args, **kwargs):
    #print("longer_username")
    # You can't just do `if sender == django.contrib.auth.models.User`
    # because you would have to import the model
    # You have to test using __name__ and __module__
    if sender.__name__ == "User" and sender.__module__ == "django.contrib.auth.models":
        sender._meta.get_field("username").max_length = 75
class_prepared.connect(longer_username)