Пример #1
0
    def confirm(self):
        self.confirmation_token = self.serializer.validated_data['token']
        self.confirmation_uid = self.serializer.validated_data['uid']

        try:
            uid = force_text(urlsafe_base64_decode(self.confirmation_uid))
            user = UserModel.objects.get(pk=uid)
        except (TypeError, ValueError, OverflowError,
                UserModel.DoesNotExist) as e:
            return False

        token_valid = account_activation_token.check_token(
            user, self.confirmation_token)

        if token_valid:
            user.is_active = True
            user.save()

            email_verify_obj = EmailAddress.objects.get(user=user)
            email_verify_obj.verified = True
            email_verify_obj.save()

            return True
        else:
            return False
Пример #2
0
def deactivate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None
    if user is not None and account_activation_token.check_token(user, token):
        user.delete()

    return render(request, 'accounts/signup_deactivated.html', {'user': user})
Пример #3
0
    def perform_mutate(cls, form, info):
        confirm_token = form.cleaned_data['confirm_token']
        user = User.objects.get(id=form.cleaned_data['user_id'])

        if account_activation_token.check_token(user, confirm_token):
            user.set_password(form.cleaned_data.get('new_password2'))
            return cls(error=ValidationErrors(validation_errors=[]),
                       success=True)
        else:
            return cls(error=ValidationErrors(validation_errors=[]),
                       success=False)
Пример #4
0
def activate(request, uidb64, token):
	try:
		uid = force_text(urlsafe_base64_decode(uidb64))
		user = User.objects.get(pk=uid)
	except (TypeError, ValueError, OverflowError, User.DoesNotExist):
		user = None
	if user is not None and account_activation_token.check_token(user, token):
		user.is_active = True
		user.save()
		return HttpResponse("Your account is successfully Activated")
	else:
		return HttpResponse("Invalid token")
Пример #5
0
def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except(TypeError, ValueError, OverflowError,User.DoesNotExist):
        user = None
    if user is not None and account_activation_token.check_token(user, token):
        # user.is_active = True
        user.email_confirmed = True
        user.save()
        login(request, user)
        return redirect('login')
    else:
        return render(request, 'accounts/account_activation_invalid.html')
Пример #6
0
def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None
    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.save()
        login(request, user)
        messages.success(request, f'Your account has been created!')
        return redirect('/signup')
    else:
        return HttpResponse('Activation link is invalid!')
Пример #7
0
def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None
    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.save()
        login(request, user)
        # return redirect('home')
        return render(request, 'registration/mail_confirmed.html', {})
    else:
        return HttpResponse('Activation link is invalid!')
Пример #8
0
def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None
    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.save()
        # login(request, user)
        return Response({"success": "true"}, status=status.HTTP_200_OK)
    else:
        return Response({"success": "false"},
                        status=status.HTTP_400_BAD_REQUEST)
Пример #9
0
def activate(request, uidb64, token):
    try:
        uid = force_text(urlsafe_base64_decode(uidb64))
        print(uid)
        user = User.objects.get(pk=uid)
    except (TypeError, ValueError, OverflowError, User.DoesNotExist):
        user = None

    print(user)
    print(account_activation_token.check_token(user, token))

    if user is not None and account_activation_token.check_token(user, token):
        user.is_active = True
        user.profile.email_confirmed = True
        print('active')
        user.save()
        login(request,
              user,
              backend='django.contrib.auth.backends.ModelBackend')
        messages.success(
            request, f'{user.username.capitalize()}, your email is confirmed')
        return redirect('blog-home')
    else:
        return render(request, 'accounts/account_activation_invalid.html')
Пример #10
0
    def get(self, request, id, token):
        try:
            user = User.objects.get(pk=id)
        except (TypeError, ValueError, OverflowError, User.DoesNotExist):
            user = None

        if user is not None and account_activation_token.check_token(
                user, token):
            user.is_active = True
            user.email_confirmed = True
            user.save()

            login(request, user)
            return redirect('blog:home')

        else:
            return render(request, 'activation_invalid.html')