Commit 907ac1f3 authored by Vladislav Rykov's avatar Vladislav Rykov
Browse files

user roles + dafault user admin

parent 398a74a4
......@@ -3,14 +3,14 @@ import bcrypt
@with_psql
def create(cur, name, password):
def create(cur, name, password, role):
query = """
INSERT INTO
users
VALUES
(%s, %s)
(%s, %s, %s)
"""
cur.execute(query, (name, bcrypt.hashpw(password, bcrypt.gensalt())))
cur.execute(query, (name, bcrypt.hashpw(password, bcrypt.gensalt()).decode('utf-8'), role))
return (True,)
@with_psql
......
......@@ -40,6 +40,7 @@
<div class="container">
{% block content %} {% endblock %}
<br><br>
<div class="col-md-6 col-md-offset-3">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
......
......@@ -42,11 +42,11 @@ 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)
#elif (len(password) < 8):
# flash('Password length must be at least 8 characters.', 'danger')
# return redirect(request.url)
else:
res = ud.create(username, password)
res = ud.create(username, password, 'user')
if (not res[0]):
flash('Error: {}'.format(res[1]), 'danger')
return redirect(request.url)
......
......@@ -68,7 +68,8 @@ CREATE TABLE public.pend_msgs (
CREATE TABLE public.users (
name character varying(30) NOT NULL,
password character varying(100) NOT NULL
password character varying(100) NOT NULL,
role character varying(10) NOT NULL
);
......@@ -105,6 +106,7 @@ ALTER TABLE ONLY public.applications
ADD CONSTRAINT applications_username_fkey FOREIGN KEY (username) REFERENCES public.users(name);
INSERT INTO public.users VALUES('admin', '$2b$12$chdF4ji1maIRLd4ms4s4yugFv.2BTvOAwiaWi6iRlTJzlGKjpTcA.', 'admin')
--
-- PostgreSQL database dump complete
--
......
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