Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email verification by sending otp #41

Open
sanchit36 opened this issue Mar 12, 2021 · 1 comment
Open

Email verification by sending otp #41

sanchit36 opened this issue Mar 12, 2021 · 1 comment
Projects

Comments

@sanchit36
Copy link
Contributor

No description provided.

@AroraShreshth AroraShreshth added this to To do in V1.1 Mar 18, 2021
@ramyak-mehra
Copy link
Contributor

Wrote something a while back you can take bits and pieces from this

@receiver(post_save, sender=Student)
 def send_cofirm_email(sender , instance , created , **kwargs):
     if created:
         sent = signup(instance)
         if not sent:
             raise Exception('Email Verification Not Sent')

def signup(student):
    mail_subject = 'Activate your blog account.'
    message = render_to_string('users/account_activate_email.html', {
        'user': student.user,
        'domain': 'localhost:8000',
        'uid': urlsafe_base64_encode(force_bytes(student.pk)),
        'token': student.token,
    })
    to_email = student.user.email
    email = EmailMessage(
        mail_subject, message, to=[to_email]
    )
    email.send()
    return True
def activate_account(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        student = Student.objects.get(pk=uid)
    except(TypeError, ValueError, OverflowError, Student.DoesNotExist):
        student = None
    print(token)

    if student is not None and str(token) == str(student.token):
        student.user.is_active = True
        student.user.save()
        return HttpResponse('Thank you for your email confirmation. Now you can login your account.')
    else:
        raise Exception('Activation link is invalid!')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
V1.1
To do
Development

No branches or pull requests

2 participants