Commit 8fd86e4a authored by Mitchell Moore's avatar Mitchell Moore Committed by Krish Moodbidri
Browse files

Added room functionality in run.py and removed unused function in run.py

- Remove unused functions
- (unstable) add room functionality for testing
parent 45612054
...@@ -16,39 +16,13 @@ app.config['SECRET_KEY'] = 'vnkdjnfjknfl1232#' ...@@ -16,39 +16,13 @@ app.config['SECRET_KEY'] = 'vnkdjnfjknfl1232#'
socketio = SocketIO(app) socketio = SocketIO(app)
global username_global global username_global
global room_global
def messageReceived(methods=['GET', 'POST']):
print('message was received!!!')
def check_dir(user, interval):
# Todo: Make this mothod in a consumer
"""
:param user: (string) username to check for in DB.
:param interval: (int) Frequency to check in seconds.
:return: (boolean) if account has been registered.
"""
seconds = 0
while seconds < 600:
querystring = "_" + user + ".done"
for filename in os.listdir("flat_db/"):
if filename.endswith(querystring):
return True
time.sleep(interval)
seconds = seconds + interval
return False
def create_account(username, fullname, reason): def create_account(username, fullname, reason):
# Todo: Ravi's and Louis's code goes here # Todo: Ravi's and Louis's code goes here
print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue') print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue')
global username_global socketio.emit("creating account", room=room_global)
username_global = username
socketio.emit("creating account")
signal.signal(signal.SIGALRM, account_agent) signal.signal(signal.SIGALRM, account_agent)
signal.alarm(5) signal.alarm(5)
...@@ -57,22 +31,23 @@ def account_agent(*args): ...@@ -57,22 +31,23 @@ def account_agent(*args):
# Todo: Code to create a consumer based on the username goes here # Todo: Code to create a consumer based on the username goes here
# Todo: Goal is to have it listening for confirmation. # Todo: Goal is to have it listening for confirmation.
global username_global global username_global
username = username_global print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tAccount successfully created for ' + username_global)
print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tAccount successfully created for ' + username) socketio.emit("account ready", room=room_global)
socketio.emit("account ready")
return True return True
@socketio.on('user connected') @socketio.on('user connected')
def user_connected(json, methods=['GET', 'POST']): def user_connected(json, methods=['GET', 'POST']):
username = json["user"] global username_global
global room_global
room = str(session['uid']) username_global = json["user"]
room_global = str(session['uid'])
join_room(room) join_room(room_global)
print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' connected.') print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username_global + ' connected.')
print('\t\t\t|-----Room ID: ' + room) print('\t\t\t|-----Room ID: ' + room_global)
@socketio.on('request account') @socketio.on('request account')
...@@ -84,8 +59,9 @@ def request_account(json, methods=['GET', 'POST']): ...@@ -84,8 +59,9 @@ def request_account(json, methods=['GET', 'POST']):
except Exception as e: except Exception as e:
print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account creation: ", e) print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account creation: ", e)
socketio.emit("Account creation failed") socketio.emit("Account creation failed", room=room_global)
if __name__ == '__main__': if __name__ == '__main__':
app.run(Debug=True) # app.run()
socketio.run(app, host='0.0.0.0')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment