Newer
Older
Mitchell Moore
committed
import signal
from flask import session
from flask_socketio import SocketIO, join_room
from app import create_app
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
app.config['SECRET_KEY'] = 'vnkdjnfjknfl1232#'
Mitchell Moore
committed
global username_global
def create_account(username, fullname, reason):
Mitchell Moore
committed
# Todo: Ravi's and Louis's code goes here
print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue')
socketio.emit("creating account", room=room_global)
Mitchell Moore
committed
signal.signal(signal.SIGALRM, account_agent)
signal.alarm(5)
Mitchell Moore
committed
def account_agent(*args):
# Todo: Code to create a consumer based on the username goes here
# Todo: Goal is to have it listening for confirmation.
Mitchell Moore
committed
global username_global
print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tAccount successfully created for ' + username_global)
socketio.emit("account ready", room=room_global)
Mitchell Moore
committed
@socketio.on('user connected')
def user_connected(json, methods=['GET', 'POST']):
global username_global
global room_global
username_global = json["user"]
room_global = str(session['uid'])
print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username_global + ' connected.')
print('\t\t\t|-----Room ID: ' + room_global)
Mitchell Moore
committed
def request_account(json, methods=['GET', 'POST']):
print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tQueue request received: ' + str(json))
# create_account(json['username'], json['fullname'], json['reason'])
tasks.celery_create_account(json['username'], json['fullname'], json['reason'], room_global)
except Exception as e:
print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account creation: ", e)
socketio.emit("Account creation failed", room=room_global)
socketio.run(app, host='0.0.0.0')