Delete old user when migrating to the new system.
authorMagnus Hagander <magnus@hagander.net>
Wed, 13 Jan 2010 20:58:20 +0000 (21:58 +0100)
committerMagnus Hagander <magnus@hagander.net>
Wed, 13 Jan 2010 20:58:20 +0000 (21:58 +0100)
Attempt to migrate the full name of the user a bit smarter.

pgweb/util/auth.py

index 55f0bf56d9a285b512b974a03cf3ca986c63eb82..d1de7fe0dd37a44c8f27a09e09a28a8a8f07c817 100644 (file)
@@ -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