mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-06 09:57:57 +00:00
Add ability to import user to django cauth example
This has been in used around a number of community sites already, backpatch it into the upstream master.
This commit is contained in:
@ -208,3 +208,28 @@ def user_search(searchterm=None, userid=None):
|
||||
j = json.loads(s)
|
||||
|
||||
return j
|
||||
|
||||
# Import a user into the local authentication system. Will initially
|
||||
# make a search for it, and if anything other than one entry is returned
|
||||
# the import will fail.
|
||||
# Import is only supported based on userid - so a search should normally
|
||||
# be done first. This will result in multiple calls to the upstream
|
||||
# server, but they are cheap...
|
||||
# The call to this function should normally be wrapped in a transaction,
|
||||
# and this function itself will make no attempt to do anything about that.
|
||||
def user_import(uid):
|
||||
u = user_search(userid=uid)
|
||||
if len(u) != 1:
|
||||
raise Exception("Internal error, duplicate or no user found")
|
||||
|
||||
u = u[0]
|
||||
|
||||
if User.objects.filter(username=u['u']).exists():
|
||||
raise Exception("User already exists")
|
||||
|
||||
User(username=u['u'],
|
||||
first_name=u['f'],
|
||||
last_name=u['l'],
|
||||
email=u['e'],
|
||||
password='setbypluginnotsha1',
|
||||
).save()
|
||||
|
Reference in New Issue
Block a user