Commit cf8328e0 authored by Krish Moodbidri's avatar Krish Moodbidri
Browse files

Merge branch 'test-merger' into 'master'

Feat certify account

See merge request rc/self-reg-form!21
parents 5f08c96d f544d8b1
......@@ -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)
......
......@@ -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 = "<h3>" + title + "</h3><br>";
document.getElementById("form-wrapper").innerHTML += "<p>" + message + "</p><br>";
......
<html class="gr__rc_uab_edu">
<title>User Blocked </title>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.3/socket.io.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
<script src="{{ url_for('static', filename='scripts/function.js') }}"></script>
<link rel="shortcut icon" type="image/x-icon" href="/public/favicon.ico">
<link rel="stylesheet" media="all" href="{{ url_for('static', filename='style/application.css') }}">
<link rel="stylesheet" media="all" href="{{ url_for('static', filename='style/app2.css') }}">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.navbar-inverse { background-color: rgb(0,99,65); }
button{ margin: 13px;
.important { color: #336699; }}
</style>
</head>
<body data-gr-c-s-loaded="true">
<header>
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-9" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
<a class="navbar-brand" href="/"> UAB Research Computing</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-9">
<div class="navbar-right">
<ul class="nav navbar-nav">
<li>
<a target="_blank" href="https://docs.uabgrid.uab.edu/wiki/Cheaha_GettingStarted">
<i class="fas fa-info-circle fa-fw"></i> Online Documentation
</a>
</li>
</ul>
</div>
</div>
</div>
</nav>
</header>
<div class="container content" role="main" style="width: 100%">
<div class="col-md-2 col-sm-2 my-col">
<img alt="logo" height="auto" width="80%" src="{{ url_for('static', filename='img/logo_svg.svg') }}">
<a href="https://tinyurl.com/cheahaAL" target="_blank"></a>
</div>
<div class="col-md-10 col-sm-10 my-col">
<div id="form-wrapper">
<h2> Account blocked </h2>
<p style="font-size:110%;"> {{ welcome_msg |safe }}</p>
</div>
</div>
</div>
<footer>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6">
<a href="https://osc.github.io/Open-OnDemand/">
<img class="footer-logo" alt="Powered by Open OnDemand" height="40" style="margin-bottom: 20px" src="{{ url_for('static', filename='img/OpenOnDemand_powered_by_RGB-cb3aad5ff5350c7994f250fb334ddcc72e343233ce99eb71fda93beddd76a847.svg') }}">
</a>
</div>
</div>
</div>
</footer>
</body>
</html>
<html class="gr__rc_uab_edu">
<title>User Certification </title>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.7.3/socket.io.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
<script src="{{ url_for('static', filename='scripts/function.js') }}"></script>
<script>
console.info('Room ID: {{ room_id }}');
var socket = io.connect();
socket.on( 'connect', function() {
autofill_form("{{ username }}", "{{ fullname }}", "{{ email }}");
socket.emit( 'join_room', {
referrer: '{{ referrer }}'
});
socket.on( 'certifying account', function( msg ) {
displayloading2();
});
socket.on( 'certified', function( msg ) {
$('#myModal2').modal('hide');
window.location.replace('{{ referrer }}');
});
socket.on( 'certify error', function( msg ) {
console.log(msg);
$('#myModal2').modal('hide');
renderDom("Account Certification Error", "{{ error_msg }}", msg);
});
});
</script>
<link rel="shortcut icon" type="image/x-icon" href="/public/favicon.ico">
<link rel="stylesheet" media="all" href="{{ url_for('static', filename='style/application.css') }}">
<link rel="stylesheet" media="all" href="{{ url_for('static', filename='style/app2.css') }}">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.navbar-inverse { background-color: rgb(0,99,65); }
button{ margin: 13px;
.important { color: #336699; }}
</style>
</head>
<body data-gr-c-s-loaded="true">
<header>
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-9" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
<a class="navbar-brand" href="/"> UAB Research Computing</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-9">
<div class="navbar-right">
<ul class="nav navbar-nav">
<li>
<a target="_blank" href="https://docs.uabgrid.uab.edu/wiki/Cheaha_GettingStarted">
<i class="fas fa-info-circle fa-fw"></i> Online Documentation
</a>
</li>
</ul>
</div>
</div>
</div>
</nav>
</header>
<div class="container content" role="main" style="width: 100%">
<div class="col-md-2 col-sm-2 my-col">
<img alt="logo" height="auto" width="80%" src="{{ url_for('static', filename='img/logo_svg.svg') }}">
<a href="https://tinyurl.com/cheahaAL" target="_blank"></a>
</div>
<div class="col-md-10 col-sm-10 my-col">
<div id="form-wrapper">
<h2> Self Certification Form </h2>
<p style="font-size:110%;"> {{ welcome_msg |safe }}</p>
<div id="user-input">
<form id="signup" data-toggle="validator" role="form" action="." method="post" onsubmit="">
<div class="col-md-7 col-sm-7 my-col">
<label for="username" class="control-label">Blazer Id:</label>&#9;<input id="username" class="form-control" placeholder="Enter Username" required><br>
</div>
<div class="col-md-7 col-sm-7 my-col">
<label for="fullname" class="control-label">Full Name:</label>&#9;<input id="fullname" class="form-control" placeholder="Enter Full Name" required><br>
</div>
<div class="col-md-7 col-sm-7 my-col">
<label for="email" class="control-label">Email:</label>&#9;<input id="email" class="form-control" placeholder="Enter Email" required><br>
</div>
<br>
<div class="col-md-7 col-sm-7 my-col">
<button class="btn btn-danger btn-md" id="cancel" name="cancel" type="button" onClick="renderDom('Account Creation Cancelled','{{ cancel_msg |safe }}', null)">Cancel</button>
<button class="btn btn-primary btn-md" id="submit" name="submit" type="button" value="Submit" onclick="displayloading1();certify_account()"> Certify Account</button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal fade" id="overlayModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Account Certification Request Received!</h4>
</div>
<div class="modal-body">
<span>Communicating this information to the server</span>
<img src="{{ url_for('static', filename='img/loading.gif') }}" width="40px">
</div>
</div>
</div>
</div>
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Account Certification Received!</h4>
</div>
<div class="modal-body">
<span>Sit tight while we certify your account.</span>
<img src="{{ url_for('static', filename='img/loading.gif') }}" width="40px">
</div>
</div>
</div>
</div>
<footer>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6">
<a href="https://osc.github.io/Open-OnDemand/">
<img class="footer-logo" alt="Powered by Open OnDemand" height="40" style="margin-bottom: 20px" src="{{ url_for('static', filename='img/OpenOnDemand_powered_by_RGB-cb3aad5ff5350c7994f250fb334ddcc72e343233ce99eb71fda93beddd76a847.svg') }}">
</a>
</div>
</div>
</div>
</footer>
</body>
</html>
......@@ -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')
......@@ -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))
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