Commit 16a7dcc0 authored by Mitchell Moore's avatar Mitchell Moore
Browse files

Added test scripts to check redir and test outputs. Added overlay on account...

Added test scripts to check redir and test outputs. Added overlay on account request submiission. Basic CSS changes.

- Added testing script to utilize 'testing' config.
- (fix) fix src file reference
- Semantic fix for route order
- Semantic fix for variable name/position.
- (fix) indexing fix for redir args and test output.
- (fix) issue with icons not showing
- (fix) variable reference of fullname to success page.
- Clean up readme typos and make it more concise.
- Feat check account existence
- Added base.html to inherit form values from Signup.html
- Clean up code to function properly
- add 'validators' dependency
- fix fullname reference in submit statement
- Fix default title error
- fix routing logic in index
- remove dev comments
- Fix falure logic routing and edit error message
- Apply css formatting to jinja elements and fix form size issues
- Reintroduce form label/instruction
- Produce overlay window with text from jobcomposer tutorial
- add temporary functionality to call window for testing
- replace next and escape button with loading.gif
- Edited text formating/content of notification window
- Refactor gif to center
parent d6ff973d
......@@ -9,3 +9,4 @@ dist/
build/
*.egg-info/
**.idea/
**/.DS_Store
......@@ -3,23 +3,19 @@
To clone this repo use the command:
```
git clone https://gitlab.rc.uab.edu/mmoo97/flask_user_reg.git
$ git clone https://gitlab.rc.uab.edu/mmoo97/flask_user_reg.git
```
## Prerequisites
- Ensure `pip` is installed (see: https://packaging.python.org/guides/installing-using-pip-and-virtualenv/ ).
- Ensure you have created a virtual environment called `venv` setup within the cloned project.
- Install Flask and other dependencies using the following:
- Ensure you have created a [virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments)
called `venv` setup within the cloned project.
- Note, this project requires a virtual environment running python2 (2.7)
- Ensure Flask and other dependencies are installed using the following commands:
```
pip intall -p requirements.txt
```
- Note, to install flask in your own `$HOME` use `pip install --user Flask`.
## Starting the virtual machine for Flask
- Change to the `flask_user_reg` directory.
- then start virtual machine:
```
source venv/bin/activate
$ cd ~/your/repo/path/flask_user_reg
$ source venv/bin/activate
$ pip install -r requirements.txt
```
- Note, to install flask in your own `$HOME` use `pip install --user Flask`.
......@@ -6,11 +6,13 @@ from __future__ import print_function
import os
import sys
import subprocess
import time
# third-party imports
from flask import Flask, redirect, url_for, request
from flask import render_template
from flask import Flask, redirect, url_for, request, render_template, flash
from flask_wtf import FlaskForm
from flask_bootstrap import Bootstrap
from wtforms import StringField, SubmitField, validators
def create_app(config_name):
......@@ -20,50 +22,52 @@ def create_app(config_name):
global return_url
return_url = ''
global loading
loading = False
@app.route('/success/<name>/<username>')
def success(username, name):
global return_url
print(username, name, return_url, file=sys.stdout)
# Deliver arguments to script.
tempString = 'echo ssh ohpc "sudo /opt/ohpc_user_create/user_create ' + username + ' \'' + name + '\'"'
print(tempString, file=sys.stdout)
output = subprocess.check_output([tempString], shell=True)
print(output.split('\n'), file=sys.stdout)
return redirect(return_url, 302)
class MainForm(FlaskForm):
fullname = StringField('Full Name: ', [validators.DataRequired(), ])
submit = SubmitField('Submit')
@app.route('/', methods=['GET', 'POST'])
def index():
global return_url
global loading
user = request.remote_user
if request.method == 'GET':
if "redir" in request.args:
return_url = request.args.get("redir") or "/pun/sys/dashboard"
global return_url
if "redir" in request.args:
return_url = request.args.get("redir") or "/pun/sys/dashboard"
username = False
form = MainForm()
if form.is_submitted():
username = form.fullname.data
form.fullname.data = ''
return render_template("auth/SignUp.html", user=user)
return redirect(url_for('success', username=str(user), fullname=username))
if request.method == 'POST':
return render_template('auth/SignUp.html', form=form, user=user, loading=loading)
name = request.form['name']
@app.route('/success/<username>/<fullname>')
def success(username, fullname):
if name != "":
global return_url
print(username, fullname, return_url, file=sys.stdout)
# Deliver arguments to script.
tempString = 'ssh ohpc "sudo /opt/ohpc_user_create/user_create ' + username + " " + fullname + '"'
print(tempString, file=sys.stdout)
return redirect(url_for('success', username=str(user), name=name))
try:
else:
return render_template("auth/SignUp.html", user=user)
subprocess.check_output([tempString], shell=True)
return redirect(return_url, 302)
with app.test_request_context(
'/', environ_base={'REMOTE_USER': 'short'}):
pass
except:
flash("Registration Failed. Please try again.")
global loading
loading = True
return redirect(url_for('index'))
@app.errorhandler(403)
def forbidden(error):
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
<html class="gr__rc_uab_edu"><head>
<title>User Register</title>
<link rel="shortcut icon" type="image/x-icon" href="/public/favicon.ico">
{% extends "auth/base.html" %}
<html class="gr__rc_uab_edu">
{% block title %} User Registration {% endblock %}
{% block head %}
{{ super() }}
<script src="/register/static/scripts/application.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">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
......@@ -10,79 +18,85 @@
}
</style>
{% endblock %}
</head>
<body data-gr-c-s-loaded="true">
<header>
<nav class="navbar navbar-inverse navbar-static-top">
<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>
</div><div class="container-fluid">
<div class="navbar-collapse collapse" id="bs-example-navbar-collapse-9" style="">
<a class="navbar-brand" href="/pun/sys/dashboard/">UAB Research Computing </a><div class="navbar-right">
<ul class="nav navbar-nav" style="float: right;">
<li class="dropdown" title="Help">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="hidden-sm hidden-sm-nav"> Help</span>
</a>
<ul class="dropdown-menu">
<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>
<li>
<a target="_self" href="/nginx/stop?redir=/pun/sys/dashboard/">
<i class="fas fa-sync fa-fw"></i> Restart Web Server
</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav" style="
float: right;
">
<li>
</li></ul>
</div><ul class="nav navbar-nav">
<ul class="dropdown-menu">
</ul>
</ul></div>
<body data-gr-c-s-loaded="true">
<header>
{% block body %}
<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="/register">Research Computing</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-9">
<ul class="nav navbar-nav">
</ul>
<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>
<li>
</li></ul>
</div>
</div>
</div>
</nav>
</header>
<div class="container content" role="main" style="width: 625px">
<div class="container content" role="main" style="
width: 800;
">
<div style="position:relative;">
<img alt="logo" height="100" style="margin-bottom: 20px" src="/register/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>
</div>
<div class="col-md-12">
<img class="header-logo" height="100" style="margin-bottom: 20px" src="/register/static/img/cheaha-logo-a605de0aecd3006b82a5ee30a6d0cb8cd9bf8b7e836296cc293eac746a4c2b11.png">
<h2>Hello, {{ user }}!</h2>
<form action="." method="post">
<div class="signUpContainer">
<label for="name"><b>Full Name:<br></b></label>
<input class="form-control" type="text" placeholder="Enter Full Name" name="name">
<input class="btn btn-primary btn-block" type="submit" value="submit" onclick="return empty()">
<label><b>{{ form.fullname.label }}<br></b></label>
{{ form.fullname(class_="form-control", placeholder="Enter Full Name") }}
{{ form.submit(class_="btn btn-primary btn-block" ) }}
{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
<div>
<strong style="color: #be051b; text-align: center;">{{ message }}</strong>
</div>
{% endfor %}
{% endif %}
{% endwith %}
</div>
</form>
</div>
</div>
<footer>
{% if loading %}
<div class="joyride-tip-guide" data-index="0" style="visibility: visible; display: block; top: 77.5px; left: 570px;"><span class="joyride-nub" style="display: none;"></span><div class="joyride-content-wrapper" role="dialog"><ol>
<h4>
Your account is pending creation...
</h4>
<br><p>
This can take between 5-10 min.
</p>
</ol>
<img src="/register/static/img/loading.gif" style="width: 35px; height: auto"> Pending...
</div></div>
<div class="joyride-modal-bg" style="display: block;"></div>
{% endif %}
{% endblock %}
</body>
{% block footer %}
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-sm-6">
......@@ -92,9 +106,7 @@
</div>
</div>
</div><!-- /.container -->
</footer>
{% endblock %}
</html>
</body></html>
<!doctype html>
<html>
<head>
{% block head %}
<link rel="stylesheet" href="/register/static/style/application.css">
<title>{% block title %}{% endblock %}</title>
{% endblock %}
</head>
<body>
{% block body%} {% endblock %}
</body>
<footer>
{% block footer %}
{% endblock %}
</footer>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Registration Failed</title>
</head>
<body>
<h2>Something went wrong...</h2>
<p>
Redirecting back to sign-in page in 5 seconds.
</p>
</body>
</html>
\ No newline at end of file
......@@ -6,6 +6,7 @@ from app import create_app
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
app.secret_key = 'randomString'
if __name__ == '__main__':
......
# tests.py
import unittest
import flask
from flask import abort, url_for, g
from flask_testing import TestCase
from app import create_app
class TestBase(TestCase):
def create_app(self):
app = create_app('testing')
return app
def setUp(self):
"""
Will be called before every test
"""
app = create_app('testing')
return app
def tearDown(self):
"""
Will be called after every test
"""
class TestModels(TestBase):
# TODO: make tests
pass
class TestViews(TestBase):
# TODO: make tests
def test_index_view(self):
"""
Test that homepage is accessible.
"""
response = self.client.get(url_for('index'))
self.assertEqual(response.status_code, 200)
# with self.app.test_client() as c:
# rv = c.get('/')
# assert flask.session['REMOTE_USER'] == 'bobby'
def test_page_resources(self):
"""
Test that all resources load are found.
"""
with self.app.test_request_context('/?redir=test'):
assert flask.request.path == '/'
c = flask.app.request.args['redir']
assert c == 'test'
# def test_logout_view(self):
# """
# Test that logout link is inaccessible without login
# and redirects to login page then to logout
# """
# target_url = url_for('auth.logout')
# redirect_url = url_for('auth.login', next=target_url)
# response = self.client.get(target_url)
# self.assertEqual(response.status_code, 302)
# self.assertRedirects(response, redirect_url)\
class TestErrorPages(TestBase):
def test_403_forbidden(self):
# create route to abort the request with the 403 Error
@self.app.route('/403')
def forbidden_error():
abort(403)
response = self.client.get('/403')
self.assertEqual(response.status_code, 403)
self.assertTrue("403 Error" in response.data)
def test_404_not_found(self):
response = self.client.get('/nothinghere')
self.assertEqual(response.status_code, 404)
self.assertTrue("404 Error" in response.data)
def test_500_internal_server_error(self):
# create route to abort the request with the 500 Error
@self.app.route('/500')
def internal_server_error():
abort(500)
response = self.client.get('/500')
self.assertEqual(response.status_code, 500)
self.assertTrue("500 Error" in response.data)
if __name__ == '__main__':
unittest.main()
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