Beispiel #1
0
def calls_history(request):
    """Загрузить историю звонков по пользователю"""
    result = {}
    shopper = get_shopper(request)
    if request.method == 'GET' and shopper:
        date = str_to_date(request.GET.get('date'))
        if not date:
            date = datetime.date.today()
        start_date = '%s-%s-%s 00:00:00' % (date.year, date.month, date.day)
        end_date = '%s-%s-%s 23:59:59' % (date.year, date.month, date.day)
        params = {
            'page': request.GET.get('page', 0),
            'filter__created__lte': end_date,
            'filter__created__gte': start_date,
            'order__created': 'desc',
            'only_fields': 'dest,created,duration,billing,state,client_name',
        }
        headers = {
            'token': '%s-%s' % (settings.FS_USER, shopper.id),
        }
        r = requests.get('%s/freeswitch/cdr_csv/api/' %
                         settings.FREESWITCH_DOMAIN,
                         params=params,
                         headers=headers)
        result = r.json()

    return JsonResponse(result, safe=False)
Beispiel #2
0
def confirm_phone(request):
    """Запрос на подтверждение телефона,
       проверка кода подтверждения телефона
    """
    result = {}
    shopper = get_shopper(request)
    if not shopper:
        # Упрощенная регистрация по телефону
        if request.GET.get('digits'):
            if request.session.get('confirm_phone') and request.GET[
                    'digits'] == request.session['confirm_phone']:
                new_user = Shopper.objects.create(
                    phone=request.session['phone'],
                    name='Гость',
                )
                save_user_to_request(request, new_user)
                if phone_confirmed(request):  # Тел подтвержден
                    result['success'] = 1
                    fs_shopper(request)
                return JsonResponse(result, safe=False)
        result = prepare_session(request, request.GET.get('phone'))
        return JsonResponse(result, safe=False)
    if request.GET.get('digits'):
        if request.session.get('confirm_phone') and request.GET[
                'digits'] == request.session['confirm_phone']:
            if phone_confirmed(request):  # Тел подтвержден
                result['success'] = 1
                fs_shopper(request)
        return JsonResponse(result, safe=False)
    result = prepare_session(request)
    return JsonResponse(result, safe=False)
Beispiel #3
0
def prepare_session(request, phone: str = None):
    """Подготовить сессию для регистрации/обновления
       профиля с подтверждением по обратному звонку
       :param request: HttpRequest
       :param phone: Телефон (если нет пользователя)
    """
    result = {}
    shopper = get_shopper(request)
    if request.method == 'GET' and (shopper or phone):
        if shopper:
            phone = shopper.phone
        phone = kill_quotes(phone, 'int')
        request.session['confirm_phone'] = GenPasswd(4, '1234567890')
        request.session['phone'] = phone
        request.session.save()
        # Скрипт отправляет на свич телефон
        # и код и свич звонит и диктует
        params = {
            'phone': phone,
            'digit': request.session['confirm_phone'],
        }
        r = requests.get('%s/freeswitch/sms_service/say_code/' %
                         settings.FREESWITCH_DOMAIN,
                         params=params)

        result = r.json()
    return result
Beispiel #4
0
def checkout(request):
    """Оформление заказа - Подтверждение заказа"""
    mh_vars = order_vars.copy()
    context = {}
    q_string = {}
    containers = {}
    shopper = get_shopper(request)

    if request.is_ajax():
        return JsonResponse(context, safe=False)
    template = 'web/order/checkout.html'

    page = SearchLink(q_string, request, containers)
    if not page:
        page = Blocks(name=order_vars['singular_obj'])
    context['breadcrumbs'] = [{
        'name': 'Подтверждение заказа',
        'link': reverse('%s:%s' % (CUR_APP, 'checkout')),
    }]

    context['page'] = page
    context['containers'] = containers
    cart = calc_cart(shopper, min_info=False)
    context['cart'] = cart

    # Оформление заказа
    context.update(**create_new_order(request, shopper, cart))
    if 'order' in context and context['order']:
        template = 'web/order/confirmed.html'

    return render(request, template, context)
Beispiel #5
0
def show_cart(request):
    """Оформление заказа - Корзинка"""
    mh_vars = cart_vars.copy()
    context = {}
    q_string = {}
    containers = {}
    shopper = get_shopper(request)

    if request.is_ajax():
        return JsonResponse(context, safe=False)
    template = 'web/order/cart.html'

    page = SearchLink(q_string, request, containers)
    if not page:
        page = Blocks(name=mh_vars['singular_obj'])
    context['breadcrumbs'] = [{
        'name':
        'Корзина',
        'link':
        reverse('%s:%s' % (CUR_APP, 'show_cart')),
    }]

    context['page'] = page
    context['containers'] = containers
    context['cart'] = calc_cart(shopper, min_info=False)

    return render(request, template, context)
Beispiel #6
0
def check_user_can_call(request):
    """Проверить, что есть регистрация и телефон подтвержден
    """
    result = {}
    shopper = get_shopper(request)
    if not shopper:
        result['not_registered'] = True
    elif not shopper.phone_confirmed:
        result['not_confirmed'] = True
    if not 'error' in result:
        result['success'] = True
    return result
Beispiel #7
0
def show_profile(request):
    """Личный кабинет пользователя"""
    mh_vars = profile_vars.copy()
    context = {
        'fs_server': settings.FREESWITCH_DOMAIN,
        'tab': request.GET.get('tab'),
    }
    q_string = {}
    containers = {}
    shopper = get_shopper(request)
    if not shopper:
        return redirect(reverse('%s:%s' % (CUR_APP, 'login')))

    if request.method == 'POST':
        result = update_profile_from_site(request)
        if isinstance(result, list):
            context['errors'] = result
        else:
            save_user_to_request(request, result)
            context['shopper'] = result.to_dict()
            context['redirect'] = reverse('%s:%s' % (CUR_APP, 'show_profile'))

    if request.is_ajax():
        return JsonResponse(context, safe=False)
    template = 'web/login/profile.html'

    page = SearchLink(q_string, request, containers)
    if not page:
        page = Blocks(name=mh_vars['singular_obj'])
    context['breadcrumbs'] = [{
        'name':
        'Ваш аккаунт',
        'link':
        reverse('%s:%s' % (CUR_APP, 'show_profile')),
    }]

    context['page'] = page
    context['containers'] = containers
    context['shopper'] = shopper
    #context['orders'] = Orders.objects.filter(shopper=shopper).order_by('-created')[:50]
    return render(request, template, context)
Beispiel #8
0
def registration(request):
    """Страничка для регистрации"""
    mh_vars = reg_vars.copy()
    context = {}
    q_string = {}
    containers = {}

    shopper = get_shopper(request)
    if shopper:
        return redirect(reverse('%s:%s' % (CUR_APP, 'show_profile')))
    # -----------
    # регистрация
    # -----------
    if request.method == 'POST':
        result = register_from_site(request)
        if isinstance(result, list):
            context['errors'] = result
        else:
            save_user_to_request(request, result)
            context['shopper'] = result.to_dict()
            context['redirect'] = reverse('%s:%s' % (CUR_APP, 'show_profile'))

    if request.is_ajax():
        return JsonResponse(context, safe=False)
    template = 'web/login/registration.html'

    page = SearchLink(q_string, request, containers)
    if not page:
        page = Blocks(name=reg_vars['singular_obj'])
    context['breadcrumbs'] = [{
        'name':
        mh_vars['singular_obj'],
        'link':
        reverse('%s:%s' % (CUR_APP, 'registration')),
    }]
    context['page'] = page
    context['containers'] = containers
    context['vk_link'] = VK().get_auth_user_link()
    context['yandex_link'] = Yandex().get_auth_user_link()

    return render(request, template, context)
Beispiel #9
0
def fs_shopper(request):
    """После регистрации и/или подтверждения номера,
       надо на свиче синхануть пользователя
       Пользователи сайта /freeswitch/admin/personal_users/
       :param request: HttpRequest
    """
    shopper = get_shopper(request)
    token = '0_o'
    endpoint = '/freeswitch/personal_users/sync/'
    params = {
        'userkey': '%s-%s' % (settings.FS_USER, shopper.id),
        'username': shopper.login,
        'phone': shopper.phone,
        'phone_confirmed': 1 if shopper.phone_confirmed else 0,
    }
    headers = {
        'token': token,
    }
    r = requests.post('%s%s' % (settings.FREESWITCH_DOMAIN, endpoint),
                      data=params,
                      headers=headers)