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.

23 lines
886 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.models import User
  8. def activate(request, uidb64, token):
  9. try:
  10. uid = force_text(urlsafe_base64_decode(uidb64))
  11. user = User.objects.get(pk=uid)
  12. except(TypeError, ValueError, OverflowError, User.DoesNotExist):
  13. user = None
  14. if user is not None and account_activation_token.check_token(user, token):
  15. user.is_active = True
  16. user.save()
  17. user.backend = 'django.contrib.auth.backends.ModelBackend'
  18. login(request=request, user=user,)
  19. return redirect('projects')
  20. else:
  21. return render(request, 'validate_mail_address_invalid.html')