Пример #1
0
from django.conf import settings
from django.core import mail
from django.urls import reverse
from plans.models import BillingInfo, Invoice, Order

from openwisp_radius.tests.tests import BaseTestCase
from openwisp_radius.tests.tests import TestApiUserToken as BaseTestApiUserToken
from openwisp_radius.utils import load_model
from openwisp_users.models import Organization, User

from . import CreatePlansMixin
from .. import settings as app_settings
from ..models import Payment

RadiusGroup = load_model('RadiusGroup')


class TestApi(CreatePlansMixin, BaseTestCase):
    def get_register_url(self, organization=None):
        if not organization:
            org = Organization.objects.first()
        return reverse('freeradius:rest_register', args=[org.slug])

    def test_register_free(self):
        plan = self._create_plan(name='free')
        pricing = self._create_pricing()
        plan_pricing = self._create_planpricing(plan=plan,
                                                pricing=pricing,
                                                price='0.00')
        plan_pricing = self._create_free_plan()
Пример #2
0
from django.utils.translation import ugettext_lazy as _
from payments import PaymentStatus
from plans.models import BillingInfo, PlanPricing, UserPlan
from rest_auth.registration.serializers import RegisterSerializer as BaseRegisterSerializer
from rest_auth.serializers import TokenSerializer as BaseTokenSerializer
from rest_framework import serializers
from rest_framework.reverse import reverse

from openwisp_radius.utils import load_model

from . import settings as app_settings
from .models import Payment
from .utils import create_order, get_or_create_temporary_radius_group

RadiusGroup = load_model('RadiusGroup')
RadiusUserGroup = load_model('RadiusUserGroup')


class TokenSerializer(BaseTokenSerializer):
    payment_url = serializers.SerializerMethodField()

    class Meta(BaseTokenSerializer.Meta):
        pass

    Meta.fields = Meta.fields + ('payment_url',)

    def get_payment_url(self, obj):
        view = self.context['view']
        token_login = self.context.get('token_login', False)
        # check if there's any pending payment
        if token_login:
Пример #3
0
import logging
import uuid
from urllib.parse import urlparse

import requests
from django.contrib.auth import get_user_model
from django.http import HttpResponse
from django.urls import reverse
from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.decorators.csrf import csrf_exempt

from openwisp_radius.utils import load_model

RadiusAccounting = load_model('RadiusAccounting')
RadiusToken = load_model('RadiusToken')
User = get_user_model()
logger = logging.getLogger('django.server')


def post_accounting_data(request, data):
    parsed_url = urlparse(request.build_absolute_uri())
    if parsed_url.netloc and parsed_url.scheme:
        url = '{}://{}{}'.format(parsed_url.scheme, parsed_url.netloc,
                                 reverse('radius:accounting'))
        try:
            requests.post(url=url, data=data, timeout=2)
        except Exception as err:
            logger.warning(err)


@csrf_exempt
Пример #4
0
from datetime import date

from django.conf import settings
from django.contrib.sites.models import Site
from django.urls import reverse
from django.utils.text import slugify
from plans.contrib import get_user_language
from plans.models import Order, PlanPricing, UserPlan

from openwisp_radius.utils import load_model

from . import settings as app_settings
from .mail import send_template_email
from .models import Payment

RadiusGroup = load_model('RadiusGroup')
RadiusGroupCheck = load_model('RadiusGroupCheck')
RadiusGroupReply = load_model('RadiusGroupReply')


def get_or_create_temporary_radius_group(organization):
    """
    gets or creates temporary radius group used while paying
    """
    rg, created = RadiusGroup.objects.get_or_create(
        name='{}-temporary'.format(organization.slug),
        organization=organization
    )
    for check in app_settings.TEMP_GROUP_CHECKS:
        opts = check.copy()
        opts.update({'group': rg,