Skip to content
Snippets Groups Projects
Commit 9714250a authored by Mitchell Moore's avatar Mitchell Moore
Browse files

Pruning of unnecessary files, and alteration form

parent ab533531
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -3,6 +3,7 @@
# third-party imports
from flask import Flask, redirect, url_for, request
from flask import render_template
from flask_bootstrap import Bootstrap
# local imports
......@@ -10,25 +11,30 @@ from flask import render_template
def create_app(config_name):
app = Flask(__name__)
Bootstrap(app)
@app.route('/success/<name>')
def success(name):
return 'welcome new user %s' % name
@app.route('/success/<name>/<username>')
def success(username, name):
# TODO: Make the success route back to cheaha.
return "Username: %s | Name: %s" % (username, name)
@app.route('/', methods=['GET'])
def index():
return render_template("auth/SignUp.html")
return render_template("index.html")
# return redirect("http://localhost:8080")
@app.route('/', methods=['POST'])
def SignUp():
if request.method == 'POST':
email = request.form['email']
# make username from email
name = request.form['name']
# TODO: Test remote_user string handling from apache server.
# user = request.environ('REMOTE_USER')
# user = request.remote_user.name
# user = request.environ
user = 'Mitchell'
return redirect(url_for('success', name=user))
user = "mmoo97"
return redirect(url_for('success', name=name, username=user))
@app.errorhandler(403)
def forbidden(error):
......
# 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>
<!-- app/templates/auth/register.html -->
<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
{% import "bootstrap/wtf.html" as wtf %}
{% extends "index.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
<!-- 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
Hello
\ No newline at end of file
<!DOCTYPE html>
<html>
<body>
<h2>Sign up Form</h2>
<form action="/" method="post">
<div class ="signUpContainer">
<label for="username"><b>Username:<br></b></label>
<label for="user_val">*REMOTE_USER val from apache server*</label><br>
<label for="name"><b>Full Name:<br></b></label>
<input type="text" placeholder="Enter Full Name" name="name" />
<input type="submit" />
</div>
</form>
</body>
</html>
\ No newline at end of file
......@@ -9,4 +9,4 @@ app = create_app(config_name)
if __name__ == '__main__':
app.run(Debug=True)
app.run()
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