Implimented some validation logic plus added flash messages

This commit is contained in:
Maxim Stewart 2020-03-14 01:15:31 -05:00
parent 95edeb9987
commit ea56c43eab
9 changed files with 92 additions and 39 deletions

View File

@ -14,7 +14,7 @@ TITLE = app.config['TITLE']
@app.route('/', methods=['GET', 'POST'])
def root():
def home():
if request.method == 'GET':
return render_template('index.html',
title=TITLE)

View File

@ -13,12 +13,8 @@ TITLE = app.config['TITLE']
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
_form = LoginForm()
return render_template('login.html',
title=TITLE,
form=_form)
return render_template('error.html',
title='Error!',
message='Must use GET request type...')

View File

@ -1,7 +1,7 @@
# Python imports
# Lib imports
from flask import request, render_template
from flask import request, render_template, url_for, redirect, flash
# App imports
from core import app, db, RegisterForm
@ -13,12 +13,12 @@ TITLE = app.config['TITLE']
@app.route('/register', methods=['GET', 'POST'])
def register():
if request.method == 'GET':
_form = RegisterForm()
if _form.validate_on_submit():
flash("Account created successfully!", "success")
return redirect(url_for("home"))
return render_template('register.html',
title=TITLE,
form=_form)
return render_template('error.html',
title='Error!',
message='Must use GET request type...')

View File

@ -1,10 +1,10 @@
<div class="container">
<div class="container" style="position: fixed; bottom: 2em;">
<div class="row">
<div class="col justify-content-center text-center">
<nav>
<a href="mailto:"><i title="Send Us an Email" class="fas fa-envelope"></i></a>
<a href="#"><i title="Find Us on Twitter" class="fab fa-twitter"></i></a>
<a href="#"><i title="Find Us on LinkedIn" class="fab fa-linkedin"></i></a>
<a href="https://twitter.com/"><i title="Find Us on Twitter" class="fab fa-twitter"></i></a>
<a href="https://www.linkedin.com/"><i title="Find Us on LinkedIn" class="fab fa-linkedin"></i></a>
<br/>
<i class="fas fa-map-marker-alt">US, Earth</i>
</nav>

View File

@ -4,7 +4,7 @@
<div class="navbar-brand justify-content-center text-center">
<div class="site-branding">
<h1 class="site-title">
<a href="{{ url_for('root') }}" title="TITLE" rel="home">
<a href="{{ url_for('home') }}" title="TITLE" rel="home">
Hello World!
</a>
</h1>
@ -17,7 +17,7 @@
<!-- Links -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="{{ url_for('root') }}">
<a class="nav-link" href="{{ url_for('home') }}">
<i class="fas fa-home"></i>&nbsp;&nbsp;Home</a>
</li>

View File

@ -1,7 +1,6 @@
{% extends "layout.html" %}
{% block body_header_additional %}
<h1 style=" position: fixed; top: 0em;">Header</h1>
{% endblock body_header_additional %}
{% block body_content %}
@ -19,7 +18,6 @@
{% block body_footer_additional %}
<h1 style=" position: fixed; bottom: 0em;">Footer</h1>
{% endblock body_footer_additional %}
{% block body_scripts_additional %}

View File

@ -30,6 +30,17 @@
{% endblock header_css_additional %}
{% endblock %}
<!-- System flashed messages! -->
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<div class=flashes>
{% for category, message in messages %}
<li class="alert alert-{{ category }}">{{ message }}</li>
{% endfor %}
</div>
{% endif %}
{% endwith %}
{% block header_scripts %}
{% block header_scripts_additional %}
{% endblock header_scripts_additional %}

View File

@ -15,11 +15,30 @@
<a href="/register">Register</a>
<div class="form-group">
{{ form.username.label(class="form-control-label") }}
{% if form.username.errors %}
{{ form.username(class="form-control form-control-sm is-invalid", autocomplete="off") }}
<div class="invalid-feedback">
{% for error in form.username.errors %}
<span class="">{{ error }}</span>
{% endfor %}
</div>
{% else %}
{{ form.username(class="form-control form-control-sm", autocomplete="off") }}
{% endif %}
</div>
<div class="form-group">
{{ form.password.label(class="form-control-label") }}
{% if form.email.errors %}
{{ form.email(class="form-control form-control-sm is-invalid", autocomplete="off") }}
<div class="invalid-feedback">
{% for error in form.email.errors %}
<span class="">{{ error }}</span>
{% endfor %}
{% else %}
{{ form.password(class="form-control form-control-sm", autocomplete="off") }}
{% endif %}
</div>
</fieldset>
<div class="form-group justify-content-right text-right">
@ -36,8 +55,4 @@
{% endblock body_footer_additional %}
{% block body_scripts_additional %}
<script src="{{ url_for('static', filename='js/ui-logic.js')}}"></script>
<script src="{{ url_for('static', filename='js/post-ajax.js')}}"></script>
<script src="{{ url_for('static', filename='js/ajax.js')}}"></script>
<script src="{{ url_for('static', filename='js/events.js')}}"></script>
{% endblock body_scripts_additional %}

View File

@ -14,19 +14,56 @@
<legend class="border-bottom mb-4">Create Account</legend>
<div class="form-group">
{{ form.username.label(class="form-control-label") }}
{% if form.username.errors %}
{{ form.username(class="form-control form-control-sm is-invalid", autocomplete="off") }}
<div class="invalid-feedback">
{% for error in form.username.errors %}
<span class="">{{ error }}</span>
{% endfor %}
</div>
{% else %}
{{ form.username(class="form-control form-control-sm", autocomplete="off") }}
{% endif %}
</div>
<div class="form-group">
{{ form.email.label(class="form-control-label") }}
{% if form.email.errors %}
{{ form.email(class="form-control form-control-sm is-invalid", autocomplete="off") }}
<div class="invalid-feedback">
{% for error in form.email.errors %}
<span class="">{{ error }}</span>
{% endfor %}
{% else %}
{{ form.email(class="form-control form-control-sm", autocomplete="off") }}
{% endif %}
</div>
<div class="form-group">
{{ form.password.label(class="form-control-label") }}
{% if form.password.errors %}
{{ form.password(class="form-control form-control-sm is-invalid", autocomplete="off") }}
<div class="invalid-feedback">
{% for error in form.password.errors %}
<span class="">{{ error }}</span>
{% endfor %}
{% else %}
{{ form.password(class="form-control form-control-sm", autocomplete="off") }}
{% endif %}
</div>
<div class="form-group">
{{ form.confirm_password.label(class="form-control-label") }}
{% if form.confirm_password.errors %}
{{ form.confirm_password(class="form-control form-control-sm is-invalid", autocomplete="off") }}
<div class="invalid-feedback">
{% for error in form.confirm_password.errors %}
<span class="">{{ error }}</span>
{% endfor %}
{% else %}
{{ form.confirm_password(class="form-control form-control-sm", autocomplete="off") }}
{% endif %}
</div>
</fieldset>
<div class="form-group justify-content-right text-right">
@ -46,8 +83,4 @@
{% endblock body_footer_additional %}
{% block body_scripts_additional %}
<script src="{{ url_for('static', filename='js/ui-logic.js')}}"></script>
<script src="{{ url_for('static', filename='js/post-ajax.js')}}"></script>
<script src="{{ url_for('static', filename='js/ajax.js')}}"></script>
<script src="{{ url_for('static', filename='js/events.js')}}"></script>
{% endblock body_scripts_additional %}