예제 #1
0
def superuser_change_form_handler(request, user_id):
    """Process the requests from the group superuser Change Account Settings
    page for the user selected on the superuser home page. This includes
    requests from the profile change form and the set password form.

    Parameters:
        request - The request object that contains the POST data from the froms.
        user_id - The ID number of the user that should be represented and
                    modified by the change forms.
    """
    changing_user = User.objects.get(id=user_id)
    changing_profile = changing_user.get_profile()

    if request.POST:
        # Process profile change form
        if 'profile_input' in request.POST:
            profile_change_form = UserProfileForm(data=request.POST,
                                                  instance=changing_profile)
            if profile_change_form.is_valid():
                profile_change_form.save()
                return HttpResponseRedirect(
                    reverse('confirm_superuser_changes',
                            kwargs={'user_id': user_id}))
            set_password_form = SetPasswordForm(user=changing_user)

        # Process password change form
        elif 'password_input' in request.POST:
            set_password_form = SetPasswordForm(user=changing_user,
                                                data=request.POST)
            if set_password_form.is_valid():
                set_password_form.save()
                return HttpResponseRedirect(
                    reverse('confirm_superuser_changes',
                            kwargs={'user_id': user_id}))
            profile_change_form = FullProfileChangeForm(
                instance=changing_profile)

        else:
            return HttpResponseRedirect(
                reverse('superuser_change_account_settings',
                        kwargs={'user_id': user_id}))

    else:
        set_password_form = SetPasswordForm(user=changing_user)
        profile_change_form = UserProfileForm(instance=changing_profile)

    return render_to_response('superuser_change_account_settings.html', {
        'username': changing_user.username,
        'set_password_form': set_password_form,
        'profile_change_form': profile_change_form,
        'auth_url': GIT_AUTH_URL
    },
                              context_instance=RequestContext(request))
예제 #2
0
def change_form_handler(request):
    """Processes the requests from the Change Account Data page. This includes
    requests from the password change form and profile change form.

    Parameters:
        request - The request object that contains the POST data from one of the
                    change forms.
    """
    profile = request.user.get_profile()

    if request.POST:
        # Process password change form
        if 'password_input' in request.POST:
            password_change_form = PasswordChangeForm(user=request.user,
                                                      data=request.POST)
            if password_change_form.is_valid():
                password_change_form.save()
                return HttpResponseRedirect(reverse('confirm_changes'))
            profile_change_form = SecuredProfileChangeForm(instance=profile)

        # Process profile change form
        elif 'profile_input' in request.POST:
            profile_change_form = UserProfileForm(data=request.POST,
                                                  instance=profile)
            if profile_change_form.is_valid():
                profile_change_form.save()
                return HttpResponseRedirect(reverse('confirm_changes'))
            password_change_form = PasswordChangeForm(user=request.user)

        else:
            return HttpResponseRedirect(reverse('change_account_settings'))

    else:
        password_change_form = PasswordChangeForm(user=request.user)
        profile_change_form = UserProfileForm(instance=profile)

    return render_to_response('change_account_settings.html', {
        'password_change_form': password_change_form,
        'profile_change_form': profile_change_form
    },
                              context_instance=RequestContext(request))
예제 #3
0
파일: views.py 프로젝트: PolicyStat/GitZen
def group_creation_form_handler(request):
    """Process the requests from the User Group Creation page.

    Parameters:
        request - The request object that contains the form data submitted from
                    the User Group Creation page.
    """
    if request.method == 'POST':
        group_superuser_form = NewGroupSuperuserForm(data=request.POST)
        user_profile_form = UserProfileForm(data=request.POST)
        api_access_data_form = NewAPIAccessDataForm(data=request.POST)
        if group_superuser_form.is_valid() and user_profile_form.is_valid() \
        and api_access_data_form.is_valid():
            group_superuser = group_superuser_form.save()
            api_access_data = api_access_data_form.save()

            group_superuser_profile = user_profile_form.save(commit=False)
            group_superuser_profile.user = group_superuser
            group_superuser_profile.api_access_data = api_access_data
            group_superuser_profile.is_group_superuser = True
            group_superuser_profile.save()

            # Authenticate and login the newly created group superuser so a
            # GitHub access token can be added to the group's API access model
            # through OAuth on the next pages.
            user = authenticate(
                username=group_superuser_form.cleaned_data['username'],
                password=group_superuser_form.cleaned_data['password1']
            )
            login(request, user)
            return HttpResponseRedirect(reverse('confirm_group_creation'))
    else:
        group_superuser_form = NewGroupSuperuserForm()
        user_profile_form = UserProfileForm()
        api_access_data_form = NewAPIAccessDataForm()

    return render_to_response('group_creation.html',
                              {'group_superuser_form': group_superuser_form,
                               'user_profile_form': user_profile_form,
                               'api_access_data_form': api_access_data_form},
                              context_instance=RequestContext(request))
예제 #4
0
파일: views.py 프로젝트: PolicyStat/GitZen
def superuser_change_form_handler(request, user_id):
    """Process the requests from the group superuser Change Account Settings
    page for the user selected on the superuser home page. This includes
    requests from the profile change form and the set password form.

    Parameters:
        request - The request object that contains the POST data from the froms.
        user_id - The ID number of the user that should be represented and
                    modified by the change forms.
    """
    changing_user = User.objects.get(id=user_id)
    changing_profile = changing_user.get_profile()

    if request.POST:
        # Process profile change form
        if 'profile_input' in request.POST:
            profile_change_form = UserProfileForm(data=request.POST,
                                                  instance=changing_profile)
            if profile_change_form.is_valid():
                profile_change_form.save()
                return HttpResponseRedirect(
                    reverse('confirm_superuser_changes',
                            kwargs={'user_id': user_id})
                )
            set_password_form = SetPasswordForm(user=changing_user)

        # Process password change form
        elif 'password_input' in request.POST:
            set_password_form = SetPasswordForm(user=changing_user,
                                                data=request.POST)
            if set_password_form.is_valid():
                set_password_form.save()
                return HttpResponseRedirect(
                    reverse('confirm_superuser_changes',
                            kwargs={'user_id': user_id})
                )
            profile_change_form = FullProfileChangeForm(
                                    instance=changing_profile)

        else:
            return HttpResponseRedirect(
                reverse('superuser_change_account_settings',
                        kwargs={'user_id': user_id})
            )

    else:
        set_password_form = SetPasswordForm(user=changing_user)
        profile_change_form = UserProfileForm(instance=changing_profile)

    return render_to_response('superuser_change_account_settings.html',
                              {'username': changing_user.username,
                               'set_password_form': set_password_form,
                               'profile_change_form': profile_change_form,
                               'auth_url': GIT_AUTH_URL},
                              context_instance=RequestContext(request))
예제 #5
0
def group_creation_form_handler(request):
    """Process the requests from the User Group Creation page.

    Parameters:
        request - The request object that contains the form data submitted from
                    the User Group Creation page.
    """
    if request.method == 'POST':
        group_superuser_form = NewGroupSuperuserForm(data=request.POST)
        user_profile_form = UserProfileForm(data=request.POST)
        api_access_data_form = NewAPIAccessDataForm(data=request.POST)
        if group_superuser_form.is_valid() and user_profile_form.is_valid() \
        and api_access_data_form.is_valid():
            group_superuser = group_superuser_form.save()
            api_access_data = api_access_data_form.save()

            group_superuser_profile = user_profile_form.save(commit=False)
            group_superuser_profile.user = group_superuser
            group_superuser_profile.api_access_data = api_access_data
            group_superuser_profile.is_group_superuser = True
            group_superuser_profile.save()

            # Authenticate and login the newly created group superuser so a
            # GitHub access token can be added to the group's API access model
            # through OAuth on the next pages.
            user = authenticate(
                username=group_superuser_form.cleaned_data['username'],
                password=group_superuser_form.cleaned_data['password1'])
            login(request, user)
            return HttpResponseRedirect(reverse('confirm_group_creation'))
    else:
        group_superuser_form = NewGroupSuperuserForm()
        user_profile_form = UserProfileForm()
        api_access_data_form = NewAPIAccessDataForm()

    return render_to_response('group_creation.html', {
        'group_superuser_form': group_superuser_form,
        'user_profile_form': user_profile_form,
        'api_access_data_form': api_access_data_form
    },
                              context_instance=RequestContext(request))
예제 #6
0
def group_superuser_home(request):
    """Processes the various form requests from the group superuser home page.
    This includes the forms to create a new user, to deactivate or reactivate a
    user, to change the group API access settings, and to change the password
    for the superuser.

    Parameters:
        request - The request object that contains the group superuser data and
                    the POST data from the various forms.
    """
    api_access_data = request.user.get_profile().api_access_data
    product_name = api_access_data.product_name

    if request.POST:
        # Process the new user form for getting the information needed to create
        # a new user and add them to the group
        if 'user_creation_input' in request.POST:
            new_user_form = NewUserForm(data=request.POST)
            user_profile_form = UserProfileForm(data=request.POST)
            if new_user_form.is_valid() and user_profile_form.is_valid():
                password = User.objects.make_random_password()
                user = User.objects.create_user(
                    new_user_form.cleaned_data['username'],
                    new_user_form.cleaned_data['email'], password)
                user_profile = user_profile_form.save(commit=False)
                user_profile.user = user
                user_profile.api_access_data = api_access_data
                user_profile.save()

                # Email the new user to let them know an account has been
                # created for them in this group and to tell them to change
                # their temporary random password.
                user.email_user(
                    'New GitZen Account', NEW_USER_EMAIL_MESSAGE % {
                        'product_name': product_name,
                        'username': user.username,
                        'password': password,
                        'absolute_site_url': settings.ABSOLUTE_SITE_URL
                    })
                return HttpResponseRedirect(
                    reverse('confirm_user_creation',
                            kwargs={'user_id': user.id}))
            user_select_form = ActiveUserSelectionForm(api_access_data)
            user_deactivate_form = ActiveUserSelectionForm(api_access_data)
            user_activate_form = InactiveUserSelectionForm(api_access_data)
            api_access_change_form = \
                    ChangeAPIAccessDataForm(instance=api_access_data)

        # Process the user selection form for selecting a user to modify
        elif 'user_select_input' in request.POST:
            user_select_form = ActiveUserSelectionForm(api_access_data,
                                                       data=request.POST)
            if user_select_form.is_valid():
                user = user_select_form.cleaned_data['profile'].user
                return HttpResponseRedirect(
                    reverse('superuser_change_account_settings',
                            kwargs={'user_id': user.id}))
            new_user_form = NewUserForm()
            user_profile_form = UserProfileForm()
            user_deactivate_form = ActiveUserSelectionForm(api_access_data)
            user_activate_form = InactiveUserSelectionForm(api_access_data)
            api_access_change_form = \
                    ChangeAPIAccessDataForm(instance=api_access_data)

        # Process the user selection form for deactivating a user
        elif 'user_deactivate_input' in request.POST:
            user_deactivate_form = ActiveUserSelectionForm(api_access_data,
                                                           data=request.POST)
            if user_deactivate_form.is_valid():
                user = user_deactivate_form.cleaned_data['profile'].user
                user.is_active = False
                user.save()

                return HttpResponseRedirect(
                    reverse('confirm_user_deactivation',
                            kwargs={'user_id': user.id}))
            new_user_form = NewUserForm()
            user_profile_form = UserProfileForm()
            user_select_form = ActiveUserSelectionForm(api_access_data)
            user_activate_form = InactiveUserSelectionForm(api_access_data)
            api_access_change_form = \
                    ChangeAPIAccessDataForm(instance=api_access_data)

        # Process the user selection form for activating a user
        elif 'user_activate_input' in request.POST:
            user_activate_form = InactiveUserSelectionForm(api_access_data,
                                                           data=request.POST)
            if user_activate_form.is_valid():
                user = user_activate_form.cleaned_data['profile'].user
                user.is_active = True
                user.save()

                return HttpResponseRedirect(
                    reverse('confirm_user_activation',
                            kwargs={'user_id': user.id}))
            new_user_form = NewUserForm()
            user_profile_form = UserProfileForm()
            user_select_form = ActiveUserSelectionForm(api_access_data)
            user_deactivate_form = ActiveUserSelectionForm(api_access_data)
            api_access_change_form = \
                    ChangeAPIAccessDataForm(instance=api_access_data)

        # Process the API access data form for changing the API access data for
        # the group.
        elif 'api_access_change_input' in request.POST:
            api_access_change_form = ChangeAPIAccessDataForm(
                data=request.POST, instance=api_access_data)
            if api_access_change_form.is_valid():
                api_access_change_form.save()
                return HttpResponseRedirect(
                    reverse('confirm_api_access_changes'))
            new_user_form = NewUserForm()
            user_profile_form = UserProfileForm()
            user_select_form = ActiveUserSelectionForm(api_access_data)
            user_deactivate_form = ActiveUserSelectionForm(api_access_data)
            user_activate_form = InactiveUserSelectionForm(api_access_data)

        else:
            return HttpResponseRedirect(reverse('home'))

    else:
        new_user_form = NewUserForm()
        user_profile_form = UserProfileForm()
        user_select_form = ActiveUserSelectionForm(api_access_data)
        user_deactivate_form = ActiveUserSelectionForm(api_access_data)
        user_activate_form = InactiveUserSelectionForm(api_access_data)
        api_access_change_form = \
                ChangeAPIAccessDataForm(instance=api_access_data)

    context = {
        'new_user_form': new_user_form,
        'user_profile_form': user_profile_form,
        'user_select_form': user_select_form,
        'user_deactivate_form': user_deactivate_form,
        'user_activate_form': user_activate_form,
        'api_access_change_form': api_access_change_form,
        'product_name': product_name,
        'auth_url': GIT_AUTH_URL
    }

    return render_to_response('superuser_home.html',
                              context,
                              context_instance=RequestContext(request))
예제 #7
0
파일: views.py 프로젝트: PolicyStat/GitZen
def group_superuser_home(request):
    """Processes the various form requests from the group superuser home page.
    This includes the forms to create a new user, to deactivate or reactivate a
    user, to change the group API access settings, and to change the password
    for the superuser.

    Parameters:
        request - The request object that contains the group superuser data and
                    the POST data from the various forms.
    """
    api_access_data = request.user.get_profile().api_access_data
    product_name = api_access_data.product_name

    if request.POST:
        # Process the new user form for getting the information needed to create
        # a new user and add them to the group
        if 'user_creation_input' in request.POST:
            new_user_form = NewUserForm(data=request.POST)
            user_profile_form = UserProfileForm(data=request.POST)
            if new_user_form.is_valid() and user_profile_form.is_valid():
                password = User.objects.make_random_password()
                user = User.objects.create_user(
                    new_user_form.cleaned_data['username'],
                    new_user_form.cleaned_data['email'],
                    password
                )
                user_profile = user_profile_form.save(commit=False)
                user_profile.user = user
                user_profile.api_access_data = api_access_data
                user_profile.save()

                # Email the new user to let them know an account has been
                # created for them in this group and to tell them to change
                # their temporary random password.
                user.email_user(
                    'New GitZen Account',
                    NEW_USER_EMAIL_MESSAGE % {'product_name': product_name,
                                        'username': user.username,
                                        'password': password,
                                        'absolute_site_url': settings.ABSOLUTE_SITE_URL}
                )
                return HttpResponseRedirect(
                    reverse('confirm_user_creation',
                            kwargs={'user_id': user.id})
                )
            user_select_form = ActiveUserSelectionForm(api_access_data)
            user_deactivate_form = ActiveUserSelectionForm(api_access_data)
            user_activate_form = InactiveUserSelectionForm(api_access_data)
            api_access_change_form = \
                    ChangeAPIAccessDataForm(instance=api_access_data)

        # Process the user selection form for selecting a user to modify
        elif 'user_select_input' in request.POST:
            user_select_form = ActiveUserSelectionForm(api_access_data,
                                                       data=request.POST)
            if user_select_form.is_valid():
                user = user_select_form.cleaned_data['profile'].user
                return HttpResponseRedirect(
                    reverse('superuser_change_account_settings',
                            kwargs={'user_id': user.id})
                )
            new_user_form = NewUserForm()
            user_profile_form = UserProfileForm()
            user_deactivate_form = ActiveUserSelectionForm(api_access_data)
            user_activate_form = InactiveUserSelectionForm(api_access_data)
            api_access_change_form = \
                    ChangeAPIAccessDataForm(instance=api_access_data)

        # Process the user selection form for deactivating a user
        elif 'user_deactivate_input' in request.POST:
            user_deactivate_form = ActiveUserSelectionForm(api_access_data,
                                                           data=request.POST)
            if user_deactivate_form.is_valid():
                user = user_deactivate_form.cleaned_data['profile'].user
                user.is_active = False
                user.save()

                return HttpResponseRedirect(
                    reverse('confirm_user_deactivation',
                            kwargs={'user_id': user.id})
                )
            new_user_form = NewUserForm()
            user_profile_form = UserProfileForm()
            user_select_form = ActiveUserSelectionForm(api_access_data)
            user_activate_form = InactiveUserSelectionForm(api_access_data)
            api_access_change_form = \
                    ChangeAPIAccessDataForm(instance=api_access_data)

        # Process the user selection form for activating a user
        elif 'user_activate_input' in request.POST:
            user_activate_form = InactiveUserSelectionForm(api_access_data,
                                                           data=request.POST)
            if user_activate_form.is_valid():
                user = user_activate_form.cleaned_data['profile'].user
                user.is_active = True
                user.save()

                return HttpResponseRedirect(
                    reverse('confirm_user_activation',
                            kwargs={'user_id': user.id})
                )
            new_user_form = NewUserForm()
            user_profile_form = UserProfileForm()
            user_select_form = ActiveUserSelectionForm(api_access_data)
            user_deactivate_form = ActiveUserSelectionForm(api_access_data)
            api_access_change_form = \
                    ChangeAPIAccessDataForm(instance=api_access_data)

        # Process the API access data form for changing the API access data for
        # the group.
        elif 'api_access_change_input' in request.POST:
            api_access_change_form = ChangeAPIAccessDataForm(data=request.POST,
                                                      instance=api_access_data)
            if api_access_change_form.is_valid():
                api_access_change_form.save()
                return HttpResponseRedirect(
                    reverse('confirm_api_access_changes')
                )
            new_user_form = NewUserForm()
            user_profile_form = UserProfileForm()
            user_select_form = ActiveUserSelectionForm(api_access_data)
            user_deactivate_form = ActiveUserSelectionForm(api_access_data)
            user_activate_form = InactiveUserSelectionForm(api_access_data)

        else:
            return HttpResponseRedirect(reverse('home'))

    else:
        new_user_form = NewUserForm()
        user_profile_form = UserProfileForm()
        user_select_form = ActiveUserSelectionForm(api_access_data)
        user_deactivate_form = ActiveUserSelectionForm(api_access_data)
        user_activate_form = InactiveUserSelectionForm(api_access_data)
        api_access_change_form = \
                ChangeAPIAccessDataForm(instance=api_access_data)

    context = {
        'new_user_form': new_user_form,
        'user_profile_form': user_profile_form,
        'user_select_form': user_select_form,
        'user_deactivate_form': user_deactivate_form,
        'user_activate_form': user_activate_form,
        'api_access_change_form': api_access_change_form,
        'product_name': product_name,
        'auth_url': GIT_AUTH_URL
    }

    return render_to_response('superuser_home.html', context,
                              context_instance=RequestContext(request))