コード例 #1
0
def report_view(user_id: int):
    account_id = cf.check_valid_account_cookie(flask.request)
    user = cf.return_user(account_id)
    if not user:
        return flask.redirect('/login')

    is_child = False
    if user.user_type:  # User is parent
        children = cf.return_connected_children(user.id)  # Returns parent's
        # Child connections
        if not children:
            return flask.redirect(
                "/home")  # Parent does not have any connections
        for child in children:
            if child.id == user_id:  # The child to view is connected to the parent
                is_child = True
        if not is_child:  # Parent does not have access to view these reports
            return flask.redirect("/home")

    else:  # User is child and thus cannot view any reports
        return flask.redirect("/home")

    user_report = cf.return_user(user_id)
    returned_reports = user_report.child_data[
        0].reports  # Reports are returned
    # And rendered

    return flask.render_template("/report/view_reports.html",
                                 report_list=returned_reports,
                                 user_name=user_report.user_name)
コード例 #2
0
def add_connection_post():
    account_id = cf.check_valid_account_cookie(flask.request)
    user = cf.return_user(account_id)
    if not user:
        return flask.redirect('/login')

    data_form = flask.request
    id = data_form.form.get("id")
    user_connect = cf.return_user(id)

    if user.user_type:  # User is paremt
        error = None
        if not user_connect:  # User with that ID does not exist
            error = "Input Error: User of that ID does not exist"
            # Parent already has connection with that child
        elif cf.check_connection_already_pending_or_exists(user_connect, user):
            error = "Input Error: Connection already exists"
        elif user_connect.user_type:  # Parent cannot have connection with another parent
            error = "Input Error: Requested connection is a parent user"
        if error:
            return flask.render_template("connection/connected_account.html",
                                         user_type=user.user_type,
                                         error=error)
        else:
            cf.create_connection(user_connect,
                                 user)  # Connection is established

    else:  # If the user is a child
        response = data_form.form.get("response")
        if response == "accept":
            cf.update_connection(user, user_connect)  # Connection is accepted
        else:
            cf.delete_connection(user, user_connect)  # Connection is declined

    return flask.redirect("/home")  # User returned to home
コード例 #3
0
def view_account_get():
    account_id = cf.check_valid_account_cookie(flask.request)
    user = cf.return_user(account_id)
    if not user:
        return flask.redirect('/login')

    if user.user_type:
        num_connections = len(user.parent_data[0].child_connections)
        num_reports = 0
        location = 'N/A'
        user_type_str = "Parent"
    else:
        num_connections = len(user.child_data[0].parent_connections)
        num_reports = len(user.child_data[0].reports)
        location = user.child_data[0].current_location
        if location:
            location_list = location.split(":")
            if len(location_list) > 1:
                if location_list[0] == "None":
                    location = f"Lat={round(float(location_list[1]),2)} - Long={round(float(location_list[2]),2)}"
                else:
                    location = location_list[0]
        else:
            location = "None"

        user_type_str = "Child"


    return flask.render_template("/account/view_user.html",num_connections=num_connections, num_reports=num_reports,
                                 user=user, user_type_str= user_type_str, location=location)
コード例 #4
0
def main_home_view():
    account_id = cf.check_valid_account_cookie(flask.request)
    user = cf.return_user(account_id)
    if not user:
        return flask.redirect('/login')

    current_time = datetime.datetime.now()
    if user.user_type:  # If user is a parent, all the user's children are returned and displayed
        connected_children: CombinedUserAndChild = cf.return_connected_children_user(
            user.id)
        return flask.render_template("home/home.html",
                                     user_name=user.user_name,
                                     user_type=user.user_type,
                                     connected_user_list=connected_children,
                                     show_report_message=False,
                                     current_time=current_time)

    returned_reports = user.child_data[0].reports
    report_expired = cf.check_if_report_is_valid(
        account_id)  # Checks if user needs to write daily report

    if cf.check_if_update_location_from_cookie(flask.request):
        return flask.redirect(
            "/add_location"
        )  # If the user's location cookie is out of date then they
        # are redirected to the add_location page
    return flask.render_template("home/home.html",
                                 user_name=user.user_name,
                                 user_type=user.user_type,
                                 report_list=returned_reports,
                                 show_report_message=not report_expired,
                                 current_time=current_time)
コード例 #5
0
def report_view_get():
    account_id = cf.check_valid_account_cookie(flask.request)
    user = cf.return_user(account_id)
    if not user:
        return flask.redirect('/login')

    # Checks that the user can write a valid report
    if not cf.check_if_report_is_valid(account_id):
        return flask.redirect("/home")

    return flask.render_template("/report/write_report.html")
コード例 #6
0
def index_view():
    if "guardian_account_cookie" not in flask.request.cookies:
        return flask.render_template("home/index.html")
    account_id = cf.check_valid_account_cookie(flask.request)
    user = cf.return_user(account_id)
    if user:
        return flask.redirect("/home")
    else:
        response = flask.redirect("/")
        cf.destroy_cookie(response)
        return response
コード例 #7
0
def location_view():
    account_id = cf.check_valid_account_cookie(flask.request)
    user = cf.return_user(account_id)
    if not user:
        return flask.redirect('/login')

    user_ip = flask.request.remote_addr
    redirect = flask.redirect("/home")
    if cf.check_if_update_location_from_cookie(flask.request):
        cf.update_time_cookie(redirect)
        cf.update_location(user_ip, account_id)
    return redirect
コード例 #8
0
def add_connection_get():
    account_id = cf.check_valid_account_cookie(flask.request)
    user = cf.return_user(account_id)
    if not user:
        return flask.redirect('/login')

    if user.user_type:  # User is parent
        return flask.render_template("connection/connected_account.html",
                                     user_type=user.user_type)

    parents = []  # Returns all the pending connections to the child user
    pending_connections = cf.return_pending_connections(user.id)
    for connection in pending_connections:
        parent: User = cf.return_user(connection.parent_id)
        parents.append(
            parent
        )  # All parent users who want to connect with the user are displayed

    return flask.render_template("connection/connected_account.html",
                                 user_type=user.user_type,
                                 parents=parents)
コード例 #9
0
def report_view_post():
    account_id = cf.check_valid_account_cookie(flask.request)
    user = cf.return_user(account_id)
    if not user:
        return flask.redirect('/login')

    data_form = flask.request

    title = data_form.form.get('Title')
    description = data_form.form.get('Description')

    if not title or not description:
        return flask.redirect("/report/write_report")

    # Creates report for that child
    cf.create_report(account_id, title, description)
    return flask.redirect('/home')
コード例 #10
0
def login_get():
    account_id = cf.check_valid_account_cookie(flask.request)
    user = cf.return_user(account_id)
    if user:
        return flask.redirect('/home') # Redirects to home if a valid cookie is found
    return flask.render_template("account/register_login.html", Page_Type="login")
コード例 #11
0
def register_get():
    account_id = cf.check_valid_account_cookie(flask.request)
    user = cf.return_user(account_id)
    if user:
        return flask.redirect('/login') # If valid cookie found redirect to login page
    return flask.render_template("account/register_login.html", Page_Type="register")