Creating users directly

69 views
Skip to first unread message

Christopher Hesse

unread,
Mar 31, 2010, 7:29:41 PM3/31/10
to django-auth-ldap
Hi, is there a way to, given a username, create the Django User object
without the user actually logging in and supplying their password?
From what I can tell, I'd need to create the _LDAPUser object myself
and call _get_or_create_user(), but judging from the underscores, that
wouldn't be quite proper.

I'm thinking there should be a populate_user() method on LDAPBackend,
but it's possible that you can't populate all the user's data without
having the user's password to do the bind. I assume if you're calling
this hypothetical method, you're saying that that is not the case. So
is there a way to do this already? Should I just customize my own auth
ldap installation?

Thanks,
Chris

Christopher Hesse

unread,
Mar 31, 2010, 8:03:37 PM3/31/10
to django-auth-ldap
Alternatively, I could create the User object directly (after
performing an LDAP search to see if the username is valid), and then
set AUTH_LDAP_ALWAYS_UPDATE_USER to True. I think it would be
something like:

from django_auth_ldap.backend import LDAPBackend, _LDAPUser

def create_user(username):
backend = LDAPBackend()
username = backend.ldap_to_django_username(username)
ldap_user = _LDAPUser(backend, username=username)
ldap_user._search_for_user_dn() # throws exception on failure
return User.objects.create(username=username)

On Mar 31, 5:29 pm, Christopher Hesse <christopher.he...@gmail.com>
wrote:

Peter Sagerson

unread,
Apr 1, 2010, 12:41:25 AM4/1/10
to django-a...@googlegroups.com
Hi Chris,

This is an easy feature to add. I'll send you a build to test. Can you elaborate on how you're using this? The documentation will make more sense if I can point to a plausible scenario.

Thanks,
Peter

> --
> To unsubscribe, reply using "remove me" as the subject.

Christopher Hesse

unread,
Apr 1, 2010, 1:10:35 PM4/1/10
to django-auth-ldap
For my use case, I need to allow administrators to create objects
belonging to users that have not yet logged in for the first time.
The objects have ForeignKey(User), so I either have to defer creation
of the object until after the user has logged in (which seems to be
more convoluted and more code) or else create the User object before
the user has logged in.

Thanks for the build, seems to work great!

-Chris

>  smime.p7s
> 6KViewDownload

Peter Sagerson

unread,
Apr 1, 2010, 3:58:16 PM4/1/10
to django-a...@googlegroups.com
That makes sense. I've uploaded version 1.0.3 with LDAPBackend.populate_user().

Thanks

Di majo

unread,
May 12, 2024, 4:00:08 PM5/12/24
to django-auth-ldap
MT103/202 DIRECT WIRE TRANSFER
PAYPAL TRANSFER
CASHAPP TRANSFER
ZELLE TRANSFER
LOAN DEAL
TRANSFER WISE
WESTERN UNION TRANSFER
BITCOIN FLASHING
BANK ACCOUNT LOADING/FLASHING
IBAN TO IBAN TRANSFER
MONEYGRAM TRANSFER
IPIP/DTC
SLBC PROVIDER
CREDIT CARD TOP UP
DUMPS/ PINS
SEPA TRANSFER
WIRE TRANSFER
BITCOIN TOP UP
GLOBALPAY INC US
SKRILL USA
UNIONPAY RECEIVER

Thanks.


NOTE; ONLY SERIOUS / RELIABLE RECEIVERS CAN CONTACT.

DM ME ON WHATSAPP
+44 7529 555638
Reply all
Reply to author
Forward
0 new messages