Commit 28445f36 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

flashed messages added

parent ff4a13ed
......@@ -39,6 +39,21 @@
<div class="container">
{% block content %} {% endblock %}
<div class="col-md-6 col-md-offset-3">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }} alert-dismissiblei" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
</div>
</div><!-- /.container -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
......
from app import app
from flask import render_template, request, redirect, url_for, session, send_from_directory
from flask import render_template, request, redirect, url_for, session, send_from_directory, flash
import psycopg2
import app.dao.user.user as ud
......@@ -41,13 +41,18 @@ def signup():
if (username == '' or password == ''):
feedback = 'Username or password fields cannot be empty'
return render_template('public/signup.html', feedback=feedback)
elif (len(password) < 8):
flash('Password length must be at least 8 characters.', 'danger')
return redirect(request.url)
else:
res = ud.create(username, password)
if (not res[0]):
return render_template('public/signup.html', feedback=res[1])
flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url)
else:
session['name'] = username
flash('User successfully created.', 'success')
return redirect(url_for('index'))
......@@ -61,12 +66,13 @@ def login():
password = request.form['password'].encode('utf-8')
if (username == '' or password == ''):
feedback = 'Username or password fields cannot be empty'
return render_template('public/login.html', feedback=feedback)
flash('Username or password fields cannot be empty', 'danger')
return redirect(request.url)
else:
res = ud.get(username, password)
if (not res[0]):
return render_template('public/login.html', feedback=msg[1])
flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url)
else:
session['name'] = username
......
No preview for this file type
......@@ -11,6 +11,7 @@ class Config(object):
DB_PORT = 5432
SESSION_COOKIE_SECURE = True
REMEMBER_COOKIE_SECURE = True
APPKEY_LENGTH = 8
DATA_DOWNLOAD_DIR = 'data'
......@@ -22,9 +23,11 @@ class DevelopmentConfig(Config):
DEBUG = True
SESSION_COOKIE_SECURE = False
REMEMBER_COOKIE_SECURE = False
class TestingConfig(Config):
TESTING = True
SESSION_COOKIE_SECURE = False
REMEMBER_COOKIE_SECURE = False
No preview for this file type
Supports Markdown
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