Exemplo n.º 1
0
def subscribe_sms(request):
    mobile = request.POST.get("mobile_number")
    if not mobile:
        return HttpResponseJSON(
            {
                "status": "error",
                "desc": "mobile_number is missing",
                "code": errors.BASKET_USAGE_ERROR,
            },
            400,
        )

    country = request.POST.get("country", "us")
    language = request.POST.get("lang", "en-US")
    msg_name = request.POST.get("msg_name", "SMS_Android")
    vendor_id = get_sms_vendor_id(msg_name, country, language)
    if not vendor_id:
        if language != "en-US":
            # if not available in the requested language, try the default
            language = "en-US"
            vendor_id = get_sms_vendor_id(msg_name, country, language)

    if not vendor_id:
        return HttpResponseJSON(
            {
                "status": "error",
                "desc": "Invalid msg_name + country + language",
                "code": errors.BASKET_USAGE_ERROR,
            },
            400,
        )

    mobile = parse_phone_number(mobile, country)
    if not mobile:
        return HttpResponseJSON(
            {
                "status": "error",
                "desc": "mobile_number is invalid",
                "code": errors.BASKET_USAGE_ERROR,
            },
            400,
        )

    # only rate limit numbers here so we don't rate limit errors.
    if is_ratelimited(
            request,
            group="basket.news.views.subscribe_sms",
            key=lambda x, y: "%s-%s" % (msg_name, mobile),
            rate=PHONE_NUMBER_RATE_LIMIT,
            increment=True,
    ):
        raise Ratelimited()

    optin = request.POST.get("optin", "N") == "Y"

    add_sms_user.delay(msg_name, mobile, optin, vendor_id=vendor_id)
    return HttpResponseJSON({"status": "ok"})
Exemplo n.º 2
0
def subscribe_sms(request):
    mobile = request.POST.get('mobile_number')
    if not mobile:
        return HttpResponseJSON(
            {
                'status': 'error',
                'desc': 'mobile_number is missing',
                'code': errors.BASKET_USAGE_ERROR,
            }, 400)

    country = request.POST.get('country', 'us')
    language = request.POST.get('lang', 'en-US')
    msg_name = request.POST.get('msg_name', 'SMS_Android')
    vendor_id = get_sms_vendor_id(msg_name, country, language)
    if not vendor_id:
        if language != 'en-US':
            # if not available in the requested language, try the default
            language = 'en-US'
            vendor_id = get_sms_vendor_id(msg_name, country, language)

    if not vendor_id:
        return HttpResponseJSON(
            {
                'status': 'error',
                'desc': 'Invalid msg_name + country + language',
                'code': errors.BASKET_USAGE_ERROR,
            }, 400)

    mobile = parse_phone_number(mobile, country)
    if not mobile:
        return HttpResponseJSON(
            {
                'status': 'error',
                'desc': 'mobile_number is invalid',
                'code': errors.BASKET_USAGE_ERROR,
            }, 400)

    # only rate limit numbers here so we don't rate limit errors.
    if is_ratelimited(request,
                      group='basket.news.views.subscribe_sms',
                      key=lambda x, y: '%s-%s' % (msg_name, mobile),
                      rate=PHONE_NUMBER_RATE_LIMIT,
                      increment=True):
        raise Ratelimited()

    optin = request.POST.get('optin', 'N') == 'Y'

    add_sms_user.delay(msg_name, mobile, optin, vendor_id=vendor_id)
    return HttpResponseJSON({'status': 'ok'})
Exemplo n.º 3
0
Arquivo: views.py Projeto: pmac/basket
def subscribe_sms(request):
    mobile = request.POST.get('mobile_number')
    if not mobile:
        return HttpResponseJSON({
            'status': 'error',
            'desc': 'mobile_number is missing',
            'code': errors.BASKET_USAGE_ERROR,
        }, 400)

    country = request.POST.get('country', 'us')
    language = request.POST.get('lang', 'en-US')
    msg_name = request.POST.get('msg_name', 'SMS_Android')
    vendor_id = get_sms_vendor_id(msg_name, country, language)
    if not vendor_id:
        if language != 'en-US':
            # if not available in the requested language, try the default
            language = 'en-US'
            vendor_id = get_sms_vendor_id(msg_name, country, language)

    if not vendor_id:
        return HttpResponseJSON({
            'status': 'error',
            'desc': 'Invalid msg_name + country + language',
            'code': errors.BASKET_USAGE_ERROR,
        }, 400)

    mobile = parse_phone_number(mobile, country)
    if not mobile:
        return HttpResponseJSON({
            'status': 'error',
            'desc': 'mobile_number is invalid',
            'code': errors.BASKET_USAGE_ERROR,
        }, 400)

    # only rate limit numbers here so we don't rate limit errors.
    if is_ratelimited(request, group='basket.news.views.subscribe_sms',
                      key=lambda x, y: '%s-%s' % (msg_name, mobile),
                      rate=PHONE_NUMBER_RATE_LIMIT, increment=True):
        raise Ratelimited()

    optin = request.POST.get('optin', 'N') == 'Y'

    add_sms_user.delay(msg_name, mobile, optin, vendor_id=vendor_id)
    return HttpResponseJSON({'status': 'ok'})
Exemplo n.º 4
0
def add_sms_user(send_name, mobile_number, optin, vendor_id=None):
    # Adding vendor_id as optional to avoid issues with deployment.
    # Old tasks with the old sitnature will be on the queue when this is first deployed.
    # TODO change the task signature to replace send_name with vendor_id
    if not vendor_id:
        vendor_id = get_sms_vendor_id(send_name)
        if not vendor_id:
            return

    sfmc.send_sms(mobile_number, vendor_id)
    if optin:
        add_sms_user_optin.delay(mobile_number)
Exemplo n.º 5
0
def add_sms_user(send_name, mobile_number, optin, vendor_id=None):
    # Adding vendor_id as optional to avoid issues with deployment.
    # Old tasks with the old sitnature will be on the queue when this is first deployed.
    # TODO change the task signature to replace send_name with vendor_id
    if not vendor_id:
        vendor_id = get_sms_vendor_id(send_name)
        if not vendor_id:
            return

    sfmc.send_sms(mobile_number, vendor_id)
    if optin:
        add_sms_user_optin.delay(mobile_number)