def __init__(self, email): try: # Connect to the RDS database mydb = connect_to_db() mycursor = mydb.cursor() # called mysql stored procedure giving email as an argument mycursor.callproc('get_user_details_by_email', [ email, ]) results = mycursor.stored_results() except mysql.connector.Error as err: print("SOMETHING WENT WRONG:", err) for result in results: u = result.fetchall()[0] self.email = u[0] self.password = u[1] self.stations = json.loads(u[2]) self.emailvalidated = u[3] mycursor.close() mydb.close()
def check_email(email): try: # Connect to the RDS database mydb = connect_to_db() mycursor = mydb.cursor() # called mysql stored procedure giving email as an argument mycursor.callproc('check_if_email_exists', [ email, ]) results = mycursor.stored_results() except mysql.connector.Error as err: print("SOMETHING WENT WRONG:", err) for result in results: email_exists = result.fetchall()[0][0] mycursor.close() mydb.close() return email_exists
def delete_account(self): try: # Connect to the RDS database mydb = connect_to_db() mycursor = mydb.cursor() mycursor.callproc('delete_user', [ self.email, ]) mydb.commit() except mysql.connector.Error as err: print("SOMETHING WENT WRONG:", err) mycursor.close() mydb.close()
def add_user(email, password): try: # Connect to the RDS database mydb = connect_to_db() mycursor = mydb.cursor() # called mysql stored procedure giving email as an argument mycursor.callproc('add_user', ( email, password, )) mydb.commit() except mysql.connector.Error as err: print("SOMETHING WENT WRONG:", err) mycursor.close() mydb.close()
def update_feature(self, data, feature): try: # Connect to the RDS database mydb = connect_to_db() mycursor = mydb.cursor() # called mysql stored procedure giving email as an argument if feature == "email": mycursor.callproc('update_email', [self.email, data]) elif feature == "password": self.password = data mycursor.callproc('update_password', [self.email, data]) elif feature == "emailvalidated": self.emailvalidated = data mycursor.callproc('update_emailvalidated', [self.email, data]) elif feature == "add_station": self.stations.append(data) mycursor.callproc( 'update_stations', [self.email, json.dumps(self.stations)]) elif feature == "remove_station": if data in self.stations: self.stations.remove(data) mycursor.callproc( 'update_stations', [self.email, json.dumps(self.stations)]) mydb.commit() except mysql.connector.Error as err: print("SOMETHING WENT WRONG:", err) mycursor.close() mydb.close()