Commit 4ea527c1 authored by Mitchell Moore's avatar Mitchell Moore Committed by Krish Moodbidri
Browse files

Modified basic flask app to populate username and password, pass it to ood and...

Modified basic flask app to populate username and password, pass it to ood and redirect to home page on password authentication

- Pruning of unnecessary files, and alteration form
- Update Readme and minor html tweaks
- Added code to pass username and name variables to ood.
- Added redirect to origin page after success
- Populate user and catch None error if form is submitted blank
- Updated return_url with placeholder value for stability.
- Update
- Updated return_url with proper redirect value
parent 60c6ba82
......@@ -3,24 +3,20 @@
To clone this repo use the command:
git clone
git clone
## Prerequisites
-have pip installed
--follow link for installation
-then install Flask
- Ensure `pip` is installed (see: )
- Install Flask using the `pip` command. Note, to install flask in your own `$HOME` use `pip install --user Flask`
pip install Flask
## Starting the virtual machine for Flask
To start go to formWork directory
-then start virtual machine:
- Change to the `formWork` directory
- then start virtual machine:
source venv/bin/activate
# app/
# local imports
from __future__ import print_function
import os
import sys
# third-party imports
from flask import Flask, redirect, url_for, request
from flask import render_template
# local imports
from flask_bootstrap import Bootstrap
def create_app(config_name):
app = Flask(__name__)
global return_url
return_url = ''
def success(name):
return 'welcome new user %s' % name
def success(username, name):
global return_url
print(username, name, return_url, file=sys.stdout)
# Deliver arguments to script.
tempString = 'sudo user_create ' + username + " " + name
os.system("ssh ohpc " + tempString)
return redirect(return_url, 302)
@app.route('/', methods=['GET'])
def index():
return render_template("auth/SignUp.html")
@app.route('/', methods=['POST'])
global return_url
return_url = request.args.get("redir")
user = request.remote_user
return render_template("auth/SignUp.html", user=user, url=return_url)
@app.route('/', methods=['GET', 'POST'])
def SignUp():
if request.method == 'POST':
email = request.form['email']
# make username from email
# user = request.environ('REMOTE_USER')
# user =
# user = request.environ
user = 'Mitchell'
return redirect(url_for('success', name=user))
name = request.form['name']
user = request.remote_user
if request.method == 'GET':
return render_template("auth/SignUp.html", user=user)
if request.method == 'POST' and name != "":
return redirect(url_for('success', username=str(user), name=name))
return render_template("auth/SignUp.html", user=user)
def forbidden(error):
# app/auth/
from flask import Blueprint
auth = Blueprint('auth', __name__)
from . import views
# app/auth/
from flask_wtf import FlaskForm
from wtforms import PasswordField, StringField, SubmitField, ValidationError
from wtforms.validators import DataRequired, Email, EqualTo
class RegistrationForm(FlaskForm):
Form for users to create new account
email = StringField('Email', validators=[DataRequired(), Email()])
username = StringField('Username', validators=[DataRequired()])
first_name = StringField('First Name', validators=[DataRequired()])
last_name = StringField('Last Name', validators=[DataRequired()])
password = PasswordField('Password', validators=[
confirm_password = PasswordField('Confirm Password')
submit = SubmitField('Register')
# def validate_email(self, field):
# if Employee.query.filter_by(
# raise ValidationError('Email is already in use.')
# def validate_username(self, field):
# if Employee.query.filter_by(
# raise ValidationError('Username is already in use.')
class LoginForm(FlaskForm):
Form for users to login
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
submit = SubmitField('Login')
from flask import flash, redirect, render_template, url_for
from forms import RegistrationForm
from . import auth
@auth.route('/register', methods=['GET', 'POST'])
def register():
Handle requests to the /register route
Add an employee to the database through the registration form
form = RegistrationForm()
if form.validate_on_submit():
employee = Employee(,,,,
# add employee to the database
flash('You have successfully registered! You may now login.')
# redirect to the login page
return redirect(url_for('auth.login'))
# load registration template
return render_template('auth/register.html', form=form, title='Register')
\ No newline at end of file
......@@ -2,41 +2,15 @@
<h2>Sign up Form</h2>
<h1>Sign up Form</h1>
<h2>Hello, {{ user }}!</h2>
<form action="/" method="post">
<div class ="signUpContainer">
<label for="email"><b>Email:<br></b></label>
<input type="email" placeholder="Enter Email" name="email" onkeyup='validateEmail(email);' required/><br>
<label>password : <br>
<input name="password" placeholder="Enter Password" id="password" type="password" onkeyup='check();' required />
<label>confirm password: <br>
<input type="password" placeholder="Re-enter Password" name="confirm_password" id="confirm_password" onkeyup='check();' required/>
<span id='message'></span>
<input type="submit" value = "Submit" ></input>
var check = function() {
if (document.getElementById('password').value ==
document.getElementById('confirm_password').value) {
document.getElementById('message').style.color = 'green';
document.getElementById('message').innerHTML = 'matching';
} else {
document.getElementById('message').style.color = 'red';
document.getElementById('message').innerHTML = 'not matching';
function validateEmail() {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
<label for="name"><b>Full Name:<br></b></label>
<input type="text" placeholder="Enter Full Name" name="name" />
<input type="submit" value="submit" onclick="return empty()"/>
\ No newline at end of file
<!-- app/templates/auth/register.html -->
{% import "bootstrap/wtf.html" as wtf %}
{% extends "base.html" %}
{% block title %}Register{% endblock %}
{% block body %}
<div class="content-section">
<div class="center">
<h1>Register for an account</h1>
{{ wtf.quick_form(form) }}
{% endblock %}
\ No newline at end of file
......@@ -4,8 +4,12 @@
<meta charset="UTF-8">
<h1>403 Error</h1>
\ No newline at end of file
......@@ -6,6 +6,7 @@
<h1>404 Error</h1>
<p>Page Not Found</p>
\ No newline at end of file
......@@ -6,6 +6,7 @@
<h1>500 Error</h1>
<p>Internal Server Error</p>
\ No newline at end of file
\ No newline at end of file
......@@ -9,4 +9,4 @@ app = create_app(config_name)
if __name__ == '__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