Example #1
0
def rename(request, user):
    return_path = moderation_return_path(request, user)

    form = ChangeUsernameForm(user=user)
    if request.method == 'POST':
        old_username = user.username
        form = ChangeUsernameForm(request.POST, user=user)
        if form.is_valid():
            try:
                form.change_username(changed_by=request.user)

                notify_user(user,
                    _("%(user)s has changed your name to %(newname)s."),
                    reverse('misago:user_warnings', kwargs={
                        'user_slug': user.slug, 'user_id': user.pk
                    }),
                    "name_history_%s" % user.pk,
                    formats={
                        'user': request.user.username,
                        'newname': user.username,
                    },
                    sender=request.user)

                message = _("%(old_username)s's username has been changed.")
                message = message % {'old_username': old_username}
                messages.success(request, message)

                return redirect(return_path)
            except IntegrityError:
                message = _("Error changing username. Please try again.")
                messages.error(request, message)

    return render(request, 'misago/modusers/rename.html',
                  {'profile': user, 'form': form, 'return_path': return_path})
Example #2
0
def change_username(request):
    options = get_username_options(request.user)
    if not options['changes_left']:
        return Response({
            'detail': _("You can't change your username now."),
            'options': options
        },
        status=status.HTTP_400_BAD_REQUEST)

    form = ChangeUsernameForm(request.data, user=request.user)
    if form.is_valid():
        try:
            form.change_username(changed_by=request.user)
            return Response({
                'username': request.user.username,
                'slug': request.user.slug,
                'options': get_username_options(request.user)
            })
        except IntegrityError:
            return Response({
                'detail': _("Error changing username. Please try again."),
                'options': options
            },
            status=status.HTTP_400_BAD_REQUEST)
    else:
        return Response({'detail': form.non_field_errors()[0]},
                        status=status.HTTP_400_BAD_REQUEST)
Example #3
0
def moderate_username_endpoint(request, profile):
    if request.method == 'POST':
        form = ChangeUsernameForm(request.data, user=profile)
        if form.is_valid():
            try:
                form.change_username(changed_by=request.user)
                return Response({
                    'username': profile.username,
                    'slug': profile.slug,
                })
            except IntegrityError:
                return Response(
                    {
                        'detail':
                        _("Error changing username. Please try again."),
                        'options': options
                    },
                    status=status.HTTP_400_BAD_REQUEST)
        else:
            return Response({'detail': form.non_field_errors()[0]},
                            status=status.HTTP_400_BAD_REQUEST)
    else:
        return Response({
            'length_min': settings.username_length_min,
            'length_max': settings.username_length_max,
        })
Example #4
0
def rename(request, user):
    return_path = moderation_return_path(request, user)

    form = ChangeUsernameForm(user=user)
    if request.method == 'POST':
        old_username = user.username
        form = ChangeUsernameForm(request.POST, user=user)
        if form.is_valid():
            try:
                form.change_username(changed_by=request.user)

                notify_user(user,
                    _("%(user)s has changed your name to %(newname)s."),
                    reverse('misago:user_warnings', kwargs={
                        'user_slug': user.slug, 'user_id': user.pk
                    }),
                    "name_history_%s" % user.pk,
                    formats={
                        'user': request.user.username,
                        'newname': user.username,
                    },
                    sender=request.user)

                message = _("%(old_username)s's username has been changed.")
                message = message % {'old_username': old_username}
                messages.success(request, message)

                return redirect(return_path)
            except IntegrityError:
                message = _("Error changing username. Please try again.")
                messages.error(request, message)

    return render(request, 'misago/modusers/rename.html',
                  {'profile': user, 'form': form, 'return_path': return_path})
Example #5
0
def change_username(request):
    namechanges = UsernameChanges(request.user)

    form = ChangeUsernameForm()
    if request.method == 'POST' and namechanges.left:
        form = ChangeUsernameForm(request.POST, user=request.user)
        if form.is_valid():
            try:
                form.change_username(changed_by=request.user)

                message = _("Your username has been changed.")
                messages.success(request, message)

                return redirect('misago:usercp_change_username')
            except IntegrityError:
                message = _("Error changing username. Please try again.")
                messages.error(request, message)

    return render(request, 'misago/usercp/change_username.html', {
            'form': form,
            'changes_left': namechanges.left,
            'next_change_on': namechanges.next_on
        })
Example #6
0
def moderate_username_endpoint(request, profile):
    if request.method == 'POST':
        form = ChangeUsernameForm(request.data, user=profile)
        if form.is_valid():
            try:
                form.change_username(changed_by=request.user)
                return Response({
                    'username': profile.username,
                    'slug': profile.slug,
                })
            except IntegrityError:
                return Response({
                    'detail': _("Error changing username. Please try again."),
                    'options': options
                },
                status=status.HTTP_400_BAD_REQUEST)
        else:
            return Response({'detail': form.non_field_errors()[0]},
                            status=status.HTTP_400_BAD_REQUEST)
    else:
        return Response({
            'length_min': settings.username_length_min,
            'length_max': settings.username_length_max,
        })