auth migrate change
authorgniibe <gniibe@fsij.org>
Tue, 24 Sep 2013 02:02:42 +0000 (11:02 +0900)
committergniibe <gniibe@fsij.org>
Tue, 24 Sep 2013 02:02:42 +0000 (11:02 +0900)
auth_migrate.py

index 3ed03d2..5c80355 100644 (file)
@@ -1,9 +1,8 @@
-from django.db.models import get_model
 from django.contrib.auth.models import User
+from django.contrib.auth.backends import ModelBackend
 from hashlib import sha1
 
-class MyUserAuthBackend(object):
-
+class MyUserAuthBackend(ModelBackend):
     def check_legacy_password(self, db_password, supplied_password):
         return constant_time_compare(sha1(supplied_password).hexdigest(), db_password)
 
@@ -11,7 +10,6 @@ class MyUserAuthBackend(object):
         """ Authenticate a user."""
         try:
             user = User.objects.get(username=username)
-
             if '$' not in user.password:
                 if self.check_legacy_password(user.password, password):
                     user.set_password(password)
@@ -19,18 +17,8 @@ class MyUserAuthBackend(object):
                     return user
                 else:
                     return None
-
             else:
                 if user.check_password(password):
                     return user
-
-        except User.DoesNotExist:
-            return None
-
-
-    def get_user(self, user_id):
-        """ Get a User object from the user_id. """
-        try:
-            return User.objects.get(pk=user_id)
         except User.DoesNotExist:
             return None