예제 #1
0
파일: backends.py 프로젝트: kaiquewdev/kuma
    def get_or_create_user(deki_user, sync_attrs=('is_superuser',
                                                  'is_staff',
                                                  'is_active',
                                                  'email')):
        """
        Grab the User via their UserProfile and deki_user_id.
        If non exists, create both.

        NOTE: Changes to this method may require changes to
              parse_user_info
        """
        try:
            # Try fetching an existing profile mapped to deki user
            profile = UserProfile.objects.get(deki_user_id=deki_user.id)
            user = profile.user

        except ObjectDoesNotExist:
            # No existing profile, so try creating a new profile and user

            # HACK: Usernames in Kuma are limited to 30 characters. There are
            # around 0.1% of MindTouch users in production (circa 2011) whose
            # names exceed this length. They're mostly the product of spammers
            # and security tests but it will still throw MySQL-level errors
            # during migration.
            username = deki_user.username[:30]

            user, created = (User.objects
                             .get_or_create(username=username))
            user.username = username
            user.email = deki_user.email
            user.set_unusable_password()
            user.save()
            profile = UserProfile(deki_user_id=deki_user.id, user=user)
            profile.save(skip_mindtouch_put=True)

        user.deki_user = deki_user

        # Sync these attributes from Deki -> Django (for now)
        needs_save = False
        for sa in sync_attrs:
            deki_val = getattr(deki_user, sa, None)
            if getattr(user, sa, None) != deki_val:
                setattr(user, sa, deki_val)
                needs_save = True

        if needs_save:
            user.save()

        return user
예제 #2
0
파일: backends.py 프로젝트: zzdjk6/kuma
    def get_or_create_user(deki_user,
                           sync_attrs=('is_superuser', 'is_staff', 'is_active',
                                       'email')):
        """
        Grab the User via their UserProfile and deki_user_id.
        If non exists, create both.

        NOTE: Changes to this method may require changes to
              parse_user_info
        """
        try:
            # Try fetching an existing profile mapped to deki user
            profile = UserProfile.objects.filter(deki_user_id=deki_user.id)[0]
            user = profile.user

        except (IndexError, ObjectDoesNotExist):
            # No existing profile, so try creating a new profile and user

            # HACK: Usernames in Kuma are limited to 30 characters. There are
            # around 0.1% of MindTouch users in production (circa 2011) whose
            # names exceed this length. They're mostly the product of spammers
            # and security tests but it will still throw MySQL-level errors
            # during migration.
            username = deki_user.username[:30]

            user, created = (User.objects.get_or_create(username=username))
            user.username = username
            user.email = deki_user.email
            user.set_unusable_password()
            user.save()
            profile = UserProfile(deki_user_id=deki_user.id, user=user)
            profile.save(skip_mindtouch_put=True)

        user.deki_user = deki_user

        # Sync these attributes from Deki -> Django (for now)
        needs_save = False
        for sa in sync_attrs:
            deki_val = getattr(deki_user, sa, None)
            if getattr(user, sa, None) != deki_val:
                setattr(user, sa, deki_val)
                needs_save = True

        if needs_save:
            user.save()

        return user
예제 #3
0
파일: test_views.py 프로젝트: tantek/kuma
    def _create_profile(self):
        """Create a user, deki_user, and a profile for a test account"""
        user = User.objects.create_user('tester23', '*****@*****.**',
                                        'trustno1')

        deki_user = DekiUser(id=0, username='******',
                             fullname='Tester Twentythree',
                             email='*****@*****.**',
                             gravatar='', profile_url=None)

        profile = UserProfile()
        profile.user = user
        profile.fullname = "Tester Twentythree"
        profile.title = "Spaceship Pilot"
        profile.organization = "UFO"
        profile.location = "Outer Space"
        profile.irc_nickname = "ircuser"
        profile.bio = "I am a freaky space alien."
        profile.save()

        return (user, deki_user, profile)
예제 #4
0
파일: backends.py 프로젝트: fwenzel/mdn
    def get_or_create_user(self, deki_user):
        """
        Grab the User via their UserProfile and deki_user_id. 
        If non exists, create both.

        NOTE: Changes to this method may require changes to
              parse_user_info
        """
        try:
            profile = UserProfile.objects.get(deki_user_id=deki_user.id)
            user = profile.user
            log.info("MONITOR Dekiwiki Profile Loaded")
            log.debug("User account already exists %d", user.id)
        except UserProfile.DoesNotExist:
            log.debug(
                "First time seeing deki user id#%d username=%s, creating account locally",
                deki_user.id,
                deki_user.username,
            )
            user, created = User.objects.get_or_create(username=deki_user.username)

            user.username = deki_user.username
            # HACK: Deki has fullname Django has First and last...
            # WACK: but our Dekiwiki instace doesn't let the user edit this data
            user.first_name = deki_user.fullname
            user.last_name = ""
            user.set_unusable_password()
            user.save()
            profile = UserProfile(deki_user_id=deki_user.id, user=user)
            profile.save()
            log.info("MONITOR Dekiwiki Profile Saved")
            log.debug("Saved profile %s", str(profile))
        user.deki_user = deki_user

        # Items we don't store in our DB (API read keeps it fresh)
        user.is_superuser = deki_user.is_superuser
        user.is_staff = deki_user.is_staff
        user.is_active = deki_user.is_active
        return user
예제 #5
0
    def get_or_create_user(self, deki_user):
        """
        Grab the User via their UserProfile and deki_user_id.
        If non exists, create both.

        NOTE: Changes to this method may require changes to
              parse_user_info
        """
        try:
            # Try fetching an existing profile mapped to deki user
            profile = UserProfile.objects.get(deki_user_id=deki_user.id)
            user = profile.user

        except UserProfile.DoesNotExist:
            # No existing profile, so try creating a new profile and user
            user, created = (User.objects.get_or_create(
                username=deki_user.username))
            user.username = deki_user.username
            user.set_unusable_password()
            user.save()
            profile = UserProfile(deki_user_id=deki_user.id, user=user)
            profile.save()

        user.deki_user = deki_user

        # Sync these attributes from Deki -> Django (for now)
        sync_attrs = ('is_superuser', 'is_staff', 'is_active', 'email')
        needs_save = False
        for sa in sync_attrs:
            deki_val = getattr(deki_user, sa, None)
            if getattr(user, sa, None) != deki_val:
                setattr(user, sa, deki_val)
                needs_save = True

        if needs_save:
            user.save()

        return user
예제 #6
0
파일: backends.py 프로젝트: tantek/kuma
    def get_or_create_user(self, deki_user):
        """
        Grab the User via their UserProfile and deki_user_id.
        If non exists, create both.

        NOTE: Changes to this method may require changes to
              parse_user_info
        """
        try:
            # Try fetching an existing profile mapped to deki user
            profile = UserProfile.objects.get(deki_user_id=deki_user.id)
            user = profile.user

        except UserProfile.DoesNotExist:
            # No existing profile, so try creating a new profile and user
            user, created = (User.objects
                             .get_or_create(username=deki_user.username))
            user.username = deki_user.username
            user.set_unusable_password()
            user.save()
            profile = UserProfile(deki_user_id=deki_user.id, user=user)
            profile.save()

        user.deki_user = deki_user

        # Sync these attributes from Deki -> Django (for now)
        sync_attrs = ('is_superuser', 'is_staff', 'is_active', 'email')
        needs_save = False
        for sa in sync_attrs:
            deki_val = getattr(deki_user, sa, None)
            if getattr(user, sa, None) != deki_val:
                setattr(user, sa, deki_val)
                needs_save = True

        if needs_save:
            user.save()

        return user
예제 #7
0
def create_profile():
    """Create a user, deki_user, and a profile for a test account"""
    user = User.objects.create_user('tester23', '*****@*****.**',
                                    'trustno1')

    deki_user = DekiUser(id=0,
                         username='******',
                         fullname='Tester Twentythree',
                         email='*****@*****.**',
                         gravatar='',
                         profile_url=None)

    profile = UserProfile()
    profile.user = user
    profile.fullname = "Tester Twentythree"
    profile.title = "Spaceship Pilot"
    profile.organization = "UFO"
    profile.location = "Outer Space"
    profile.bio = "I am a freaky space alien."
    profile.irc_nickname = "ircuser"
    profile.locale = 'en-US'
    profile.timezone = 'US/Central'
    profile.save()

    return (user, deki_user, profile)
예제 #8
0
파일: __init__.py 프로젝트: Arveti/kuma
def create_profile():
    """Create a user and a profile for a test account"""
    user = User.objects.create_user('tester23', '*****@*****.**',
                                    'trustno1')

    profile = UserProfile()
    profile.user = user
    profile.fullname = "Tester Twentythree"
    profile.title = "Spaceship Pilot"
    profile.organization = "UFO"
    profile.location = "Outer Space"
    profile.bio = "I am a freaky space alien."
    profile.irc_nickname = "ircuser"
    profile.locale = 'en-US'
    profile.timezone = 'US/Central'
    profile.save()

    return (user, profile)
예제 #9
0
파일: __init__.py 프로젝트: jsocol/kuma
def create_profile():
    """Create a user, deki_user, and a profile for a test account"""
    user = User.objects.create_user("tester23", "*****@*****.**", "trustno1")

    deki_user = DekiUser(
        id=0,
        username="******",
        fullname="Tester Twentythree",
        email="*****@*****.**",
        gravatar="",
        profile_url=None,
    )

    profile = UserProfile()
    profile.user = user
    profile.fullname = "Tester Twentythree"
    profile.title = "Spaceship Pilot"
    profile.organization = "UFO"
    profile.location = "Outer Space"
    profile.bio = "I am a freaky space alien."
    profile.irc_nickname = "ircuser"
    profile.locale = "en-US"
    profile.timezone = "US/Central"
    profile.save()

    return (user, deki_user, profile)