Commit b23cf956 authored by Mitchell Moore's avatar Mitchell Moore
Browse files

Removed watchdog function, added fullname & reason for request account, fixes...

Removed watchdog function, added fullname & reason for request account, fixes template issues and updated requirements.txt

- Remove watchdog elements
- Add reason field to form
- Added mock sucess template and added to form
- Fix typo
- Make template functional
- Fix templates
- Delete request_recieved.html
- Add fullname to file
- Change success route name to request_sent
- Update requirements/imports for socket.io
- Edit script paths for local testing
- Change dir and make default user
- Introduce funtions (needs alteration)
- Update all requirements
parent 47b97e0a
# app/__init__.py
# app/__init__.py
# local imports
from __future__ import print_function
......@@ -9,76 +9,33 @@ import subprocess
import time
# third-party imports
from flask import Flask, redirect, url_for, request, render_template, flash
from flask import Flask, redirect, url_for, request, render_template, flash, session
from flask_wtf import FlaskForm
from flask_bootstrap import Bootstrap
from wtforms import StringField, SubmitField, validators
from wtforms import StringField, SubmitField, TextAreaField, validators
from flask_socketio import SocketIO
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from watchdog.utils import dirsnapshot
global snap_before
global snap_after
global snap_diff
global observing
# global declarations
global time_stamp
observing = False
class MyHandler(FileSystemEventHandler): # Watchdog handler class to take action when observation requested
def on_modified(self, event):
global snap_before
global snap_after
global snap_diff
global observing
global time_stamp
# print(event.src_path + " modified.")
snap_after = dirsnapshot.DirectorySnapshot("/home/reggie/flat_db", True) # take post flat_db creation snapshot of the directory
snap_diff = dirsnapshot.DirectorySnapshotDiff(snap_before, snap_after) # object to compare the initial snapshot with the final snapshot
try:
<<<<<<< Updated upstream
if ("/home/reggie/flat_db/" + time_stamp + ".done") in snap_diff.files_moved[0]: # check for timestamped string with .done extention in flat_db
=======
if len(snap_diff.files_moved) > 0 and ("/home/reggie/flat_db/" + time_stamp + ".done") in snap_diff.files_moved[0]:
>>>>>>> Stashed changes
observing = False
# print("YES!")
except Exception as e:
print(e)
return render_template('errors/500.html', title='Server Error'), 500
# print("Created: ", snap_diff.files_created)
# print("Deleted: ", snap_diff.files_deleted)
# print("Modified: ", snap_diff.files_modified)
# print("Moved: ", snap_diff.files_moved)
def on_created(self, event):
print(event.src_path + " created.")
def create_app(config_name):
app = Flask(__name__) # initialization of the flask app
Bootstrap(app) # allowing app to use bootstrap
socketio = SocketIO(app)
global return_url
return_url = ''
class MainForm(FlaskForm): # class for the form itself
fullname = StringField('Full Name: ', [validators.DataRequired(), ])
fullname = StringField('Full Name: ', [validators.DataRequired(), validators.length(max=50)])
reason = TextAreaField('Reason for Requesting Account: ', [validators.DataRequired(), validators.length(max=150)])
submit = SubmitField('Submit')
@app.route('/', methods=['GET', 'POST']) # initial route to display the reg page
def index():
global return_url
username = request.remote_user
username = "mmoo97"
if "redir" in request.args and return_url == "": # check for redir arg in url
return_url = request.args.get("redir") or "/pun/sys/dashboard"
......@@ -87,19 +44,23 @@ def create_app(config_name):
fullname = False
form = MainForm() # initialize form object
if form.is_submitted():
fullname = form.fullname.data
session["fullname"] = form.fullname.data
session['reason'] = form.reason.data
form.fullname.data = '' # reset form data upon capture
form.fullname.data = '' # reset form data upon capture
return redirect(url_for('success', username=str(username), fullname=fullname))
return redirect(url_for('request_sent', username=username))
return render_template('auth/SignUp.html', form=form, user=username)
@app.route('/success/<username>/<fullname>')
def success(username, fullname):
@app.route('/request_sent/<username>')
def request_sent(username):
fullname = session.get('fullname', None)
reason = session.get('reason', None)
global return_url
global snap_before
global observing
global time_stamp
print(username, fullname, return_url, file=sys.stdout)
......@@ -112,32 +73,20 @@ def create_app(config_name):
# of the file beieng blazerID the user submitted from the flask form (fullname)
time_stamp = time.strftime("%m-%d-%Y_%H:%M:%S")
directory = "/home/reggie/flat_db/"
complete_file_name = os.path.join(directory, time_stamp + "_" + request.remote_user + ".txt")
directory = "flat_db/"
complete_file_name = os.path.join(directory, time_stamp + "_" + username + ".txt")
if not os.path.exists(directory):
os.makedirs(directory)
event_handler = MyHandler() # initialize handler
observer = Observer() # initialize obsever to relay to handler
observer.schedule(event_handler, path='/home/reggie/flat_db', recursive=True)
observer.start()
observing = True
file = open(complete_file_name, "w") # create time stamped file to be queued
file.write("Hey")
# take an initial state snapshot of the db after file queued
snap_before = dirsnapshot.DirectorySnapshot("/home/reggie/flat_db", True)
file.write(fullname + "\n")
file.write(reason)
while observing:
# TODO: Update page ui element dynamically
time.sleep(5)
observer.stop()
file.close()
return render_template("errors/registration_failed.html") # Todo: replace template with redirect
return "Hello"
# return render_template("auth/request_received.html") # Todo: replace template with redirect
# return redirect(return_url, 302)
except Exception as e:
......@@ -147,6 +96,27 @@ def create_app(config_name):
# misc page error catching
def messageReceived(methods=['GET', 'POST']):
print('message was received!!!')
@socketio.on('user connect')
def handle_my_custom_event(json, methods=['GET', 'POST']):
print('received my event: ' + str(json))
@socketio.on('my event')
def handle_my_custom_event(json, methods=['GET', 'POST']):
print('received my event: ' + str(json))
socketio.emit('my response', json, callback=messageReceived)
# time_stamp = time.strftime("%m-%d-%Y_%H:%M:%S")
# complete_file_name = os.path.join(directory, time_stamp + ".txt")
# file = open(complete_file_name, "w")
# file.close()
# time.sleep(5)
#
# pre, ext = os.path.splitext(complete_file_name)
# os.rename(complete_file_name, pre + ".done")
socketio.emit('create response', json, callback=messageReceived)
@app.errorhandler(403)
def forbidden(error):
return render_template('errors/403.html', title='Forbidden'), 403
......
......@@ -10,10 +10,53 @@ function displayloading() {
" This can take between 5-10 min.\n" +
" </p>\n" +
" </ol>\n" +
" <img src=\"/register/static/img/loading.gif\" style=\"width: 35px; height: auto\"> Pending...\n" +
" <img src=\"/static/img/loading.gif\" style=\"width: 35px; height: auto\"> Pending...\n" +
" </div></div>\n" +
"\n" +
" <div class=\"joyride-modal-bg\" style=\"display: block;\"></div>"
}
function socketIO() {
var socket = io.connect('http://' + document.domain + ':' + location.port);
}
\ No newline at end of file
socket.on( 'connect', function() {
socket.emit( 'user connect', {
data: 'User Connected'
} )
document.getElementById("testo").innerHTML = "yo"
var form = $( 'form' ).on( 'submit', function( e ) {
e.preventDefault()
let user_name = $( 'input.username' ).val()
let user_input = $( 'input.message' ).val()
socket.emit( 'my event', {
user_name : user_name,
message : user_input
} )
$( 'input.message' ).val( '' ).focus()
} )
} )
socket.on( 'my response', function( msg ) {
console.log( msg )
if( typeof msg.user_name !== 'undefined' ) {
$( 'h3' ).remove()
$( 'div.message_holder' ).append( '<div><b style="color: #002">'+msg.user_name+'</b> creating</div>' )
}
})
socket.on( 'create response', function( msg ) {
console.log( msg )
if( typeof msg.user_name !== 'undefined' ) {
$( 'h3' ).remove()
$( 'div.message_holder' ).append( '<div><b style="color: #002">'+msg.user_name+'</b> created. WELCOME</div>' )
}
})
</script>
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -5,12 +5,14 @@
{{ super() }}
<script src="{{ url_for('static', filename='scripts/function.js') }}"></script>
<script src="{{ url_for('static', filename='scripts/application.js') }}"></script>
<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>
<style type="text/css">
.important { color: #336699; }
</style>
<link rel="shortcut icon" type="image/x-icon" href="/public/favicon.ico">
<link rel="stylesheet" media="all" href="/register/static/style/application.css">
<link rel="stylesheet" media="all" href="/register/static/style/app2.css">
<link rel="stylesheet" media="all" href="/static/style/application.css">
<link rel="stylesheet" media="all" href="/static/style/app2.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
......@@ -30,7 +32,7 @@
<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="/register">Research Computing</a>
<a class="navbar-brand" href="/">Research Computing</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-9">
<ul class="nav navbar-nav">
......@@ -52,7 +54,7 @@
<div class="container content" role="main" style="width: 625px">
<div style="position:relative;">
<img alt="logo" height="100" style="margin-bottom: 20px" src="/register/static/img/cheaha-logo-a605de0aecd3006b82a5ee30a6d0cb8cd9bf8b7e836296cc293eac746a4c2b11.png">
<img alt="logo" height="100" style="margin-bottom: 20px" src="/static/img/cheaha-logo-a605de0aecd3006b82a5ee30a6d0cb8cd9bf8b7e836296cc293eac746a4c2b11.png">
<a href="https://tinyurl.com/cheahaAL" target="_blank">
<div style="float:left;position:absolute;display:block;left:310px;top:-6px;padding:10px 20px;"> </div>
</a>
......@@ -60,10 +62,12 @@
<h2>Hello, {{ user }}!</h2>
<form action="." method="post" onsubmit="displayloading()">
<form action="." method="post" onsubmit="displayloading(); socketIO();">
<div class="signUpContainer">
<label><b>{{ form.fullname.label }}<br></b></label>
{{ form.fullname(class_="form-control", placeholder="Enter Full Name") }}
<label><b>{{ form.reason.label }}<br></b></label>
{{ form.reason(class_="form-control", placeholder="Enter Reason for Account Request") }}
{{ form.submit(class_="btn btn-primary btn-block" ) }}
{% with messages = get_flashed_messages() %}
......@@ -79,9 +83,12 @@
</div>
</form>
</div>
<div id="notification_window" >
<div id="notification_window" >
</div>
<div id ="testo"></div>
{% endblock %}
</body>
{% block footer %}
......@@ -89,7 +96,7 @@
<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="/register/static/img/OpenOnDemand_powered_by_RGB-cb3aad5ff5350c7994f250fb334ddcc72e343233ce99eb71fda93beddd76a847.svg">
<img class="footer-logo" alt="Powered by Open OnDemand" height="40" style="margin-bottom: 20px" src="/static/img/OpenOnDemand_powered_by_RGB-cb3aad5ff5350c7994f250fb334ddcc72e343233ce99eb71fda93beddd76a847.svg">
</a>
</div>
</div>
......
......@@ -2,7 +2,7 @@
<html>
<head>
{% block head %}
<link rel="stylesheet" href="/register/static/style/application.css">
<link rel="stylesheet" href="/static/style/application.css">
<title>{% block title %}{% endblock %}</title>
{% endblock %}
</head>
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Request Received!</title>
</head>
<body>
<h2>Thank You!</h2>
<p>
You will be emailed as soon as your request has been fulfilled.
</p>
</body>
</html>
\ No newline at end of file
alembic==1.3.1
argh==0.26.2
blinker==1.4
certifi==2019.9.11
chardet==3.0.4
Click==7.0
dominate==2.3.5
Flask==1.0.2
dnspython==1.16.0
dominate==2.4.0
enum34==1.1.6
eventlet==0.25.1
Flask==1.1.1
Flask-Bootstrap==3.3.7.1
Flask-Dance==3.0.0
Flask-DebugToolbar==0.10.1
Flask-Login==0.4.1
Flask-Migrate==2.5.2
Flask-OAuth==0.12
Flask-OAuthlib==0.9.5
Flask-SocketIO==4.2.1
Flask-SQLAlchemy==2.4.1
Flask-Testing==0.7.1
Flask-WTF==0.14.2
greenlet==0.4.15
gunicorn==19.9.0
httplib2==0.14.0
idna==2.8
itsdangerous==1.1.0
Jinja2==2.10.1
Mako==1.0.7
Jinja2==2.10.3
lazy==1.4
Mako==1.1.0
MarkupSafe==1.1.1
monotonic==1.5
oauth2==1.9.0.post1
oauthlib==3.1.0
pathtools==0.1.2
pbr==5.1.3
python-dateutil==1.5
pbr==5.4.3
python-dateutil==2.8.1
python-editor==1.0.4
pytz==2013.7
python-engineio==3.10.0
python-socketio==4.3.1
pytz==2019.3
PyYAML==5.1.2
six==1.12.0
stevedore==1.30.1
virtualenv==16.4.3
virtualenv-clone==0.5.1
requests==2.22.0
requests-oauthlib==1.3.0
six==1.13.0
SQLAlchemy==1.3.11
SQLAlchemy-Utils==0.35.0
stevedore==1.31.0
urllib3==1.25.7
URLObject==2.4.3
virtualenv==16.7.7
virtualenv-clone==0.5.3
virtualenvwrapper==4.8.4
visitor==0.1.3
watchdog==0.9.0
Werkzeug==0.14.1
Werkzeug==0.16.0
wincertstore==0.2
WTForms==2.2.1
......@@ -3,11 +3,14 @@
import os
from app import create_app
from flask_socketio import SocketIO
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
app.secret_key = 'randomString'
socketio = SocketIO(app)
if __name__ == '__main__':
app.run()
# app.run()
socketio.run(app)
Markdown is supported
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