コード例 #1
0
ファイル: backends.py プロジェクト: MechanisM/django-phpbb
    def authenticate(self, username=None, password=None):
        """Authenticate user against phpBB3 database.
        
        Check if the user exists in Django users. If not, create it.
        Then authenticate."""
        logging.debug("PhpbbBackend::authenticate()")
        user = None
        try:
            phpbb_user = PhpbbUser.objects.get(username=username)
        except PhpbbUser.DoesNotExist:
            # The user does not exist in phpBB. Bailing out.
            logging.info("User '%s' doesn't exist." % username)
            return None
        phpbb_checker = php_password.PhpbbPassword()
        if phpbb_checker.phpbb_check_hash(password, phpbb_user.user_password):
            logging.debug("User %s successfully authenticated "
                          "with phpBB database." % username)
        else:
            # Invalid password
            logging.info("Wrong password for user %s" % username)
            return None
        # At this point we have successfully checked phpBB user password.
        # Now we're getting and returning Django user. If necessary, we're
        # creating the user on the fly.
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            logging.info("Creating new Django user '%s'" % username)
            if username:
                user = User(username=username, password="")
                user.is_staff = True
                user.is_superuser = False

                user.email = phpbb_user.user_email
                user.save()
            else:
                logging.warning("User name empty. Not creating.")
                return None
        # In case the phpBB password has changed, we're updating user's
        # Django password. Django password is necessary when user wants to log
        # in to the admin interface.
        user.set_password(password)
        logging.debug("Returning user '%s'" % user)
        return user
コード例 #2
0
ファイル: password_test.py プロジェクト: evecm/django-phpbb
 def setUp(self):
     self.p1 = password.PhpbbPassword()
コード例 #3
0
ファイル: backends.py プロジェクト: evecm/django-phpbb
    def authenticate(self, username=None, password=None):
        """Authenticate user against phpBB3 database.

        Check if the user exists in Django users. If not, create it.
        Then authenticate."""
        logging.debug("PhpbbBackend::authenticate()")
        user = None

        try:
            phpbb_user = PhpbbUser.objects.get(username=username)
        except PhpbbUser.DoesNotExist:
            # The user does not exist in phpBB. Bailing out.
            logging.info("User '%s' doesn't exist." % username)
            return None
        phpbb_checker = php_password.PhpbbPassword()
        if phpbb_checker.phpbb_check_hash(password, phpbb_user.user_password):
            logging.debug("User %s successfully authenticated "
                          "with phpBB database." % username)
        else:
            # Invalid password
            logging.info("Wrong password for user %s" % username)
            return None
        # At this point we have successfully checked phpBB user password.
        # Now we're getting and returning Django user. If necessary, we're
        # creating the user on the fly.
        try:
            user = User.objects.get(username=username)
        except User.DoesNotExist:
            logging.info("Creating new Django user '%s'" % username)
            if username:
                user = User(username=username, password="")
                user.is_staff = False
                user.is_superuser = False

                user.email = phpbb_user.user_email
                user.save()

                # Do the initial update of the user's characters
                characters = api.get_account_characters(
                    UserAPIKey(keyID=phpbb_user.eveapi_keyid,
                               vCode=phpbb_user.eveapi_vcode))
                members, corps = init_characters(user, characters)
                for corp in corps:
                    corp.save()
                for member in members:
                    member.save()

                # Give the new user roles/groups:
                update_user_accesses(user)

            else:
                logging.warning("User name empty. Not creating.")
                return None
        # In case the phpBB password has changed, we're updating user's
        # Django password. Django password is necessary when user wants to log
        # in to the admin interface.
        user.set_password(password)

        # Update the API information always to allow changes from phpBB
        user_api = UserAPIKey()
        user_api.keyID = phpbb_user.eveapi_keyid
        user_api.vCode = phpbb_user.eveapi_vcode
        user_api.user = user
        user_api.save()

        logging.debug("Returning user '%s'" % user)
        return user