Exemple #1
0
def auth_settings(request, id):
    user_ = get_object_or_404(User, id=id)

    if not (request.user.is_superuser or request.user == user_):
        return HttpResponseUnauthorized(request)
    if not settings.USERS_CAN_CHANGE_AUTH_SETTINGS:
        return HttpResponseUnauthorized(request)

    auth_keys = user_.auth_keys.all()

    if request.user.is_superuser or (not user_.has_usable_password()):
        FormClass = SetPasswordForm
    else:
        FormClass = ChangePasswordForm

    if request.POST:
        form = FormClass(request.POST, user=user_)
        if form.is_valid():
            is_new_pass = not user_.has_usable_password()
            user_.set_password(form.cleaned_data["password1"])
            user_.save()

            if is_new_pass:
                request.user.message_set.create(message=_("New password set"))
                if not request.user.is_superuser:
                    form = ChangePasswordForm(user=user_)
            else:
                request.user.message_set.create(message=_("Your password was changed"))

            return HttpResponseRedirect(reverse("user_authsettings", kwargs={"id": user_.id}))
    else:
        form = FormClass(user=user_)

    auth_keys_list = []

    for k in auth_keys:
        provider = AUTH_PROVIDERS.get(k.provider, None)

        if provider is not None:
            name = "%s: %s" % (provider.context.human_name, provider.context.readable_key(k))
        else:
            from forum.authentication.base import ConsumerTemplateContext

            "unknown: %s" % ConsumerTemplateContext.readable_key(k)

        auth_keys_list.append({"name": name, "id": k.id})

    return render_response(
        "auth/auth_settings.html",
        {
            "view_user": user_,
            "can_view_private": (user_ == request.user) or request.user.is_superuser,
            "form": form,
            "has_password": user_.has_usable_password(),
            "auth_keys": auth_keys_list,
            "allow_local_auth": AUTH_PROVIDERS.get("local", None),
        },
        request,
    )
Exemple #2
0
def auth_settings(request, id):
    user_ = get_object_or_404(User, id=id)

    if not (request.user.is_superuser or request.user == user_):
        return HttpResponseUnauthorized(request)

    auth_keys = user_.auth_keys.all()

    if request.user.is_superuser or (not user_.has_usable_password()):
        FormClass = SetPasswordForm
    else:
        FormClass = ChangePasswordForm

    if request.POST:
        form = FormClass(request.POST, user=user_)
        if form.is_valid():
            is_new_pass = not user_.has_usable_password()
            user_.set_password(form.cleaned_data['password1'])
            user_.save()

            if is_new_pass:
                request.user.message_set.create(message=_("New password set"))
                if not request.user.is_superuser:
                    form = ChangePasswordForm(user=user_)
            else:
                request.user.message_set.create(
                    message=_("Your password was changed"))

            return HttpResponseRedirect(
                reverse('user_authsettings', kwargs={'id': user_.id}))
    else:
        form = FormClass(user=user_)

    auth_keys_list = []

    for k in auth_keys:
        provider = AUTH_PROVIDERS.get(k.provider, None)

        if provider is not None:
            name = "%s: %s" % (provider.context.human_name,
                               provider.context.readable_key(k))
        else:
            from forum.authentication.base import ConsumerTemplateContext
            "unknown: %s" % ConsumerTemplateContext.readable_key(k)

        auth_keys_list.append({'name': name, 'id': k.id})

    return render_to_response(
        'auth/auth_settings.html', {
            'view_user': user_,
            "can_view_private":
            (user_ == request.user) or request.user.is_superuser,
            'form': form,
            'has_password': user_.has_usable_password(),
            'auth_keys': auth_keys_list,
            'allow_local_auth': AUTH_PROVIDERS.get('local', None),
        },
        context_instance=RequestContext(request))
Exemple #3
0
def auth_settings(request, id):
    user_ = get_object_or_404(User, id=id)

    if not (request.user.is_superuser or request.user == user_):
        return HttpResponseUnauthorized(request)
    if not settings.USERS_CAN_CHANGE_AUTH_SETTINGS:
        return HttpResponseUnauthorized(request)

    auth_keys = user_.auth_keys.all()

    if request.user.is_superuser or (not user_.has_usable_password()):
        FormClass = SetPasswordForm
    else:
        FormClass = ChangePasswordForm

    if request.POST:
        form = FormClass(request.POST, user=user_)
        if form.is_valid():
            is_new_pass = not user_.has_usable_password()
            user_.set_password(form.cleaned_data['password1'])
            user_.save()

            if is_new_pass:
                messages.info(request, _("New password set"))
                if not request.user.is_superuser:
                    form = ChangePasswordForm(user=user_)
            else:
                messages.info(request, _("Your password was changed"))

            return HttpResponseRedirect(reverse('user_authsettings', kwargs={'id': user_.id}))
    else:
        form = FormClass(user=user_)

    auth_keys_list = []

    for k in auth_keys:
        provider = AUTH_PROVIDERS.get(k.provider, None)

        if provider is not None:
            name =  "%s: %s" % (provider.context.human_name, provider.context.readable_key(k))
        else:
            from forum.authentication.base import ConsumerTemplateContext
            "unknown: %s" % ConsumerTemplateContext.readable_key(k)

        auth_keys_list.append({
        'name': name,
        'id': k.id
        })

    return render_to_response('auth/auth_settings.html', {
    'view_user': user_,
    "can_view_private": (user_ == request.user) or request.user.is_superuser,
    'form': form,
    'has_password': user_.has_usable_password(),
    'auth_keys': auth_keys_list,
    'allow_local_auth': AUTH_PROVIDERS.get('local', None),
    }, context_instance=RequestContext(request))
Exemple #4
0
def auth_settings(request):
    """
    change password view.

    url : /changepw/
    template: authopenid/changepw.html
    """
    user_ = request.user
    auth_keys = user_.auth_keys.all()

    if user_.has_usable_password():
        FormClass = ChangePasswordForm
    else:
        FormClass = SetPasswordForm

    if request.POST:
        form = FormClass(request.POST, user=user_)
        if form.is_valid():
            if user_.has_usable_password():
                request.user.message_set.create(message=_("Your password was changed"))
            else:
                request.user.message_set.create(message=_("New password set"))
                FormClass = ChangePasswordForm
                
            user_.set_password(form.cleaned_data['password1'])
            user_.save()
            return HttpResponseRedirect(reverse('user_authsettings'))
    
    form = FormClass(user=user_)

    auth_keys_list = []

    for k in auth_keys:
        provider = AUTH_PROVIDERS.get(k.provider, None)

        if provider is not None:
            name =  "%s: %s" % (provider.context.human_name, provider.context.readable_key(k))
        else:
            from forum.authentication.base import ConsumerTemplateContext
            "unknown: %s" % ConsumerTemplateContext.readable_key(k)

        auth_keys_list.append({
            'name': name,
            'id': k.id
        })

    return render_to_response('auth/auth_settings.html', {
        'form': form,
        'has_password': user_.has_usable_password(),
        'auth_keys': auth_keys_list,
    }, context_instance=RequestContext(request))
Exemple #5
0
def auth_settings(request):
    """
    change password view.

    url : /changepw/
    template: authopenid/changepw.html
    """
    user_ = request.user
    auth_keys = user_.auth_keys.all()

    if user_.has_usable_password():
        FormClass = ChangePasswordForm
    else:
        FormClass = SetPasswordForm

    if request.POST:
        form = FormClass(request.POST, user=user_)
        if form.is_valid():
            if user_.has_usable_password():
                request.user.message_set.create(message=_("Your password was changed"))
            else:
                request.user.message_set.create(message=_("New password set"))
                FormClass = ChangePasswordForm
                
            user_.set_password(form.cleaned_data['password1'])
            user_.save()
            return HttpResponseRedirect(reverse('user_authsettings'))
    
    form = FormClass(user=user_)

    auth_keys_list = []

    for k in auth_keys:
        provider = AUTH_PROVIDERS.get(k.provider, None)

        if provider is not None:
            name =  "%s: %s" % (provider.context.human_name, provider.context.readable_key(k))
        else:
            from forum.authentication.base import ConsumerTemplateContext
            "unknown: %s" % ConsumerTemplateContext.readable_key(k)

        auth_keys_list.append({
            'name': name,
            'id': k.id
        })

    return render_to_response('auth/auth_settings.html', {
        'form': form,
        'has_password': user_.has_usable_password(),
        'auth_keys': auth_keys_list,
    }, context_instance=RequestContext(request))