def track_app_event(request):
    event_name = request.POST.get("name")
    logging.info("Track app event: %s" % event_name)

    passenger = Passenger.from_request(request)
    if event_name:
        if event_name == "APPLICATION_INSTALL":
            BIEvent.log(BIEventType.APP_INSTALL, request=request, passenger=passenger)
        elif event_name == "APPLICATION_OPEN":
            BIEvent.log(BIEventType.BOOKING_START, request=request, passenger=passenger)

    return HttpResponse("OK")
def booking_page(request, continued=False):
    lib_ng = True
    lib_map = True
    lib_geo = True

    if continued:
        continue_booking = simplejson.dumps(True)
    else:
        request.session[CURRENT_BOOKING_DATA_KEY] = None

    BIEvent.log(BIEventType.BOOKING_START, request=request, passenger=Passenger.from_request(request))

    return render_to_response("booking_page.html", locals(), RequestContext(request))
def registration(request, step="auth"):
    country_code = settings.DEFAULT_COUNTRY_CODE
    page_specific_class = "registration"
    login_controller_url = reverse("mobile_auth_login") if request.mobile else reverse("auth_login")

    BIEvent.log(BIEventType.REGISTRATION_START, request=request)

    login_link = "%s?next=%s" % (login_controller_url, reverse(post_login_redirect))
    form = UserRegistrationForm()

    ga_track_event(request, "registration", "register_now", "after_ordering" if request.session.get(CURRENT_BOOKING_DATA_KEY) else "direct")

    if request.user.is_authenticated() and step == "auth":
        return post_login_redirect(request)

    return custom_render_to_response("passenger_registration.html", locals(), context_instance=RequestContext(request))
def registration(request, step="auth"):
    country_code = settings.DEFAULT_COUNTRY_CODE
    page_specific_class = "registration"
    login_controller_url = reverse(
        "mobile_auth_login") if request.mobile else reverse("auth_login")

    BIEvent.log(BIEventType.REGISTRATION_START, request=request)

    login_link = "%s?next=%s" % (login_controller_url,
                                 reverse(post_login_redirect))
    form = UserRegistrationForm()

    ga_track_event(
        request, "registration", "register_now", "after_ordering"
        if request.session.get(CURRENT_BOOKING_DATA_KEY) else "direct")

    if request.user.is_authenticated() and step == "auth":
        return post_login_redirect(request)

    return custom_render_to_response("passenger_registration.html",
                                     locals(),
                                     context_instance=RequestContext(request))
Example #5
0
def transaction_ok(request):
    from analytics.models import BIEvent, BIEventType

    passenger = Passenger.from_request(request)
    if not passenger:
        logging.info("[transaction_ok] not a passenger")
        registration_url = reverse(mobile_registration_view if request.mobiel else web_registration_view)
        return HttpResponseRedirect(registration_url)

    #TODO: handle errors
    #TODO: makesure referrer is creditguard
    ga_track_event(request, "registration", "credit_card_validation", "approved")
    date_string = request.GET.get("cardExp")
    exp_date = date(year=int(date_string[2:]) + 2000, month=int(date_string[:2]), day=1)
    kwargs = {
        "passenger"			: passenger,
        "token"					: request.GET.get("cardToken"),
        "expiration_date"		: exp_date,
        "card_repr"				: request.GET.get("cardMask"),
        "personal_id"          : request.GET.get("personalId")
    }
    # clean up old billing info objects
    BillingInfo.objects.filter(passenger=passenger).delete()

    # save new billing info
    billing_info = BillingInfo(**kwargs)
    billing_info.save()

    BIEvent.log(BIEventType.BILLING_INFO_COMPLETE, passenger=passenger, request=request)

    if request.session.get(CURRENT_BOOKING_DATA_KEY): # continue booking process
        continue_booking_url = settings.CLOSE_CHILD_BROWSER_URI if request.mobile else reverse("booking_continued")
        logging.info("[transaction_ok] continue booking after billing registration --> %s" % continue_booking_url)
        return HttpResponseRedirect(continue_booking_url)
    else:
        account_url = reverse(mobile_account_view if request.mobile else web_account_view)
        return HttpResponseRedirect(account_url)
def registration_view(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse(account_view))

    if request.method == "GET":
        BIEvent.log(BIEventType.REGISTRATION_START, request=request)

        title = _("Join WAYbetter")
        return render_to_response("mobile/account_registration.html", locals(), RequestContext(request))

    elif request.method == "POST":
        email = request.POST.get("email")
        phone = request.POST.get("phone")

        try:
            validate_email(email)
        except ValidationError:
            return JSONResponse({"error": _("Invalid email")})

        # fail if email is registered
        if User.objects.filter(username=email).count() > 0:
            notify_by_email("Help! I can't register!", msg="email %s already registered\n%s" % (email, phone))
            return JSONResponse(
                {"account_exists": True, "error": _("This email address was registered by another user.")}
            )

        # fail if phone is registered to more than 1 passenger
        country = Country.objects.get(code=settings.DEFAULT_COUNTRY_CODE)
        existing_passengers = Passenger.objects.filter(phone=phone, country=country)
        if len(existing_passengers) > 1:
            notify_by_email(
                "Help! I can't register!",
                msg="phone %s registered to multiple passengers\n%s" % (phone, existing_passengers),
            )
            return JSONResponse(
                {
                    "failed": True,
                    "error": _(
                        "This phone number is registered to multiple passengers. Please contact support for help."
                    ),
                }
            )

        # fail if phone is registered to 1 passenger but this passenger has a user
        existing_passengers_users = [existing_passenger.user for existing_passenger in existing_passengers]
        if any(existing_passengers_users):
            notify_by_email(
                "Help! I can't register!",
                msg="phone %s already registered to another user\n%s\n%s" % (phone, email, existing_passengers_users),
            )
            return JSONResponse(
                {
                    "failed": True,
                    "error": _("This phone number was registered by another user. Please contact support for help."),
                }
            )

        # by now we know:
        # 1. email is not registered; we will create a new user
        # 2. phone is not registered; we will create a new passenger
        #   OR
        # 3. phone registered to a passenger with NO user; we will keep the passenger and create a user for her
        passenger = existing_passengers[0] if existing_passengers else None
        user = register_new_user(request, passenger)
        if user:
            redirect = settings.CLOSE_CHILD_BROWSER_URI
            return JSONResponse({"redirect": redirect, "billing_url": (get_token_url(request))})
        else:
            return JSONResponse({"error": _("Registration failed")})

    else:
        return HttpResponseNotAllowed(request.method)
Example #7
0
def registration_view(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse(account_view))

    if request.method == 'GET':
        BIEvent.log(BIEventType.REGISTRATION_START, request=request)

        title = _("Join WAYbetter")
        return render_to_response("mobile/account_registration.html", locals(),
                                  RequestContext(request))

    elif request.method == 'POST':
        email = request.POST.get("email")
        phone = request.POST.get("phone")

        try:
            validate_email(email)
        except ValidationError:
            return JSONResponse({'error': _("Invalid email")})

        # fail if email is registered
        if User.objects.filter(username=email).count() > 0:
            notify_by_email("Help! I can't register!",
                            msg="email %s already registered\n%s" %
                            (email, phone))
            return JSONResponse({
                'account_exists':
                True,
                'error':
                _("This email address was registered by another user.")
            })

        # fail if phone is registered to more than 1 passenger
        country = Country.objects.get(code=settings.DEFAULT_COUNTRY_CODE)
        existing_passengers = Passenger.objects.filter(phone=phone,
                                                       country=country)
        if len(existing_passengers) > 1:
            notify_by_email(
                "Help! I can't register!",
                msg="phone %s registered to multiple passengers\n%s" %
                (phone, existing_passengers))
            return JSONResponse({
                'failed':
                True,
                'error':
                _("This phone number is registered to multiple passengers. Please contact support for help."
                  )
            })

        # fail if phone is registered to 1 passenger but this passenger has a user
        existing_passengers_users = [
            existing_passenger.user
            for existing_passenger in existing_passengers
        ]
        if any(existing_passengers_users):
            notify_by_email(
                "Help! I can't register!",
                msg="phone %s already registered to another user\n%s\n%s" %
                (phone, email, existing_passengers_users))
            return JSONResponse({
                'failed':
                True,
                'error':
                _("This phone number was registered by another user. Please contact support for help."
                  )
            })

        # by now we know:
        # 1. email is not registered; we will create a new user
        # 2. phone is not registered; we will create a new passenger
        #   OR
        # 3. phone registered to a passenger with NO user; we will keep the passenger and create a user for her
        passenger = existing_passengers[0] if existing_passengers else None
        user = register_new_user(request, passenger)
        if user:
            redirect = settings.CLOSE_CHILD_BROWSER_URI
            return JSONResponse({
                'redirect': redirect,
                'billing_url': (get_token_url(request))
            })
        else:
            return JSONResponse({'error': _("Registration failed")})

    else:
        return HttpResponseNotAllowed(request.method)