Пример #1
0
def settings():
    if is_logged_in():
        user_info = get_user_info()
        if check_if_user_exists(user_info['email']):
            data = get_user_data(user_info['email'])

            form = UpdateUserSettings()
            form.username.data = data["name"]
            if form.validate_on_submit():
                if form.username.raw_data[0] != data["name"]:
                    change_name(data["email"], form.username.raw_data[0])
                else:
                    flash("You haven't made any changes to your settings.",
                          "info")
                return redirect(url_for("tracker.settings"))

            return render_template("settings.html",
                                   title="Settings",
                                   logged_in=True,
                                   form=form,
                                   email=data["email"],
                                   name=data["name"],
                                   color=data["color"])

    flash("Unable to access settings without being logged in!", "danger")
    return redirect(url_for("tracker.home"))
Пример #2
0
def confirm_add_location():
    lat = request.args.get('lat')
    lng = request.args.get('lng')

    if not lat or not lng:
        flash("Sorry. We couldn't reach that location.")
        return redirect(url_for("tracker.locations"))

    if is_logged_in():
        user_info = get_user_info()
        if check_if_user_exists(user_info['email']):
            country = get_country_from_coordinates(lat, lng)
            if not country:
                return redirect(url_for("tracker.locations"))

            form = NewLocation()
            if form.validate_on_submit():
                add_location_to_db(user_info['email'], form.name.data, country,
                                   form.description.data, lat, lng,
                                   form.pin_color.data)
                return redirect(url_for("tracker.locations"))

            return render_template("confirm_location.html",
                                   title="Confirm Location",
                                   logged_in=True,
                                   country=country,
                                   form=form)

    flash("Unable to access the location page without being logged in!",
          "danger")
    return redirect(url_for("tracker.home"))
Пример #3
0
def add_flight():
    if is_logged_in():
        user_info = get_user_info()
        if check_if_user_exists(user_info['email']):
            return render_template("add_flight.html",
                                   title="Add Flight",
                                   logged_in=True,
                                   api_key=Config.API_KEY)

    flash("Unable to access the flights page without being logged in!",
          "danger")
    return redirect(url_for("tracker.home"))
Пример #4
0
def locations():
    if is_logged_in():
        user_info = get_user_info()

        if check_if_user_exists(user_info['email']):
            data = get_locations_from_db(user_info['email'])
            number_of_locations = len(data)
            return render_template("locations.html",
                                   title="Locations",
                                   logged_in=True,
                                   number_of_locations=number_of_locations,
                                   data=data)

    flash("Unable to access the location page without being logged in!",
          "danger")
    return redirect(url_for("tracker.home"))
Пример #5
0
def home():
    if is_logged_in():
        user_info = get_user_info()
        if check_if_user_exists(user_info['email']) is False:
            create_user(user_info['email'], user_info['given_name'])

        location_info = get_location_coordinates(user_info['email'])
        flight_info = get_flight_coordinates(user_info['email'])
        return render_template("home.html",
                               title="Home",
                               api_key=Config.API_KEY,
                               location_info=location_info,
                               flight_info=flight_info,
                               name=user_info['given_name'],
                               email=user_info['email'],
                               logged_in=True)

    flash("You need to login!", "info")
    return render_template("home.html", title="Home", logged_in=False)
Пример #6
0
def confirm_flight():
    lat1 = request.args.get('lat1')
    lng1 = request.args.get('lng1')
    lat2 = request.args.get('lat2')
    lng2 = request.args.get('lng2')

    if not lat1 or not lng1 or not lat2 or not lng2:
        flash("Sorry. We couldn't log that flight.")
        return redirect(url_for("tracker.flights"))

    if is_logged_in():
        user_info = get_user_info()
        if check_if_user_exists(user_info['email']):
            loc1 = get_location_from_coordinates(lat1, lng1)
            loc2 = get_location_from_coordinates(lat2, lng2)

            if not loc1 or not loc2:
                flash("Unable to access that specific location.", "danger")
                return redirect(url_for("tracker.flights"))

            form = NewFlight()
            if form.validate_on_submit():
                add_flight_to_db(user_info['email'], form.flight_name.data,
                                 loc1, lat1, lng1, loc2, lat2, lng2)
                return redirect(url_for("tracker.flights"))

            return render_template("confirm_flight.html",
                                   title="Confirm Flight",
                                   logged_in=True,
                                   form=form,
                                   loc1=loc1,
                                   loc2=loc2)

    flash("Unable to access the flights page without being logged in!",
          "danger")
    return redirect(url_for("tracker.home"))