예제 #1
0
 def __init__(self, id):
     table_entry = db_ex(f"SELECT * FROM 'request' WHERE 'request'.request_id=\"{id}\";").fetchall()
     if len(table_entry) <= 0:
         raise ValueError("You tried to create a request object with an id that is not in the request table")
     else:
         self.request_id = id
         self.sender_id = table_entry[0][1]
         self.reciever_id = table_entry[0][2]
         self.status = table_entry[0][3]
         self.message = table_entry[0][4]
예제 #2
0
 def authenticate_user(username, password):
     fetch = db_ex(
         f"SELECT password FROM 'user' WHERE 'user'.username=\"{username}\";"
     ).fetchall()
     if len(fetch) == 0:
         flash("Username not found")
         return False  #user with that username does not exist
     if fetch[0][0] != password:
         flash("Incorrect password")
         return False
     else:
         print(fetch)
         return True
예제 #3
0
 def new_request(sender_id, reciever_id, status, message):
     '''Function called when user sends a request to another user'''
     # if status == "block":
     db_ex(f"""DELETE FROM 'request' WHERE 'request'.sender_id={sender_id} AND 'request'.reciever_id={reciever_id};""")
     db_ex(f"""DELETE FROM 'request' WHERE 'request'.sender_id={reciever_id} AND 'request'.reciever_id={sender_id};""")
     # if len(db_ex(f"SELECT * FROM 'request' WHERE 'request'.sender_id=\"{sender_id}\" AND 'request'.reciever_id=\"{reciever_id}\";").fetchall()) > 0:
         # flash("a request has already been sent to this person")
         # return False
     # else:
     db_ex(f"""INSERT INTO 'request' (sender_id, reciever_id, status, message)
           VALUES ({sender_id}, {reciever_id}, \"{status}\", \"{message}\");""")
     return True
예제 #4
0
 def __init__(self, id):
     table_entry = db_ex(
         f"SELECT * FROM 'user' WHERE 'user'.id=\"{id}\";").fetchall()
     if len(table_entry) <= 0:
         raise ValueError(
             "You tried to create a user object with an id that is not in the user table"
         )
     else:
         self.id = id
         self.username = table_entry[0][1]
         self.password = table_entry[0][2]
         self.name = table_entry[0][3]
         self.gender = table_entry[0][4]
         self.preference = table_entry[0][5]
         self.dob = table_entry[0][6]
         self.email = table_entry[0][7]
         self.phone_number = table_entry[0][8]
         self.bio = table_entry[0][9]
         self.location = table_entry[0][10]
예제 #5
0
 def update_location(self):
     loc_info = api_request.json2dict(
         api_request.ip_location(api_request.user_ip()))
     db_ex(f"""UPDATE 'user'
               SET location = \"{loc_info['lat']},{loc_info['lon']}\"
               WHERE 'user'.id = \"{self.id}\";""")
예제 #6
0
 def query_by_id(userID, query):
     fetch = db_ex(f"SELECT {query} FROM 'user' WHERE 'user'.id = {userID};"
                   ).fetchall()
     if (len(fetch) == 0):
         flash("Username not found, or error with query")
     return fetch[0][0]
예제 #7
0
 def get_by_reciever(reciever_id):
     fetch = db_ex(f"SELECT reciever_id FROM 'request' WHERE 'request'.reciever_id=\"{reciever_id}\";").fetchall()
     return fetch[0]
예제 #8
0
 def get_by_sender(sender_id):
     fetch = db_ex(f"SELECT request_id FROM 'request' WHERE 'request'.sender_id=\"{sender_id}\";").fetchall()
     return fetch[0]