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

flashed messages added

parent ff4a13ed
...@@ -39,6 +39,21 @@ ...@@ -39,6 +39,21 @@
<div class="container"> <div class="container">
{% block content %} {% endblock %} {% 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 --> </div><!-- /.container -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
......
from app import app 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 psycopg2
import app.dao.user.user as ud import app.dao.user.user as ud
...@@ -41,13 +41,18 @@ def signup(): ...@@ -41,13 +41,18 @@ def signup():
if (username == '' or password == ''): if (username == '' or password == ''):
feedback = 'Username or password fields cannot be empty' feedback = 'Username or password fields cannot be empty'
return render_template('public/signup.html', feedback=feedback) 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: else:
res = ud.create(username, password) res = ud.create(username, password)
if (not res[0]): if (not res[0]):
return render_template('public/signup.html', feedback=res[1]) flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url)
else: else:
session['name'] = username session['name'] = username
flash('User successfully created.', 'success')
return redirect(url_for('index')) return redirect(url_for('index'))
...@@ -61,12 +66,13 @@ def login(): ...@@ -61,12 +66,13 @@ def login():
password = request.form['password'].encode('utf-8') password = request.form['password'].encode('utf-8')
if (username == '' or password == ''): if (username == '' or password == ''):
feedback = 'Username or password fields cannot be empty' flash('Username or password fields cannot be empty', 'danger')
return render_template('public/login.html', feedback=feedback) return redirect(request.url)
else: else:
res = ud.get(username, password) res = ud.get(username, password)
if (not res[0]): if (not res[0]):
return render_template('public/login.html', feedback=msg[1]) flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url)
else: else:
session['name'] = username session['name'] = username
......
No preview for this file type
...@@ -11,6 +11,7 @@ class Config(object): ...@@ -11,6 +11,7 @@ class Config(object):
DB_PORT = 5432 DB_PORT = 5432
SESSION_COOKIE_SECURE = True SESSION_COOKIE_SECURE = True
REMEMBER_COOKIE_SECURE = True
APPKEY_LENGTH = 8 APPKEY_LENGTH = 8
DATA_DOWNLOAD_DIR = 'data' DATA_DOWNLOAD_DIR = 'data'
...@@ -22,9 +23,11 @@ class DevelopmentConfig(Config): ...@@ -22,9 +23,11 @@ class DevelopmentConfig(Config):
DEBUG = True DEBUG = True
SESSION_COOKIE_SECURE = False SESSION_COOKIE_SECURE = False
REMEMBER_COOKIE_SECURE = False
class TestingConfig(Config): class TestingConfig(Config):
TESTING = True TESTING = True
SESSION_COOKIE_SECURE = False 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