def profile():
    is_login = cookie_check()
    if not is_login:
        flash("not logged in")
        return redirect(url_for("welcome"))
    else:
        pass
    # Assume we have the following variables resolved
    _user_name = request.cookies.get("username")
    print "get username: "******"profile.html",
                           username = _user_name,
                           nickname = _nick_name,
                           email = _email,
                           phone = _phone,
                           gender = _gender,
                           facebook = _facebook,
						   avatar = figure)
Example #2
0
def profile():
    is_login = cookie_check()
    if not is_login:
        flash("not logged in")
        return redirect(url_for("welcome"))
    else:
        pass
    # Assume we have the following variables resolved
    _user_name = request.cookies.get("username")
    print "get username: "******"profile.html",
                           username=_user_name,
                           nickname=_nick_name,
                           email=_email,
                           phone=_phone,
                           gender=_gender,
                           facebook=_facebook,
                           avatar=figure)
Example #3
0
def welcome():
    is_login = cookie_check()
    if is_login == True:
        # when user has a cookie, login if the cookie is correct
        return redirect(url_for("log_in_auth"))
        #return render_template("welcome.html")
    else:
        # when cookie is not correct or no cookie, go welcome page
        return render_template("welcome.html")
def welcome():
    is_login = cookie_check()
    if is_login == True:
        # when user has a cookie, login if the cookie is correct
        return redirect(url_for("log_in_auth"))
        #return render_template("welcome.html")
    else:
        # when cookie is not correct or no cookie, go welcome page
        return render_template("welcome.html")
Example #5
0
def decline_proposal():
    is_login = cookie_check()
    if not is_login:
        flash("not logged in")
        return redirect(url_for("welcome"))
    else:
        pass
    # The ID of declined user is passed in URL
    userid = request.cookies.get("username")
    # The ID of decline user should be get in cookie
    friendid = request.args.get("friendid")
    decline_match(userid, friendid)
    flash("Have declined the proposal!")
    return redirect(url_for("dashboard"))
def decline_proposal():
    is_login = cookie_check()
    if not is_login:
        flash("not logged in")
        return redirect(url_for("welcome"))
    else:
        pass
    # The ID of declined user is passed in URL
    userid = request.cookies.get("username")
    # The ID of decline user should be get in cookie
    friendid = request.args.get("friendid")
    decline_match(userid, friendid)
    flash("Have declined the proposal!")
    return redirect(url_for("dashboard"))
Example #7
0
def dashboard():

    is_login = cookie_check()
    if not is_login:
        flash("not logged in")
        return redirect(url_for("welcome"))

    # TODO: need to get a lot of info from database
    # 1) get current userid

    userid = request.cookies.get("username")
    friendid = ""
    matched_person = {
    }  # a dict, keys = ["id", "name", "gender", "phone", "facebook"]
    recommend_restaurants = [
    ]  # a list, each is a dict, keys = ["name", "address", "star"]

    # 2) first know if there is any pending match
    pending_flag, matched_person1 = check_match(userid)

    # 3) second check recommendation
    # attention, matched_person would be empty if both 1&2 is empty
    matched_person2, recommend_restaurants = check_recommendation(userid)

    # 4) merge the result of matched_person
    if bool(matched_person1) or bool(matched_person2):
        if bool(matched_person1):
            matched_person = matched_person1
            friendid = matched_person1["id"]
        else:
            matched_person = matched_person2
            friendid = matched_person2["id"]
    else:
        matched_person = {}

    _status = pending_flag  # THIS IS A BOOLEAN VALUE that if True-> enable accept/decline
    # if false -> disable accept/decline
    figure = maptofigure(userid)

    return render_template(
        "dashboard.html",
        person=matched_person,
        restaurants=recommend_restaurants,
        status=_status,
        avatar=figure)  # ADD friendid as a variable that won't display
def dashboard():

    is_login = cookie_check()
    if not is_login:
        flash("not logged in")
        return redirect(url_for("welcome"))

    # TODO: need to get a lot of info from database
    # 1) get current userid

    userid = request.cookies.get("username")
    friendid = ""
    matched_person = {}  # a dict, keys = ["id", "name", "gender", "phone", "facebook"]
    recommend_restaurants = []  # a list, each is a dict, keys = ["name", "address", "star"]

    # 2) first know if there is any pending match
    pending_flag, matched_person1 = check_match(userid)

    # 3) second check recommendation
    # attention, matched_person would be empty if both 1&2 is empty
    matched_person2, recommend_restaurants = check_recommendation(userid)

    # 4) merge the result of matched_person
    if bool(matched_person1) or bool(matched_person2):
        if bool(matched_person1):
            matched_person = matched_person1
            friendid = matched_person1["id"]
        else:
            matched_person = matched_person2
            friendid = matched_person2["id"]
    else:
        matched_person = {}

    _status = pending_flag  # THIS IS A BOOLEAN VALUE that if True-> enable accept/decline
                            # if false -> disable accept/decline
    figure = maptofigure(userid)
	
    return render_template("dashboard.html", person=matched_person,
                           restaurants=recommend_restaurants,
                           status=_status,
						   avatar = figure) # ADD friendid as a variable that won't display
Example #9
0
def log_in_auth():
    is_login = cookie_check()
    if is_login == True:
        # if user has correct cookie, go to dashboard page
        return redirect(url_for("dashboard"))
    elif is_login == False:
        # inform the user that the session has expired
        flash("Your information is not in our database.")
        return redirect(url_for("welcome"))
    else:
        # If the user doesn't have a cookie, it must have filled the form
        if not validate_email(request.form["email"]):
            flash("Your email is not valid. Please check the input.")
            return redirect(url_for("welcome"))

        # Set cookie if the user could login
        print "GOT EMAIL ::" + request.form["email"] + "\n"
        print "GOT PASSWORD ::" + request.form["password"] + "\n"

        can_login, username, password = check_user(request.form["email"],
                                                   request.form["password"])
        if can_login:
            #resp = redirect(url_for("dashboard"))
            s = session
            s.username = username
            print "SET USERNAME :: " + str(username) + "\n"
            print "SET PASSWORD :: " + str(password) + "\n"
            s.password = password
            #if s.setSession:
            #resp = make_response(render_template("dashboard.html"))
            resp = make_response(redirect('/dashboard'))
            resp.set_cookie("username", username)
            resp.set_cookie("password", password)
            #resp.set_cookie('session_id', s.session_id)
            print "coockie setted"
            return resp
        else:
            flash("Your email or password is not in our database.")
            return redirect(url_for("welcome"))
def log_in_auth():
    is_login = cookie_check()
    if is_login == True:
        # if user has correct cookie, go to dashboard page
        return redirect(url_for("dashboard"))
    elif is_login == False:
        # inform the user that the session has expired
        flash("Your information is not in our database.")
        return redirect(url_for("welcome"))
    else:
        # If the user doesn't have a cookie, it must have filled the form
        if not validate_email(request.form["email"]):
            flash("Your email is not valid. Please check the input.")
            return redirect(url_for("welcome"))

        # Set cookie if the user could login
        print "GOT EMAIL ::" + request.form["email"] +"\n"
        print "GOT PASSWORD ::" + request.form["password"] +"\n"

        can_login, username, password = check_user(request.form["email"], request.form["password"])
        if can_login:
            #resp = redirect(url_for("dashboard"))
            s = session
            s.username = username
            print "SET USERNAME :: " + str(username) +"\n"
            print "SET PASSWORD :: " + str(password) +"\n"
            s.password = password
            #if s.setSession:
            #resp = make_response(render_template("dashboard.html"))
            resp = make_response(redirect('/dashboard'))
            resp.set_cookie("username", username)
            resp.set_cookie("password", password)
            #resp.set_cookie('session_id', s.session_id)
            print "coockie setted"
            return resp
        else:
            flash("Your email or password is not in our database.")
            return redirect(url_for("welcome"))
Example #11
0
def new_proposal():
    # Only works when user login
    is_login = cookie_check()
    if is_login:
        # The following data will be collected here
        # request.form["date"]  xxxx-xx-xx
        # request.form["starthour"]
        # request.form["startmin"]
        # request.form["endhour"]
        # request.form["endmin"]
        # request.form["foodtype"]
        # request.form["distance"]
        # request.form["budget"]
        # request.form["gender"]
        if not validate_date(request.form["date"]):
            flash(
                "Your appointment date is not valid. Please check the input.")
            return redirect(url_for("dashboard"))
        if not validate_hour(request.form["starthour"]):
            flash(
                "Your appointment start hour is not valid. Please check the input."
            )
            return redirect(url_for("dashboard"))
        if not validate_minute(request.form["startmin"]):
            flash(
                "Your appointment start minute is not valid. Please check the input."
            )
            return redirect(url_for("dashboard"))
        if not validate_hour(request.form["endhour"]):
            flash(
                "Your appointment end hour is not valid. Please check the input."
            )
            return redirect(url_for("dashboard"))
        if not validate_minute(request.form["endmin"]):
            flash(
                "Your appointment end minute is not valid. Please check the input."
            )
            return redirect(url_for("dashboard"))
        if not validate_empty_str(request.form["foodtype"]):
            flash("Your didn't select the perferred food type")
            return redirect(url_for("dashboard"))
        if not validate_gender(request.form["gender"]):
            flash(
                "Your preferred gender is not valid. Please check the input.")
            return redirect(url_for("dashboard"))

        # TODO: handle in database
        userid = request.cookies.get("username")

        date = request.form["date"]
        starthour = request.form["starthour"]
        startmin = request.form["startmin"]
        endhour = request.form["endhour"]
        endmin = request.form["endmin"]
        foodtype = request.form["foodtype"].lower()
        distance = request.form["distance"]
        budget = request.form["budget"]
        gender = request.form["gender"].lower()
        latitude = request.form["latitude"]  ##----string value
        longitude = request.form["longitude"]  ##----string value

        print "GET lati ::" + request.form["latitude"] + "\n"
        print "GET longi ::" + request.form["longitude"] + "\n"

        add_proposal(userid, date, starthour, startmin, endhour, endmin,
                     foodtype, distance, budget, gender, latitude, longitude)

        return redirect(url_for("dashboard"))
    else:
        #flash("404 Page Not Found")
        flash("not logged in")
        return redirect(url_for("welcome"))
def new_proposal():
    # Only works when user login
    is_login = cookie_check()
    if is_login:
        # The following data will be collected here
        # request.form["date"]  xxxx-xx-xx
        # request.form["starthour"]
        # request.form["startmin"]
        # request.form["endhour"]
        # request.form["endmin"]
        # request.form["foodtype"]
        # request.form["distance"]
        # request.form["budget"]
        # request.form["gender"]
        if not validate_date(request.form["date"]):
            flash("Your appointment date is not valid. Please check the input.")
            return redirect(url_for("dashboard"))
        if not validate_hour(request.form["starthour"]):
            flash("Your appointment start hour is not valid. Please check the input.")
            return redirect(url_for("dashboard"))
        if not validate_minute(request.form["startmin"]):
            flash("Your appointment start minute is not valid. Please check the input.")
            return redirect(url_for("dashboard"))
        if not validate_hour(request.form["endhour"]):
            flash("Your appointment end hour is not valid. Please check the input.")
            return redirect(url_for("dashboard"))
        if not validate_minute(request.form["endmin"]):
            flash("Your appointment end minute is not valid. Please check the input.")
            return redirect(url_for("dashboard"))
        if not validate_empty_str(request.form["foodtype"]):
            flash("Your didn't select the perferred food type")
            return redirect(url_for("dashboard"))
        if not validate_gender(request.form["gender"]):
            flash("Your preferred gender is not valid. Please check the input.")
            return redirect(url_for("dashboard"))

        # TODO: handle in database
        userid = request.cookies.get("username")

        date = request.form["date"]
        starthour = request.form["starthour"]
        startmin = request.form["startmin"]
        endhour = request.form["endhour"]
        endmin = request.form["endmin"]
        foodtype = request.form["foodtype"].lower()
        distance = request.form["distance"]
        budget = request.form["budget"]
        gender = request.form["gender"].lower()
        latitude = request.form["latitude"] ##----string value
        longitude = request.form["longitude"] ##----string value

	print "GET lati ::" + request.form["latitude"] +"\n"
	print "GET longi ::" + request.form["longitude"] +"\n"

        add_proposal(userid, date, starthour, startmin, endhour, endmin,
                     foodtype, distance, budget, gender, latitude, longitude)

	return redirect(url_for("dashboard"))
    else:
        #flash("404 Page Not Found")
        flash("not logged in")
        return redirect(url_for("welcome"))