0

I am using a Custom user model and so far I have been able to hook it into the allauth package extending the "SignupForm".

Everything seems to work fine because I sign up and the information about the new account is in the DB (user table and account_emailaddress table) but the email is not sent.

here is what my signup form looks like

forms.py

class StudentSignUpForm(SignupForm): 

    @transaction.atomic
    def save(self, request):
        user = super(StudentSignUpForm, self).save(request)
        user.is_student = True
        user.save()
        student = StudentProfile.objects.create(user=user)
        return user

views.py

def student_profile_view(request):

    if request.method == 'POST':

        user_form = StudentSignUpForm(request.POST, prefix='UF')

        if user_form.is_valid():
            user_form.save(request)
            return redirect('/') 

    else: 
        user_form = StudentSignUpForm(prefix='UF')

    return render(request, 'registration/student-profile.html', {'user_form': user_form,})

This works for creating the Custom User as well as creating the user under All auth, the registered email address shows in the "/admin/" under accounts/emails_address but no confirmation emails are being sent to newly registered users.

How do I fix this?? Any ideas??

CodeRed
  • 81
  • 2
  • 10

3 Answers3

0

To send email you need to configure django email settings

Please follow link to send email and link to know about django settings for email

After saving user profile you call

class StudentSignUpForm(SignupForm): 
    ........
    student = StudentProfile.objects.create(user=user)
    send_mail(
        'Subject here',
        'Here is the message.',
        'from@example.com',
        ['to@example.com'],
        fail_silently=False,
    )
Saiful Azad
  • 1,823
  • 3
  • 17
  • 27
  • Hi, I am using sendgrid as my email backend and it works well. The funny thing is that if I use the inbuilt allauth signup form, I get an email confirmation mail but when I use my custom user form, no mails are sent... I need allauth to automatically send the email verification mail when user sign-up with my custom sign-up form. – CodeRed May 27 '20 at 16:46
0

I fixed it. The problem was with the views, all I needed to do was to change into a class-based view and use the allauth signupview.

In views.py

from allauth.account.views import SignupView


class student_profile_view(SignupView):

    # The referenced HTML content can be copied from the signup.html
    # in the django-allauth template folder

    template_name = 'registration/student-profile.html'

    # the previously created form class
    form_class = StudentSignUpForm

then in my custom signup template, I just passed in "form" to render the registration form.

in urls.py

    path('register/student/', student_profile_view.as_view(), name='intern_register'),

CodeRed
  • 81
  • 2
  • 10
0

In setting.py, add:

ACCOUNT_EMAIL_VERIFICATION =”mandatory”
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77