示例#1
0
文件: tests.py 项目: J3173/alexia
    def load_organization_data(self):
        data = self.data

        # User / Profile
        username1 = 'testuser'
        username2 = 'testuser2'

        data['password1'] = 'testuser13475'
        data['password2'] = 'testuser23475'

        data['user1'] = User(username=username1,
                             first_name='Test',
                             last_name='Client',
                             email='*****@*****.**',
                             is_superuser=True)
        data['user1'].set_password(data['password1'])
        data['user1'].save()

        data['user1'].profile = Profile()
        data['user1'].profile.save()

        data['authenticationdata1'] = AuthenticationData(
            backend=RADIUS_BACKEND_NAME,
            username=username1,
            user=data['user1'])
        data['authenticationdata1'].save()

        data['user2'] = User(username=username2,
                             first_name='Test2',
                             last_name='Client',
                             email='*****@*****.**')
        data['user2'].set_password(data['password2'])
        data['user2'].save()

        data['user2'].profile = Profile()
        data['user2'].profile.save()

        data['authenticationdata2'] = AuthenticationData(
            backend=RADIUS_BACKEND_NAME,
            username=username2,
            user=data['user2'])
        data['authenticationdata2'].save()

        # Organization
        data['organization1'] = Organization(name='Organization 1')
        data['organization1'].save()

        data['organization2'] = Organization(name='Organization 2')
        data['organization2'].save()

        # Location
        data['location1'] = Location(name='Location 1',
                                     is_public=True,
                                     prevent_conflicting_events=True)
        data['location1'].save()

        data['location2'] = Location(name='Location 2',
                                     is_public=True,
                                     prevent_conflicting_events=False)
        data['location2'].save()
示例#2
0
文件: __init__.py 项目: J3173/alexia
def get_or_create_user(backend, username):
    try:
        authentication_data = AuthenticationData.objects.get(backend=backend, username=username)
        return authentication_data.user, False
    except AuthenticationData.DoesNotExist:
        user = User(username=username)
        user.set_unusable_password()
        user.save()

        data = AuthenticationData(user=user, backend=backend, username=username.lower())
        data.save()

        profile = Profile(user=user)
        profile.save()

        return user, True
示例#3
0
文件: __init__.py 项目: J3173/alexia
def get_or_create_user(backend, username):
    try:
        authentication_data = AuthenticationData.objects.get(backend=backend,
                                                             username=username)
        return authentication_data.user, False
    except AuthenticationData.DoesNotExist:
        user = User(username=username)
        user.set_unusable_password()
        user.save()

        data = AuthenticationData(user=user,
                                  backend=backend,
                                  username=username.lower())
        data.save()

        profile = Profile(user=user)
        profile.save()

        return user, True
示例#4
0
文件: user.py 项目: J3173/alexia
def user_add(request, radius_username, first_name, last_name, email):
    """
    Add a new user to Alexia.

    An user must have an unique radius_username and a valid email address.

    Returns the user information on success.

    radius_username  -- Unique RADIUS username
    first_name       -- First name
    last_name        -- Last name
    email            -- Valid email address

    Example result value:
    {
        "first_name": "John",
        "last_name": "Doe",
        "radius_username": "******"
    }

    Raises error -32602 (Invalid params) if the radius_username already exists.
    """
    if User.objects.filter(username=radius_username).exists() or \
            AuthenticationData.objects.filter(backend=RADIUS_BACKEND_NAME, username__iexact=radius_username).exists():
        raise InvalidParametersError('User with provided radius_username already exists')

    user = User(username=radius_username, first_name=first_name, last_name=last_name, email=email)
    user.save()

    data = AuthenticationData(user=user, backend=RADIUS_BACKEND_NAME, username=radius_username.lower())
    data.save()

    user.profile = Profile()
    user.profile.save()

    return format_user(user)