0

So basicaly when a user register , i put the is_active=False i generate a verification_code and i send it within an email ,

but i want that verification_code to be used within 1Hour otherwise verification_code is set to null to my database

                        email=email,
                        age=age,
                        gender=gender,
                        phone_number=phone_number,
                        city=city,
                        is_active=False
                        occupation=occupation,)
   user_obj.set_password(password)
   user_obj.save()

   activation_link = 'http://127.0.0.1:4200/' + random_string(200)
   subject = 'Confirm email'
   from_email = EMAIL_HOST_USER
   to = [email,]
   html_message = render_to_string('forget_password.html', {'activation_link': activation_link})
   text_message = strip_tags(html_message)   
   msg = EmailMultiAlternatives(subject, text_message, to=to, from_email=from_email)
   msg.attach_alternative(html_message, "text/html")
   msg.send()
   return Response("Mail sended", status=status.HTTP_200_OK)```
Archi
  • 1
  • 1
  • easy way would be putting some kind of timestamp in the activation_link itself and validate it. the proper way would be using RESTapi and create a token. This way done before many times and just google it. here is also a question on the topic https://stackoverflow.com/questions/43780955/django-rest-framework-jwt-how-to-change-the-token-expiration-time-when-logged-i – hansTheFranz May 20 '20 at 09:52
  • thanks ! it works and it's a very efficient solution <3 – Archi May 23 '20 at 17:40

0 Answers0