Skip to content
Snippets Groups Projects
Commit 60c6ba82 authored by Nick Valladares's avatar Nick Valladares Committed by Krish Moodbidri
Browse files

Created a basic flask app with signup and error html pages.

parents
No related branches found
No related tags found
No related merge requests found
venv/
*.pyc
__pycache__/
instance/
.pytest_cache/
.coverage
htmlcov/
dist/
build/
*.egg-info/
**.idea/
# Project Setup
To clone this repo use the command:
```
git clone https://gitlab.rc.uab.edu/noe121/flaskformwork.git
```
## Prerequisites
-have pip installed
--follow link for installation
```
https://packaging.python.org/guides/installing-using-pip-and-virtualenv/
```
-then install Flask
```
pip install Flask
```
## Starting the virtual machine for Flask
To start go to formWork directory
-then start virtual machine:
```
source venv/bin/activate
```
# app/__init__.py
# third-party imports
from flask import Flask, redirect, url_for, request
from flask import render_template
# local imports
def create_app(config_name):
app = Flask(__name__)
@app.route('/success/<name>')
def success(name):
return 'welcome new user %s' % name
@app.route('/', methods=['GET'])
def index():
return render_template("auth/SignUp.html")
@app.route('/', methods=['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))
@app.errorhandler(403)
def forbidden(error):
return render_template('errors/403.html', title='Forbidden'), 403
@app.errorhandler(404)
def page_not_found(error):
return render_template('errors/404.html', title='Page Not Found'), 404
@app.errorhandler(500)
def internal_server_error(error):
return render_template('errors/500.html', title='Server Error'), 500
return app
# app/auth/__init__.py
from flask import Blueprint
auth = Blueprint('auth', __name__)
from . import views
# 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')
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
<!DOCTYPE html>
<html>
<body>
<h2>Sign up Form</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>
</form>
</body>
</html>
\ 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>
<br/>
{{ wtf.quick_form(form) }}
</div>
</div>
{% endblock %}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>403</title>
<h1>403 Error</h1>
</head>
<body>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>404</title>
<h1>404 Error</h1>
</head>
<body>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>500</title>
<h1>500 Error</h1>
</head>
<body>
</body>
</html>
\ No newline at end of file
Hello
\ No newline at end of file
# config.py
class Config(object):
"""
Common configurations
"""
DEBUG = True
class DevelopmentConfig(Config):
"""
Development configurations
"""
DEBUG = True
class ProductionConfig(Config):
"""
Production configurations
"""
DEBUG = False
class TestingConfig(Config):
"""
Testing configurations
"""
TESTING = True
app_config = {
'development': DevelopmentConfig,
'production': ProductionConfig,
'testing': TestingConfig
}
Click==7.0
dominate==2.3.5
Flask==1.0.2
Flask-Bootstrap==3.3.7.1
Flask-Login==0.4.1
Flask-Testing==0.7.1
Flask-WTF==0.14.2
itsdangerous==1.1.0
Jinja2==2.10
Mako==1.0.7
MarkupSafe==1.1.1
pbr==5.1.3
python-dateutil==1.5
python-editor==1.0.4
pytz==2013.7
six==1.12.0
stevedore==1.30.1
virtualenv==16.4.3
virtualenv-clone==0.5.1
virtualenvwrapper==4.8.4
visitor==0.1.3
Werkzeug==0.14.1
WTForms==2.2.1
run.py 0 → 100644
# run.py
import os
from app import create_app
config_name = os.getenv('FLASK_CONFIG')
app = create_app(config_name)
if __name__ == '__main__':
app.run(Debug=True)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment