diff --git a/README.md b/README.md index 6d3968802c175e386e82defcd5550607d699bb00..6c88eb95cb72d58c15e2c6bd1106d066e06aa517 100644 --- a/README.md +++ b/README.md @@ -3,24 +3,20 @@ To clone this repo use the command: ``` -git clone https://gitlab.rc.uab.edu/noe121/flaskformwork.git +git clone https://gitlab.rc.uab.edu/mmoo97/flask_user_reg.git ``` ## Prerequisites --have pip installed ---follow link for installation -``` -https://packaging.python.org/guides/installing-using-pip-and-virtualenv/ -``` --then install Flask +- Ensure `pip` is installed (see: https://packaging.python.org/guides/installing-using-pip-and-virtualenv/ ) +- 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 ``` diff --git a/app/__init__.py b/app/__init__.py index 418a9a1f6033b5a3066c4dd8f7ac131c7c18d5c9..0ffb1e4198e13680fa95e459828faf6bc64efc82 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,34 +1,62 @@ # app/__init__.py +# 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__) + Bootstrap(app) + global return_url + return_url = '' - @app.route('/success/<name>') - def success(name): - return 'welcome new user %s' % name + @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 = '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 = request.remote_user.name - # 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)) + + else: + return render_template("auth/SignUp.html", user=user) @app.errorhandler(403) def forbidden(error): diff --git a/app/auth/__init__.py b/app/auth/__init__.py deleted file mode 100644 index 44e6588ec1d8f6aeec5de574198c66d87611d643..0000000000000000000000000000000000000000 --- a/app/auth/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -# app/auth/__init__.py - -from flask import Blueprint - -auth = Blueprint('auth', __name__) - -from . import views diff --git a/app/auth/forms.py b/app/auth/forms.py deleted file mode 100644 index f87e52e4cc88de217b2d7e639b62fbe3db4900fc..0000000000000000000000000000000000000000 --- a/app/auth/forms.py +++ /dev/null @@ -1,39 +0,0 @@ -# app/auth/forms.py - -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=[ - DataRequired(), - EqualTo('confirm_password') - ]) - confirm_password = PasswordField('Confirm Password') - submit = SubmitField('Register') - - # def validate_email(self, field): - # if Employee.query.filter_by(email=field.data).first(): - # raise ValidationError('Email is already in use.') - # - # def validate_username(self, field): - # if Employee.query.filter_by(username=field.data).first(): - # 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') - diff --git a/app/auth/views.py b/app/auth/views.py deleted file mode 100644 index c442d169ab17c9f931895b3024efd107da4b3977..0000000000000000000000000000000000000000 --- a/app/auth/views.py +++ /dev/null @@ -1,30 +0,0 @@ -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(email=form.email.data, - username=form.username.data, - first_name=form.first_name.data, - last_name=form.last_name.data, - password=form.password.data) - - # add employee to the database - db.session.add(employee) - db.session.commit() - 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 diff --git a/app/templates/auth/SignUp.html b/app/templates/auth/SignUp.html index 172c96319f3f9b2d7082266204759ceca23abfc8..38930fdb9f697a9b4ef4b80659a10f976b3173de 100644 --- a/app/templates/auth/SignUp.html +++ b/app/templates/auth/SignUp.html @@ -2,41 +2,15 @@ <html> <body> -<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>` -<br> -<label>confirm password: <br> - <input type="password" placeholder="Re-enter Password" name="confirm_password" id="confirm_password" onkeyup='check();' required/> - <span id='message'></span> -</label>`<br> - <input type="submit" value = "Submit" ></input> - <script> - 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()); -} -</script> - - </div> + <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()"/> + </div> </form> - </body> </html> \ No newline at end of file diff --git a/app/templates/auth/SignUp_v2.html b/app/templates/auth/SignUp_v2.html deleted file mode 100644 index d7090374ec8556a18dfcf9ae076cc70ade6cb616..0000000000000000000000000000000000000000 --- a/app/templates/auth/SignUp_v2.html +++ /dev/null @@ -1,14 +0,0 @@ -<!-- 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> - <br/> - {{ wtf.quick_form(form) }} - </div> -</div> -{% endblock %} \ No newline at end of file diff --git a/app/templates/errors/403.html b/app/templates/errors/403.html index 6a66726656b075f49d755435ebae514c9302ad3e..421c6dc905ca533efdd46c3278be25ec0ad58e97 100644 --- a/app/templates/errors/403.html +++ b/app/templates/errors/403.html @@ -4,8 +4,12 @@ <meta charset="UTF-8"> <title>403</title> <h1>403 Error</h1> + </head> <body> +<p>Forbidden</p> + + </body> </html> \ No newline at end of file diff --git a/app/templates/errors/404.html b/app/templates/errors/404.html index 9447e11316b8d87d07681560da937852d823888b..d63ecfdeaa4742f428f4c6da5cbbac877ccce099 100644 --- a/app/templates/errors/404.html +++ b/app/templates/errors/404.html @@ -6,6 +6,7 @@ <h1>404 Error</h1> </head> <body> +<p>Page Not Found</p> </body> </html> \ No newline at end of file diff --git a/app/templates/errors/500.html b/app/templates/errors/500.html index fcf4e90ce9a232385006cb4ff42eb60817b8203c..2a9347aedffbb770678806f21c11dc6966e57d63 100644 --- a/app/templates/errors/500.html +++ b/app/templates/errors/500.html @@ -6,6 +6,7 @@ <h1>500 Error</h1> </head> <body> +<p>Internal Server Error</p> </body> </html> \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html deleted file mode 100644 index 5ab2f8a4323abafb10abb68657d9d39f1a775057..0000000000000000000000000000000000000000 --- a/app/templates/index.html +++ /dev/null @@ -1 +0,0 @@ -Hello \ No newline at end of file diff --git a/run.py b/run.py index 2c5dc9b6272dadc6f73582d8d0736aa907835895..5699926e45f56aa7d16ec763b2144797e1ebd2c1 100644 --- a/run.py +++ b/run.py @@ -9,4 +9,4 @@ app = create_app(config_name) if __name__ == '__main__': - app.run(Debug=True) + app.run()