• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rafalp / Misago / 9487666026

12 Jun 2024 06:16PM UTC coverage: 97.699% (-1.0%) from 98.716%
9487666026

push

github

web-flow
Replace forum options with account settings (#1742)

1947 of 1979 new or added lines in 68 files covered. (98.38%)

661 existing lines in 143 files now uncovered.

52601 of 53840 relevant lines covered (97.7%)

0.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/misago/users/api/userendpoints/create.py
1
from django.contrib.auth import authenticate, get_user_model, login
1✔
2
from django.core.exceptions import PermissionDenied, ValidationError
1✔
3
from django.db import IntegrityError
1✔
4
from django.utils.translation import pgettext
1✔
5
from django.views.decorators.csrf import csrf_protect
1✔
6
from rest_framework import status
1✔
7
from rest_framework.response import Response
1✔
8

9
from ... import captcha
1✔
10
from ....legal.models import Agreement
1✔
11
from ...forms.register import RegisterForm
1✔
12
from ...registration import (
1✔
13
    get_registration_result_json,
14
    save_user_agreements,
15
    send_welcome_email,
16
)
17
from ...setupnewuser import setup_new_user
1✔
18

19
User = get_user_model()
1✔
20

21

22
@csrf_protect
1✔
23
def create_endpoint(request):
1✔
24
    if request.settings.account_activation == "closed":
1✔
25
        raise PermissionDenied(
1✔
26
            pgettext(
27
                "user register api", "New users registrations are currently closed."
28
            )
29
        )
30

31
    request_data = request.data
1✔
32
    if not isinstance(request_data, dict):
1✔
33
        request_data = {}
1✔
34

35
    form = RegisterForm(
1✔
36
        request_data, request=request, agreements=Agreement.objects.get_agreements()
37
    )
38

39
    try:
1✔
40
        if form.is_valid():
1✔
41
            captcha.test_request(request)
1✔
42
    except ValidationError as e:
1✔
43
        form.add_error("captcha", e)
1✔
44

45
    if not form.is_valid():
1✔
46
        return Response(form.errors, status=status.HTTP_400_BAD_REQUEST)
1✔
47

48
    activation_kwargs = {}
1✔
49
    if request.settings.account_activation == "user":
1✔
50
        activation_kwargs = {"requires_activation": User.ACTIVATION_USER}
1✔
51
    elif request.settings.account_activation == "admin":
1✔
52
        activation_kwargs = {"requires_activation": User.ACTIVATION_ADMIN}
1✔
53

54
    try:
1✔
55
        new_user = User.objects.create_user(
1✔
56
            form.cleaned_data["username"],
57
            form.cleaned_data["email"],
58
            form.cleaned_data["password"],
59
            joined_from_ip=request.user_ip,
60
            **activation_kwargs
61
        )
62
    except IntegrityError:
×
UNCOV
63
        return Response(
×
64
            {
65
                "__all__": pgettext(
66
                    "user register api", "Please try resubmitting the form."
67
                )
68
            },
69
            status=status.HTTP_400_BAD_REQUEST,
70
        )
71

72
    setup_new_user(request.settings, new_user)
1✔
73
    save_user_agreements(new_user, form)
1✔
74
    send_welcome_email(request, new_user)
1✔
75

76
    if new_user.requires_activation == User.ACTIVATION_NONE:
1✔
77
        authenticated_user = authenticate(
1✔
78
            username=new_user.email, password=form.cleaned_data["password"]
79
        )
80
        login(request, authenticated_user)
1✔
81

82
    return Response(get_registration_result_json(new_user))
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc