diff --git a/app/__init__.py b/app/__init__.py index 7995fe2ba022f8fd76b2d3761dc5fb697b688394..6880ec6ce9eaa5d489ae73a987749d6494eadb85 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -12,6 +12,10 @@ from flask_bootstrap import Bootstrap import random import os import json +import sys + +sys.path.append(vars.rabbitmq_agents_loc) +import rc_util def create_app(config_name): app = Flask(__name__, static_folder='static') # initialization of the flask app @@ -22,11 +26,13 @@ def create_app(config_name): username_key = list(filter(lambda key: (request.headers.get(key) is not None), vars.username_key)) fullname_key = list(filter(lambda key: (request.headers.get(key) is not None), vars.fullname_key)) email_key = list(filter(lambda key: (request.headers.get(key) is not None), vars.email_key)) + eppa_key = list(filter(lambda key: (request.headers.get(key) is not None), vars.eppa_key)) user = { "username": (request.headers.get(username_key[0]) if len(username_key) > 0 else None), "fullname": (request.headers.get(fullname_key[0]) if len(fullname_key) > 0 else None), "email": (request.headers.get(email_key[0]) if len(email_key) > 0 else None), + "eppa": (request.headers.get(eppa_key[0]) if len(eppa_key) > 0 else None), } return user @@ -42,7 +48,22 @@ def create_app(config_name): session['return_url'] = request.args.get('redir', vars.default_referrer) - return render_template('auth/SignUp.html', room_id=session['uid'], +# if (not any(item in session['user'].get('eppa') for item in valid_eppa)): +# return render_template('errors/shibboleth.html') + + if rc_util.check_state(session['user'].get('username')) == "blocked": + return render_template('errors/blocked.html') + + elif rc_util.check_state(session['user'].get('username')) == "certification": + return render_template('errors/certify.html', room_id=session['uid'], + username=session['user'].get('username'), + fullname=session['user'].get('fullname'), email=session['user'].get('email'), + referrer=session['return_url'], cancel_url=vars.default_referrer, + welcome_msg=messages.welcome_message, + cancel_msg=messages.cancel_message, + error_msg=messages.error_message) + else: + return render_template('auth/SignUp.html', room_id=session['uid'], username=session['user'].get('username'), fullname=session['user'].get('fullname'), email=session['user'].get('email'), referrer=session['return_url'], cancel_url=vars.default_referrer, @@ -50,10 +71,13 @@ def create_app(config_name): cancel_msg=messages.cancel_message, error_msg=messages.error_message) - @app.route('/error_account') - def error_account_create(): - return render_template('errors/error.html', title='account creation failed') + @app.route('/blocked_account') + def account_block(): + return render_template('errors/blocked.html') + @app.route('/certify_account') + def error_certify(): + return render_template('errors/certify.html') # misc page error catching @app.errorhandler(403) diff --git a/app/static/scripts/function.js b/app/static/scripts/function.js index 77bd28ad114e8de33d54c031b80018c76b7f3580..486006b1e028e25f37ee330bd3602358d12b70c0 100644 --- a/app/static/scripts/function.js +++ b/app/static/scripts/function.js @@ -23,6 +23,14 @@ function request_account() { }) } +function certify_account() { + socket.emit('request certification', { + fullname: document.getElementById("fullname").value, + email: document.getElementById("email").value, + username: document.getElementById("username").value + }) +} + function renderDom(title, message, error_msg) { document.getElementById("form-wrapper").innerHTML = "

" + title + "


"; document.getElementById("form-wrapper").innerHTML += "

" + message + "


"; diff --git a/app/templates/errors/blocked.html b/app/templates/errors/blocked.html new file mode 100644 index 0000000000000000000000000000000000000000..964235ee1dfb6324c37f53ae2a21528d4efa7503 --- /dev/null +++ b/app/templates/errors/blocked.html @@ -0,0 +1,74 @@ + +User Blocked + + + + + + + + + + + + + + + + + + +
+ +
+ +
+
+ logo + +
+ +
+
+

Account blocked

+

{{ welcome_msg |safe }}

+
+
+
+ + + + + diff --git a/app/templates/errors/certify.html b/app/templates/errors/certify.html new file mode 100644 index 0000000000000000000000000000000000000000..abb4a4642c09f34632363043daa2d23c0c95123b --- /dev/null +++ b/app/templates/errors/certify.html @@ -0,0 +1,147 @@ + +User Certification + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+
+ logo + +
+ +
+
+

Self Certification Form

+

{{ welcome_msg |safe }}

+
+
+
+
+
+
+
+
+
+
+
+
+
+ + +
+
+
+
+
+
+ + + + + + + + + diff --git a/run.py b/run.py index f69a20825a47ab2d526807240273a5737a878ac5..d68af7680ea9fe04320aacde2022edf8cae3dae8 100644 --- a/run.py +++ b/run.py @@ -35,5 +35,16 @@ def request_account(json, methods=['GET', 'POST']): print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account creation: ", e) socketio.emit("Account creation failed", room) +@socketio.on('request certification') +def certify_account(json, methods=['GET', 'POST']): + print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tQueue request received: ' + str(json)) + room = str(session['uid']) + print("CERTIFY Room: {}".format(room)) + try: + tasks.celery_certify_account(json, session=room ) + except Exception as e: + print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account certification: ", e) + socketio.emit("Account certification failed", room) + if __name__ == '__main__': socketio.run(app, host='0.0.0.0') diff --git a/tasks.py b/tasks.py index 300a58cec84162213a749dbe825746299a59f3a9..3b00fce51e03b5f42b1d670cd251c312d3461758 100644 --- a/tasks.py +++ b/tasks.py @@ -35,6 +35,26 @@ def gen_f(room): rc_util.rc_rmq.delete_queue() return callback +def certify_gen_f(room): + def callback(channel, method, properties, body): + msg = json.loads(body) + username = msg['username'] + queuename = msg['username'] + + if msg['success']: + print(f'Account for {username} has been certified.') + send_msg('certified', room) + else: + print(f"There's some issue while certifying account for {username}") + errmsg = msg.get('errmsg', []) + for err in errmsg: + print(err) + socketio.emit('certify error', errmsg, room= room) + + rc_util.rc_rmq.stop_consume() + rc_util.rc_rmq.delete_queue(queuename) + return callback + def send_msg(event, room): socketio.emit(event, room=room) @@ -60,4 +80,20 @@ def celery_create_account(json, session): rc_util.add_account(username, queuename, email, fullname, reason, aup) print('sent account info') print('Waiting for completion...') - rc_util.consume(queuename, routing_key=f'complete.{queuename}', callback=gen_f(room)) + rc_util.consume(queuename, routing_key=f'complete.{queuename}', callback=gen_f(room)) + +@celery.task +def celery_certify_account(json, session): + room = session + username= json['username'] + email= json['email'] + fullname= json['fullname'] + queuename= rc_util.encode_name(username) + + print("CERTIFY : "+time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue') + send_msg('certifying account', room) + print(username) + rc_util.certify_account(username, queuename, 'ok', 'all') + print('sent account info') + print('Waiting for certification...') + rc_util.consume(queuename, routing_key=f'certified.{queuename}', callback=certify_gen_f(room))