def register_user_(): js = request.get_json(force=True) email = js.get('email') password = js.get('password') fname = js.get('fname') lname = js.get('lname') #Missing arguments if not email or not password or not fname or not lname: return abort(400) fname = formatting.stringify_sql(fname) lname = formatting.stringify_sql(lname) email = formatting.stringify_sql(email) if giftlydb.insert_user( (giftlydb.generate_uuid(), email, fname, lname, formatting.stringify_sql(encryption.hash_password(password)), '1')): values = giftlydb.select_values(values="USERID, EMAIL, FNAME, LNAME", table="User", where="EMAIL=" + email) value_dict = giftlydb.row_to_dict(values) userid = value_dict[0]['userid'] email = value_dict[0]['email'] lname = value_dict[0]['lname'] fname = value_dict[0]['fname'] return jsonify( formatting.format_user_json(userid=userid, email=email, lname=lname, fname=fname)) else: return abort(400)
def test(): values = giftlydb.select_values(values="USERID, EMAIL, FNAME, LNAME, STATE", table="User") if values: value_dict = giftlydb.row_to_dict(values) dicts = {} for dict in value_dict: value_dict = giftlydb.row_to_dict(values) userid = dict['userid'] email = dict['email'] lname = dict['lname'] fname = dict['fname'] dicts[email] = formatting.format_user_json(userid=userid, email=email, lname=lname, fname=fname) print "dict" print dicts return jsonify({"users":dicts})
def get_user_friend(): js = request.get_json(force=True) userid = js.get('userid') friendid = js.get('friendid') if userid and friendid: value = giftlydb.select_values(values="NAME, DOB, STATE", table="Friend", where=("USERID="+userid + "AND FRIENDID="+friendid)) return json.dumps(giftlydb.row_to_dict(value)) else: return jsonify({"userid":userid, "friendid":friendid, "exists":"False", "response":200})
def test(): values = giftlydb.select_values( values="USERID, EMAIL, FNAME, LNAME, STATE", table="User") if values: value_dict = giftlydb.row_to_dict(values) dicts = {} for dict in value_dict: value_dict = giftlydb.row_to_dict(values) userid = dict['userid'] email = dict['email'] lname = dict['lname'] fname = dict['fname'] dicts[email] = formatting.format_user_json(userid=userid, email=email, lname=lname, fname=fname) print "dict" print dicts return jsonify({"users": dicts})
def get_user_friend(): js = request.get_json(force=True) userid = js.get('userid') friendid = js.get('friendid') if userid and friendid: value = giftlydb.select_values(values="NAME, DOB, STATE", table="Friend", where=("USERID=" + userid + "AND FRIENDID=" + friendid)) return json.dumps(giftlydb.row_to_dict(value)) else: return jsonify({ "userid": userid, "friendid": friendid, "exists": "False", "response": 200 })
def login_user(): js = request.get_json(force=True) email = js.get('email') password = js.get('password') if giftlydb.row_exists("EMAIL", 'User', "EMAIL=" + formatting.stringify_sql(email), state='1'): hashed_password = giftlydb.select_values( "PASSWORD", "USER", "EMAIL=" + formatting.stringify_sql(email))[0]['PASSWORD'] else: print 'abort' return abort(400) login_auth = None if encryption.check_hashed_password(password, hashed_password): login_auth = True else: login_auth = False values = giftlydb.select_values( values="USERID, EMAIL, FNAME, LNAME, STATE", table="User", where="EMAIL=" + email) if values: value_dict = giftlydb.row_to_dict(values) userid = value_dict[0]['userid'] email = value_dict[0]['email'] fname = value_dict[0]['fname'] lname = value_dict[0]['lname'] return jsonify( formatting.format_user_json(userid=userid, email=email, fname=fname, lname=lname, auth=login_auth))
def login_user(): js = request.get_json(force=True) email = js.get('email') password = js.get('password') if giftlydb.row_exists("EMAIL", 'User', "EMAIL="+formatting.stringify_sql(email), state='1'): hashed_password = giftlydb.select_values("PASSWORD", "USER", "EMAIL=" + formatting.stringify_sql(email))[0]['PASSWORD'] else: print 'abort' return abort(400) login_auth = None if encryption.check_hashed_password(password, hashed_password): login_auth = True else: login_auth = False values = giftlydb.select_values(values="USERID, EMAIL, FNAME, LNAME, STATE", table="User", where="EMAIL="+email) if values: value_dict = giftlydb.row_to_dict(values) userid = value_dict[0]['userid'] email = value_dict[0]['email'] fname = value_dict[0]['fname'] lname = value_dict[0]['lname'] return jsonify(formatting.format_user_json(userid=userid, email=email, fname=fname, lname=lname, auth=login_auth))
def register_user_(): js = request.get_json(force=True) email = js.get('email') password = js.get('password') fname = js.get('fname') lname = js.get('lname') #Missing arguments if not email or not password or not fname or not lname: return abort(400) fname = formatting.stringify_sql(fname) lname = formatting.stringify_sql(lname) email = formatting.stringify_sql(email) if giftlydb.insert_user((giftlydb.generate_uuid(), email, fname, lname, formatting.stringify_sql(encryption.hash_password(password)), '1')): values = giftlydb.select_values(values="USERID, EMAIL, FNAME, LNAME", table="User", where="EMAIL="+email) value_dict = giftlydb.row_to_dict(values) userid = value_dict[0]['userid'] email = value_dict[0]['email'] lname = value_dict[0]['lname'] fname = value_dict[0]['fname'] return jsonify(formatting.format_user_json(userid=userid, email=email, lname=lname, fname=fname)) else: return abort(400)