+ +
diff --git a/README.md b/README.md index 268771b..8db1ed3 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,24 @@ flask app for plurals to publicly share member lists - after cloning, run `py -3 -m venv .venv` in the root directory and then `.venv\Scripts\activate` - then `pip install Flask` inside the virtual env - you might also need to init a database, so use `flask --app myriad init-db` -- to start the site use `flask --app myriad run --debug` \ No newline at end of file +- to start the site use `flask --app myriad run --debug` + +# prod set up + +- not ready yet + +# config + +- create `config.py` in the instance folder and customise the following settings to your needs +``` +REGISTRATION: False # only set to True if in a development situation, or to create your first user +``` + +# usage + +- the software here is free to use, and there's no requirement to link back +- edit the styles and functionality to suit your needs. i'm sure some of you out there are far better with CSS than I am + +# dependencies + +- Flask \ No newline at end of file diff --git a/myriad/__init__.py b/myriad/__init__.py index ad5709e..a9124d7 100644 --- a/myriad/__init__.py +++ b/myriad/__init__.py @@ -11,15 +11,11 @@ def create_app(test_config=None): DATABASE=os.path.join(app.instance_path, 'database.sqlite'), ) - if test_config is None: - # load the instance config, if it exists, when not testing - app.config.from_pyfile('config.py', silent=True) - else: - # load the test config if passed in - app.config.from_mapping(test_config) - # ensure the instance folder exists os.makedirs(app.instance_path, exist_ok=True) + + app.config.from_pyfile('config.py') + #print(app.config["REGISTRATION"]) from . import db db.init_app(app) @@ -31,4 +27,7 @@ def create_app(test_config=None): app.register_blueprint(home.bp) app.add_url_rule('/', endpoint='index') + from . import manage + app.register_blueprint(manage.bp) + return app \ No newline at end of file diff --git a/myriad/auth.py b/myriad/auth.py index 50afc49..ce13c95 100644 --- a/myriad/auth.py +++ b/myriad/auth.py @@ -1,7 +1,7 @@ import functools from flask import ( - Blueprint, flash, g, redirect, render_template, request, session, url_for + Blueprint, flash, g, redirect, render_template, request, session, url_for, current_app ) from werkzeug.security import check_password_hash, generate_password_hash @@ -9,8 +9,34 @@ from myriad.db import get_db bp = Blueprint('auth', __name__, url_prefix='/auth') +def login_required(view): + @functools.wraps(view) + def wrapped_view(**kwargs): + if g.user is None: + return redirect(url_for('auth.login')) + + return view(**kwargs) + + return wrapped_view + + +@bp.before_app_request +def load_logged_in_user(): + user_id = session.get('user_id') + + if user_id is None: + g.user = None + else: + g.user = get_db().execute( + 'SELECT * FROM user WHERE id = ?', (user_id,) + ).fetchone() + + + @bp.route('/register', methods=('GET', 'POST')) def register(): + if current_app.config["REGISTRATION"] == False and g.user is None: + return redirect(url_for("index")) if request.method == 'POST': username = request.form['username'] password = request.form['password'] @@ -63,17 +89,6 @@ def login(): return render_template('auth/login.html') -@bp.before_app_request -def load_logged_in_user(): - user_id = session.get('user_id') - - if user_id is None: - g.user = None - else: - g.user = get_db().execute( - 'SELECT * FROM user WHERE id = ?', (user_id,) - ).fetchone() - @bp.route('/logout') def logout(): @@ -81,12 +96,3 @@ def logout(): return redirect(url_for('index')) -def login_required(view): - @functools.wraps(view) - def wrapped_view(**kwargs): - if g.user is None: - return redirect(url_for('auth.login')) - - return view(**kwargs) - - return wrapped_view \ No newline at end of file diff --git a/myriad/home.py b/myriad/home.py index 28d5beb..d7fc3ce 100644 --- a/myriad/home.py +++ b/myriad/home.py @@ -16,4 +16,10 @@ def index(): # ' FROM post p JOIN user u ON p.author_id = u.id' # ' ORDER BY created DESC' # ).fetchall() - return render_template('index.html') \ No newline at end of file + return render_template('index.html') + +@bp.route('/full') +def full_list(): + db = get_db() + members = db.execute('SELECT * FROM member ORDER BY member_name').fetchall() + return render_template('full.html', memberlist=members) \ No newline at end of file diff --git a/myriad/manage.py b/myriad/manage.py new file mode 100644 index 0000000..23c19b6 --- /dev/null +++ b/myriad/manage.py @@ -0,0 +1,36 @@ +from flask import ( + Blueprint, flash, g, redirect, render_template, request, session, url_for +) + +from myriad.auth import login_required +from myriad.db import get_db + +bp = Blueprint('manage', __name__, url_prefix='/manage') + +@bp.route('/new', methods=('GET', 'POST')) +@login_required +def new(): + if request.method == 'POST': + name = request.form['name'] + bio = request.form['bio'] + #icon = request.form['icon'] + user_id = g.user[0] + db = get_db() + error = None + + if not name: + error = 'Name is required.' + + if error is None: + db.execute( + "INSERT INTO member (user_id, member_name, bio) VALUES (?, ?, ?)", + (user_id, name, bio), + + ) + db.commit() + + flash(error) + + return redirect(url_for('home.full_list')) + + return render_template('manage/new.html') \ No newline at end of file diff --git a/myriad/static/icons/any.jpg b/myriad/static/icons/any.jpg new file mode 100644 index 0000000..34247b9 Binary files /dev/null and b/myriad/static/icons/any.jpg differ diff --git a/myriad/static/style.css b/myriad/static/style.css index 48618de..a47cddf 100644 --- a/myriad/static/style.css +++ b/myriad/static/style.css @@ -29,6 +29,11 @@ form{ label,input{ margin:10px; } +form textarea{ + height:100px; + width:300px; + vertical-align: top; +} diff --git a/myriad/templates/base.html b/myriad/templates/base.html index 1effd19..24613ee 100644 --- a/myriad/templates/base.html +++ b/myriad/templates/base.html @@ -7,14 +7,25 @@