Example #1
0
def send_sms_verification(request):
    country_code = request.POST.get("country_code")
    local_phone = request.POST.get("local_phone")
    test_key = request.POST.get("test_key", None)

    if not local_phone:
        return HttpResponseBadRequest("missing phone parameter")

    country = get_object_or_404(Country, code=country_code)
    phone = get_international_phone(country, local_phone)

    if local_phone == settings.APPLE_TESTER_PHONE_NUMBER:
        code = str(
            set_session_sms_code(request,
                                 phone,
                                 code=settings.APPLE_TESTER_VERIFICATION))
    elif test_key == SELENIUM_TEST_KEY:
        code = str(
            set_session_sms_code(request,
                                 phone,
                                 code=SELENIUM_VERIFICATION_CODE))
    else:
        code = str(set_session_sms_code(request, phone))
        send_sms(local_phone, _("Verification code: %s") % code)

    logging.info("Sending SMS verification code: %s" % code)
    return HttpResponse("OK")
Example #2
0
def notify_passenger(passenger, message, data=None, force_sms=False):
    logging.info(u"notification: sending push message '%s' to passenger [%s]" % (message, passenger.id))
    res = False
    if force_sms and passenger.phone:
        sms_id = send_sms(passenger.phone, message)
        if sms_id and not settings.DEV:
            deferred.defer(track_sms, passenger, sms_id, _countdown=SMS_DELIVERY_GRACE)

        return sms_id is not None

    if passenger.push_token:
        if not PUSH_BACKEND.is_active(passenger.push_token, passenger.mobile_platform):
            logging.warning(u"notification: push sent to inactive device: %s" % passenger.push_token)

        res = PUSH_BACKEND.push(passenger.push_token, passenger.mobile_platform, message, data)

    elif passenger.phone: # fallback
        sms_id = send_sms(passenger.phone, message)
        if sms_id and not settings.DEV:
            deferred.defer(track_sms, passenger, sms_id, _countdown=SMS_DELIVERY_GRACE)

        return sms_id is not None

    else:
        logging.warning("notification: send push with no token and no phone")

    logging.info("notification: send push result: %s" % res)
    return res # couldn't send :(
def workstation_exit(request):
    workstation_id = request.GET.get("id")
    ws = WorkStation.by_id(workstation_id)
    if ws and not ws.station.debug:
        msg = u"%s closed the workstation module" % ws.station.name
        notify_by_email("Module Closed by Station", msg=msg)

        for num in CRITICAL_MESSAGES_CONTACT_LIST:
            send_sms(num, msg)

    return HttpResponse("OK")
def workstation_exit(request):
    workstation_id = request.GET.get("id")
    ws = WorkStation.by_id(workstation_id)
    if ws and not ws.station.debug:
        msg = u"%s closed the workstation module" % ws.station.name
        notify_by_email("Module Closed by Station", msg=msg)

        for num in CRITICAL_MESSAGES_CONTACT_LIST:
            send_sms(num, msg)

    return HttpResponse("OK")
Example #5
0
def send_msg_to_passenger(passenger, msg):
    if not msg:
        logging.error("skipping msg to passenger [%d]: empty msg" % passenger.id)
    elif passenger.business:
        send_channel_msg_to_passenger(passenger, msg)
    else:
        phone = passenger.international_phone()
        if phone:
            logging.info("sending message passenger [%d]: %s" % (passenger.id, msg))
            send_sms(phone, msg)
        else:
            logging.error("Passenger [%d] missing phone - skipping message: %s" % (passenger.id, msg))
def send_ride_in_risk_notification(msg, ride_id):
    msg_key = u"%s_%s" % (ride_id, msg)
    namespace = "ride_in_risk_notifications"

    msg_sent = memcache.get(msg_key, namespace=namespace)
    if msg_sent:
        logging.info(u"skipping sending: %s" % msg)
        return

    ride = SharedRide.by_id(ride_id)
    if ride and ride.debug:
        logging.info("skipping notification for debug ride %s" % ride_id)

    elif ride:
        t = get_template("ride_in_risk_email.html")
        orders = ride.orders.all()
        passengers = [o.passenger for o in orders.all()]
        station = ride.station
        try:
            sharing_ws = station.work_stations.filter(
                accept_shared_rides=True)[0]
        except Exception:
            sharing_ws = None

        html = t.render(
            Context({
                "passengers":
                [u"%s (%s)" % (p.full_name, p.phone) for p in passengers],
                "station_phones":
                station.phones.all() if station else [],
                "station_name":
                station.name if station else "[NO STATION]",
                "online_status":
                sharing_ws.is_online if sharing_ws else None,
                "ride_id":
                ride_id,
                "depart_time":
                ride.depart_time.strftime("%H:%M"),
                "ride_status":
                RideStatus.get_name(ride.status),
                "msg":
                msg
            }))
        logging.info("sending risk mail: %s" % html)

        notify_by_email("IMPORTANT: Ride In Risk [%s]" % ride_id, html=html)
        memcache.set(msg_key, True, namespace=namespace)

        for num in CRITICAL_MESSAGES_CONTACT_LIST:
            send_sms(num, msg)
Example #7
0
def send_msg_to_passenger(passenger, msg):
    if not msg:
        logging.error("skipping msg to passenger [%d]: empty msg" %
                      passenger.id)
    elif passenger.business:
        send_channel_msg_to_passenger(passenger, msg)
    else:
        phone = passenger.international_phone()
        if phone:
            logging.info("sending message passenger [%d]: %s" %
                         (passenger.id, msg))
            send_sms(phone, msg)
        else:
            logging.error(
                "Passenger [%d] missing phone - skipping message: %s" %
                (passenger.id, msg))
def send_sms_verification(request):
    country_code = request.POST.get("country_code")
    local_phone = request.POST.get("local_phone")
    test_key = request.POST.get("test_key", None)

    if not local_phone:
        return HttpResponseBadRequest("missing phone parameter")

    country = get_object_or_404(Country, code=country_code)
    phone = get_international_phone(country, local_phone)

    if local_phone == settings.APPLE_TESTER_PHONE_NUMBER:
        code = str(set_session_sms_code(request, phone, code=settings.APPLE_TESTER_VERIFICATION))
    elif test_key == SELENIUM_TEST_KEY:
        code = str(set_session_sms_code(request, phone, code=SELENIUM_VERIFICATION_CODE))
    else:
        code = str(set_session_sms_code(request, phone))
        send_sms(local_phone, _("Verification code: %s") % code)

    logging.info("Sending SMS verification code: %s" % code)
    return HttpResponse("OK")
def send_ride_in_risk_notification(msg, ride_id):
    msg_key = u"%s_%s" % (ride_id, msg)
    namespace = "ride_in_risk_notifications"

    msg_sent = memcache.get(msg_key, namespace=namespace)
    if msg_sent:
        logging.info(u"skipping sending: %s" % msg)
        return

    ride = SharedRide.by_id(ride_id)
    if ride and ride.debug:
        logging.info("skipping notification for debug ride %s" % ride_id)

    elif ride:
        t = get_template("ride_in_risk_email.html")
        orders = ride.orders.all()
        passengers = [o.passenger for o in orders.all()]
        station = ride.station
        try:
            sharing_ws = station.work_stations.filter(accept_shared_rides=True)[0]
        except Exception:
            sharing_ws = None

        html = t.render(Context({
            "passengers": [u"%s (%s)" % (p.full_name, p.phone) for p in passengers],
            "station_phones": station.phones.all() if station else [],
            "station_name": station.name if station else "[NO STATION]",
            "online_status": sharing_ws.is_online if sharing_ws else None,
            "ride_id": ride_id,
            "depart_time": ride.depart_time.strftime("%H:%M"),
            "ride_status": RideStatus.get_name(ride.status),
            "msg": msg
        }))
        logging.info("sending risk mail: %s" % html)

        notify_by_email("IMPORTANT: Ride In Risk [%s]" % ride_id, html=html)
        memcache.set(msg_key, True, namespace=namespace)

        for num in CRITICAL_MESSAGES_CONTACT_LIST:
            send_sms(num, msg)
Example #10
0
def notify_passenger(passenger, message, data=None, force_sms=False):
    logging.info(u"notification: sending push message '%s' to passenger [%s]" %
                 (message, passenger.id))
    res = False
    if force_sms and passenger.phone:
        sms_id = send_sms(passenger.phone, message)
        if sms_id and not settings.DEV:
            deferred.defer(track_sms,
                           passenger,
                           sms_id,
                           _countdown=SMS_DELIVERY_GRACE)

        return sms_id is not None

    if passenger.push_token:
        if not PUSH_BACKEND.is_active(passenger.push_token,
                                      passenger.mobile_platform):
            logging.warning(u"notification: push sent to inactive device: %s" %
                            passenger.push_token)

        res = PUSH_BACKEND.push(passenger.push_token,
                                passenger.mobile_platform, message, data)

    elif passenger.phone:  # fallback
        sms_id = send_sms(passenger.phone, message)
        if sms_id and not settings.DEV:
            deferred.defer(track_sms,
                           passenger,
                           sms_id,
                           _countdown=SMS_DELIVERY_GRACE)

        return sms_id is not None

    else:
        logging.warning("notification: send push with no token and no phone")

    logging.info("notification: send push result: %s" % res)
    return res  # couldn't send :(
Example #11
0
 def test_send_sms(self):
     logging.info("\nTesting sms sending")
     self.assertTrue(send_sms('0526342974', 'sms test'),
                     msg="sms send failed")
Example #12
0
 def test_send_sms(self):
     logging.info("\nTesting sms sending")
     self.assertTrue(send_sms('0526342974', 'sms test'), msg="sms send failed")