def _audit_title_viewed(title_number, username):
    # This puts something in our audit logs of what a user/ip address viewed at what time
    ip_address = utils.get_ip_address()
    date_and_time_viewed = datetime.now()
    auditing.audit(
        "VIEWED TITLE ON CONFIRM PAGE: Title number {0} was viewed by {3} on ip address {1} viewed on {2}"
        .format(title_number, ip_address, date_and_time_viewed, username))
    def registration_successful(title_number, search_term):
        ip_address = utils.get_ip_address()
        auditing.audit("ACCOUNT CREATED: IP Address {0} ".format(ip_address))

        # If we've been redirected here from the account creation form, render the success message
        if request.referrer and url_for('create_account') in request.referrer:
            if title_number and search_term:
                return render_template(
                    'account/registration_successful.html',
                    title_number=encryption_utils.encrypt(title_number),
                    search_term=search_term)
            else:
                return render_template('account/registration_successful.html')

        # Otherwise the user has managed to arrive here "directly" such as via entering the url manually
        # In this situation we redirect them on to the search page
        return redirect(url_for('search'))
Ejemplo n.º 3
0
def get_service(request):
    """
    Save post data to the model.
    Args:
        request (object):

    Returns:
        response (object): Return address data JsonResponse if POST request, else render to homepage.
    """

    data = {}
    address_data = {}
    if request.POST:
        post_data = request.POST
        loc_latitude = post_data.get('loc_latitude', "")
        loc_longitude = post_data.get('loc_longitude', "")
        ip_address = utils.get_ip_address(request)

        # Check if latitude and longitude are not present
        if not (loc_latitude and loc_longitude):
            loc_latitude, loc_longitude = utils.get_latlong(ip_address)

        if loc_latitude and loc_longitude:
            formatted_address = utils.get_formatted_address(
                loc_latitude, loc_longitude)

            if formatted_address:
                address_data = {
                    "formatted_address": formatted_address,
                    "latitude": loc_latitude,
                    "longitude": loc_longitude
                }
                data = {
                    "loc_latitude": loc_latitude,
                    "loc_longitude": loc_longitude,
                    "seeker_ip": ip_address
                }
                serializer = ServiceSeekerSerializer(data=data)
                if serializer.is_valid():
                    serializer.save()
        response = JsonResponse(json.dumps(address_data), safe=False)
        return response
    else:
        response = render(request, "service/home.html")
        return response
    def get_account_details():
        ip_address = utils.get_ip_address()

        LOGGER.debug(
            "STARTED: get-account-details email -: {0} from IP: {1}".format(
                request.form.get('email'), ip_address))

        # Pass request straight through to public-account-services-api
        status = 200
        try:
            data = api_client.get_account_details(request.form['email'])
        except requests.exceptions.HTTPError as e:
            LOGGER.debug("get-account-details email not found -: {0}".format(
                request.form.get('email')))

            data = {}
            status = e.response.status_code

        LOGGER.debug("ENDED: get-account-details")
        return jsonify(data), status
Ejemplo n.º 5
0
def get_titles_by_postcode(postcode, page_number):
    LOGGER.debug(
        "STARTED: get_titles_by_postcode postcode, pagenumber: {0}, {1}".
        format(postcode, page_number))
    try:
        response = requests.get('{}/title_search_postcode/{}'.format(
            REGISTER_TITLE_API_URL, postcode),
                                params={
                                    'page': page_number,
                                    'user_ip': get_ip_address()
                                })
        response.raise_for_status()

    except requests.exceptions.HTTPError as e:
        if e.response.status_code == 429:
            raise SearchRateLimitExceeded(response) from e
        else:
            raise

    LOGGER.debug("get_titles_by_postcode {0}".format(response))
    LOGGER.debug("ENDED: get_titles_by_postcode")
    return _to_json(response)