diff --git a/pgweb/util/auth.py b/pgweb/util/auth.py index 55f0bf56..d1de7fe0 100644 --- a/pgweb/util/auth.py +++ b/pgweb/util/auth.py @@ -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