You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
856 B

3 years ago
3 years ago
  1. from django.contrib.auth import get_user_model, login
  2. from django.shortcuts import redirect, render
  3. from django.utils.encoding import force_text
  4. from django.utils.http import urlsafe_base64_decode
  5. from .tokens import account_activation_token
  6. User = get_user_model()
  7. def activate(request, uidb64, token):
  8. try:
  9. uid = force_text(urlsafe_base64_decode(uidb64))
  10. user = User.objects.get(pk=uid)
  11. except(TypeError, ValueError, OverflowError, User.DoesNotExist):
  12. user = None
  13. if user is not None and account_activation_token.check_token(user, token):
  14. user.is_active = True
  15. user.save()
  16. user.backend = 'django.contrib.auth.backends.ModelBackend'
  17. login(request=request, user=user,)
  18. return redirect('projects')
  19. else:
  20. return render(request, 'validate_mail_address_invalid.html')