mirror of
https://github.com/postgres/pgweb.git
synced 2025-07-25 16:02:27 +00:00
Delete old user when migrating to the new system.
Attempt to migrate the full name of the user a bit smarter.
This commit is contained in:
@ -23,6 +23,7 @@ class AuthBackend(ModelBackend):
|
||||
curs = connection.cursor()
|
||||
curs.execute('SELECT * FROM community_login_old(%s,%s)', (username, password))
|
||||
rows = curs.fetchall()
|
||||
|
||||
if len(rows) != 1:
|
||||
# No rows returned, something clearly went wrong
|
||||
return None
|
||||
@ -30,9 +31,15 @@ class AuthBackend(ModelBackend):
|
||||
# Value 1 in field 1 means the login succeeded. In this case,
|
||||
# create a user in the django system, and migrate all settings
|
||||
# we can think of.
|
||||
user = User(username=username, email=rows[0][3], first_name=rows[0][2])
|
||||
namepieces = rows[0][2].split(None, 2)
|
||||
if len(namepieces) == 1: namepieces[1] = ''
|
||||
user = User(username=username, email=rows[0][3], first_name=namepieces[0], last_name=namepieces[1])
|
||||
user.set_password(password)
|
||||
user.save()
|
||||
|
||||
# Now delete the user in the old system so nobody can use it
|
||||
curs.execute('SELECT * FROM community_login_old_delete(%s)', (username, ))
|
||||
|
||||
return user
|
||||
# Any other value in field 1 means login failed, so tell django we did
|
||||
return None
|
||||
|
Reference in New Issue
Block a user