Ejemplo n.º 1
0
def user_preferences(request, template_name='accounts/prefs.html'):
    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME,
                                      reverse("dashboard"))

    profile, profile_is_new = \
        Profile.objects.get_or_create(user=request.user)
    must_configure = not profile.first_time_setup_done
    profile.save()

    siteconfig = SiteConfiguration.objects.get_current()
    auth_backend = siteconfig.get("auth_backend")
    can_change_password = auth_backend in ['builtin', 'x509']

    if request.POST:
        form = PreferencesForm(request.POST)

        if form.is_valid():
            password = form.cleaned_data['password1']

            if can_change_password and password:
                salt = sha(str(time.time())).hexdigest()[:5]
                hash = sha(salt + password)
                newpassword = '******' % (salt, hash.hexdigest())
                request.user.password = newpassword

            if auth_backend == "builtin":
                request.user.first_name = form.cleaned_data['first_name']
                request.user.last_name = form.cleaned_data['last_name']
                request.user.email = form.cleaned_data['email']

            request.user.review_groups = form.cleaned_data['groups']
            request.user.save()

            profile.first_time_setup_done = True
            profile.syntax_highlighting = \
                form.cleaned_data['syntax_highlighting']
            profile.save()

            return HttpResponseRedirect(redirect_to)
    else:
        form = PreferencesForm({
            'settings': settings,
            'redirect_to': redirect_to,
            'first_name': request.user.first_name,
            'last_name': request.user.last_name,
            'email': request.user.email,
            'syntax_highlighting': profile.syntax_highlighting,
            'groups': [g.id for g in request.user.review_groups.all()],
        })

    return render_to_response(template_name, RequestContext(request, {
        'form': form,
        'settings': settings,
        'can_change_password': can_change_password,
        'must_configure': must_configure,
    }))
Ejemplo n.º 2
0
def user_preferences(request, template_name='accounts/prefs.html'):
    # TODO: Figure out the right place to redirect when using a LocalSite.
    redirect_to = \
        request.REQUEST.get(REDIRECT_FIELD_NAME,
            request.REQUEST.get('redirect_to', None))

    if not redirect_to:
        redirect_to = reverse("dashboard")

    try:
        profile = request.user.get_profile()
    except Profile.DoesNotExist:
        # The Profile didn't exist, but it might have been created since.
        # Let's try to create one, and if one exists now, we'll just
        # fetch again.
        try:
            profile = Profile.objects.create(user=request.user)
        except IntegrityError:
            # This was created since we checked, so load it again.
            profile = request.user.get_profile()

    auth_backends = get_auth_backends()

    if request.POST:
        form = PreferencesForm(request.user, request.POST)

        if form.is_valid():
            form.save(request.user)

            return HttpResponseRedirect(redirect_to)
    else:
        form = PreferencesForm(
            request.user, {
                'settings': settings,
                'redirect_to': redirect_to,
                'first_name': request.user.first_name,
                'last_name': request.user.last_name,
                'email': request.user.email,
                'timezone': profile.timezone,
                'syntax_highlighting': profile.syntax_highlighting,
                'profile_private': profile.is_private,
                'open_an_issue': profile.open_an_issue,
                'groups': [g.id for g in request.user.review_groups.all()],
            })

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                'form': form,
                'settings': settings,
                'can_change_password':
                auth_backends[0].supports_change_password,
            }))
Ejemplo n.º 3
0
def user_preferences(request, template_name='accounts/prefs.html'):
    # TODO: Figure out the right place to redirect when using a LocalSite.
    redirect_to = \
        request.REQUEST.get(REDIRECT_FIELD_NAME,
            request.REQUEST.get('redirect_to', None))

    if not redirect_to:
        redirect_to = reverse("dashboard")

    try:
        profile = request.user.get_profile()
    except Profile.DoesNotExist:
        # The Profile didn't exist, but it might have been created since.
        # Let's try to create one, and if one exists now, we'll just
        # fetch again.
        try:
            profile = Profile.objects.create(user=request.user)
        except IntegrityError:
            # This was created since we checked, so load it again.
            profile = request.user.get_profile()

    auth_backends = get_auth_backends()

    if request.POST:
        form = PreferencesForm(request.user, request.POST)

        if form.is_valid():
            form.save(request.user)

            return HttpResponseRedirect(redirect_to)
    else:
        form = PreferencesForm(request.user, {
            'settings': settings,
            'redirect_to': redirect_to,
            'first_name': request.user.first_name,
            'last_name': request.user.last_name,
            'email': request.user.email,
            'timezone': profile.timezone,
            'syntax_highlighting': profile.syntax_highlighting,
            'profile_private': profile.is_private,
            'open_an_issue': profile.open_an_issue,
            'groups': [g.id for g in request.user.review_groups.all()],
        })

    return render_to_response(template_name, RequestContext(request, {
        'form': form,
        'settings': settings,
        'can_change_password': auth_backends[0].supports_change_password,
    }))
Ejemplo n.º 4
0
def user_preferences(request, template_name='accounts/prefs.html'):
    # TODO: We should just get rid of this redirect and have it show the
    # settings again with a "saved" message.
    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME,
                                      request.REQUEST.get('redirect_to', None))

    if not redirect_to:
        redirect_to = reverse("dashboard")

    profile, is_new = Profile.objects.get_or_create(user=request.user)

    auth_backends = get_auth_backends()

    if request.POST:
        form = PreferencesForm(request.user, request.POST)

        if form.is_valid():
            form.save(request.user)

            return HttpResponseRedirect(redirect_to)
    else:
        form = PreferencesForm(
            request.user, {
                'settings': settings,
                'redirect_to': redirect_to,
                'first_name': request.user.first_name,
                'last_name': request.user.last_name,
                'email': request.user.email,
                'timezone': profile.timezone,
                'syntax_highlighting': profile.syntax_highlighting,
                'profile_private': profile.is_private,
                'open_an_issue': profile.open_an_issue,
                'groups': [g.id for g in request.user.review_groups.all()],
            })

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                'form': form,
                'settings': settings,
                'can_change_password':
                auth_backends[0].supports_change_password,
            }))
Ejemplo n.º 5
0
def user_preferences(request, template_name="accounts/prefs.html"):
    # TODO: We should just get rid of this redirect and have it show the
    # settings again with a "saved" message.
    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, request.REQUEST.get("redirect_to", None))

    if not redirect_to:
        redirect_to = reverse("dashboard")

    profile, is_new = Profile.objects.get_or_create(user=request.user)

    auth_backends = get_auth_backends()

    if request.POST:
        form = PreferencesForm(request.user, request.POST)

        if form.is_valid():
            form.save(request.user)

            return HttpResponseRedirect(redirect_to)
    else:
        form = PreferencesForm(
            request.user,
            {
                "settings": settings,
                "redirect_to": redirect_to,
                "first_name": request.user.first_name,
                "last_name": request.user.last_name,
                "email": request.user.email,
                "timezone": profile.timezone,
                "syntax_highlighting": profile.syntax_highlighting,
                "profile_private": profile.is_private,
                "open_an_issue": profile.open_an_issue,
                "groups": [g.id for g in request.user.review_groups.all()],
            },
        )

    return render_to_response(
        template_name,
        RequestContext(
            request,
            {"form": form, "settings": settings, "can_change_password": auth_backends[0].supports_change_password},
        ),
    )
Ejemplo n.º 6
0
def user_preferences(request, template_name='accounts/prefs.html'):
    # TODO: Figure out the right place to redirect when using a LocalSite.
    redirect_to = \
        request.REQUEST.get(REDIRECT_FIELD_NAME,
            request.REQUEST.get('redirect_to', None))

    if not redirect_to:
        redirect_to = reverse("dashboard")

    profile, profile_is_new = \
        Profile.objects.get_or_create(user=request.user)
    profile.save()

    auth_backends = get_auth_backends()

    if request.POST:
        form = PreferencesForm(request.user, request.POST)

        if form.is_valid():
            form.save(request.user)

            return HttpResponseRedirect(redirect_to)
    else:
        form = PreferencesForm(
            request.user, {
                'settings': settings,
                'redirect_to': redirect_to,
                'first_name': request.user.first_name,
                'last_name': request.user.last_name,
                'email': request.user.email,
                'syntax_highlighting': profile.syntax_highlighting,
                'groups': [g.id for g in request.user.review_groups.all()],
            })

    return render_to_response(
        template_name,
        RequestContext(
            request, {
                'form': form,
                'settings': settings,
                'can_change_password':
                auth_backends[0].supports_change_password,
            }))
Ejemplo n.º 7
0
def user_preferences(request, template_name='accounts/prefs.html'):
    # TODO: Figure out the right place to redirect when using a LocalSite.
    redirect_to = \
        request.REQUEST.get(REDIRECT_FIELD_NAME,
            request.REQUEST.get('redirect_to', None))

    if not redirect_to:
        redirect_to = reverse("dashboard")

    profile, profile_is_new = \
        Profile.objects.get_or_create(user=request.user)
    profile.save()

    auth_backends = get_auth_backends()

    if request.POST:
        form = PreferencesForm(request.user, request.POST)

        if form.is_valid():
            form.save(request.user)

            return HttpResponseRedirect(redirect_to)
    else:
        form = PreferencesForm(request.user, {
            'settings': settings,
            'redirect_to': redirect_to,
            'first_name': request.user.first_name,
            'last_name': request.user.last_name,
            'email': request.user.email,
            'timezone': profile.timezone,
            'syntax_highlighting': profile.syntax_highlighting,
            'profile_private': profile.is_private,
            'open_an_issue': profile.open_an_issue,
            'groups': [g.id for g in request.user.review_groups.all()],
        })

    return render_to_response(template_name, RequestContext(request, {
        'form': form,
        'settings': settings,
        'can_change_password': auth_backends[0].supports_change_password,
    }))