scholrly / neo4django

Drop-in Neo4j/Django integration.
GNU General Public License v3.0
357 stars 83 forks source link

Backend fix User model (avoid from_model trick) #217

Closed tonjo closed 10 years ago

tonjo commented 10 years ago

Using authenticate gave always graph_auth.User. Taken from django's auth, get_user_model will ensure your own AUTH_USER_MODEL is returned instead.

tonjo commented 10 years ago

In test_settings.py we had to put the app where AUTH_USER_MODEL is defined. I'm thinking to enhance the customization. I saw the django authentication backend looks for USERNAME_FIELD, so we can define our own.
AbstractBaseUser is there exactly for that purpose, since it defines only password, is_active and last_login.
Maybe we could derive from it?
Maybe we don't even need a custom backend, just a custom user, not sure about that.

tonjo commented 10 years ago

Did you have a look at this, @mhluongo? It fixes the wrong type when authenticating. Reading the doc it seems the issue is only with Django 1.4, but it's still present in 1.5.

mhluongo commented 10 years ago

@tonjo This is a backwards-incompatible change- maybe there's a less heavy-handed approach? Eg by testing the import, like

try:
    from django.contrib.auth import get_user_model
    UserModel = get_user_model()
except ImportError:
    from .models import User as UserModel
mhluongo commented 10 years ago

I'd rather keep support for Django 1.4 and support 1.5, rather than just 1.5.

tonjo commented 10 years ago

Yes, you're right, forgot get_user_model was added in 1.5. Changed as you suggested.

mhluongo commented 10 years ago

Thanks @tonjo!

tonjo commented 10 years ago

You're welcome. Sorry for the little mess, still quite new at github.

On 6 November 2013 18:05, Matt Luongo notifications@github.com wrote:

Thanks @tonjo https://github.com/tonjo!

— Reply to this email directly or view it on GitHubhttps://github.com/scholrly/neo4django/pull/217#issuecomment-27892216 .

mhluongo commented 10 years ago

No worries, you'll get the hang of it :)