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.

25 lines
914 B

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