[Answered ]-Django user login after successful user creation failed

2👍

You’ve correctly overridden the form’s save method to set the hashed password via user.set_password(). But you never call that save from your view: instead, you instantiate a GeneralUser directly in the view’s form_valid method, and there you set the password directly from cleaned_data, so it is not hashed.

Remove that instantiation from the view, and call the super method (which calls form.save()) instead:

def form_valid(self, form, *args, **kwargs):
    response = super(GeneralUserCreateView, self).form_valid(form, *args, **kwargs)
    user = self.object
    title = "Welcome to something"
    content = "Thank you for using our system."
    send_mail(title, content, settings.EMAIL_HOST_USER, [user.email], fail_silently=True)
    return response

Leave a comment