def get_propeties_list():
    """Have user confirm the search results.
    Upon confirmation, add property to session.
    Show list of properties stored in the session."""

    
    #Get the properties stored in session or create an empty session
    #Turn the list of properties into a set to get rid of repeats
    props_in_set = set(session.get('properties',[]))

    # Our output cart will be a dictionary (so we can easily see if we
    # already have the property in there
    properties = []
    used_color_map = session.get('used_color_map', {})

    # Loop over the ZPIDs in the session cart and add each one to
    # the output cart

    for zpid in props_in_set:
        house_data = Property.query.get(zpid)
        if house_data is not None:
            properties.append(house_data)
            if str(zpid) not in used_color_map:
                rgb_tuple = RGB_TUPLES.pop()
                r,g,b = rgb_tuple
                hex_color_string = HEX_COLOR_STRINGS.pop()
                color_map = {'r': r, 'g': g, 'b': b, 'hex': hex_color_string}
                used_color_map[str(zpid)] = color_map


    session['used_color_map'] = used_color_map
    user_id = session.get('user_id')
    liked = None

    if user_id:
        results = db.session.query(UserProperty.zpid).filter_by(user_id=user_id).all()
        liked = [zpid for (zpid, ) in results]

    props_in_table = [int(x) for x in session.get('comp_table',[])]

    page_state = request.args.get('view-state', 0)

    return render_template("left-column.html", properties=properties, liked=liked, props_in_table=props_in_table, used_color_map=used_color_map, page_state=int(page_state))
def login_process():
    """Process login."""

    # Get form variables
    email = request.form["email"]
    password = request.form["password"]

    user = User.query.filter_by(email=email).first()

    if not user:
        flash("No such user. Please register an account.")
        return "register"

    # if user.password != password:
    if not user.check_password(password):
        flash("Incorrect password")
        return "incorrectlogin"

    session["user_id"] = user.user_id

    liked = UserProperty.query.filter_by(user_id=user.user_id).all()
    liked = [x.zpid for x in liked]

    session['properties'] = liked
    session['comp_table'] = []
    session['used_color_map']={}

    for zpid in liked:
        if str(zpid) not in session['used_color_map']:
            rgb_tuple = RGB_TUPLES.pop()
            r,g,b = rgb_tuple
            hex_color_string = HEX_COLOR_STRINGS.pop()
            color_map = {'r': r, 'g': g, 'b': b, 'hex': hex_color_string}
            session['used_color_map'][str(zpid)] = color_map


    flash("Hello, %s!" % user.fname)

    return render_template("session-login.html", session=session)