dragon-fire-fly / developer_matcher

2 stars 1 forks source link

[BUG] Sign up form not valid #16

Closed dragon-fire-fly closed 1 year ago

dragon-fire-fly commented 1 year ago

Describe the bug When the signup form is submitted, rather than validating the form and redirecting to the success page, the signup form page is being rendered again.

This is the responsible code:

class SignupView(TemplateView):
    model = User
    template_name = "app_user/signup.html"

    def post(self, request, *args, **kwargs):
        signup_form = UserSignupForm(request.POST)
        if signup_form.is_valid():
            user = signup_form.save()
            login(request, user)
            return redirect(reverse("app_user:success"))
        return redirect(reverse("app_user:signup"))

Using a breakpoint (after signup_form = UserSignupForm(request.POST), the object being returned when the form is submitted is as so: <UserSignupForm bound=True, valid=Unknown, fields=(username;email;password)> Therefore, the if signup_form.is_valid(): check returns FALSE and the app_user:signup page is being rendered.

To Reproduce Steps to reproduce the behavior:

  1. Go to signup form (http://127.0.0.1:8000/user/signup/)
  2. Fill in and submit form
  3. See error

Expected behavior The form should be evaluated as valid and the success page (return redirect(reverse("app_user:success"))) should be displayed.

Screenshots form_redirects_back_to_form signup_form_valid_unknown

Desktop (please complete the following information):

dragon-fire-fly commented 1 year ago

Adding a print statement to see the signup_form.errors showed the following ValueError: ValueError: You have multiple authentication backends configured and therefore must provide the 'backend' argument or set the 'backend' attribute on the user. This was also shown in the browse (see screenshots).

multipl_backends

multiple_backends_configured

Looking into the settings.py, AUTHENTICATION_BACKENDS were added in two places and were therefore conflicting. One of the copies was removed and the form was able to be validated and the user redirected to the success page.

success_screen_redirect