mirror of
https://github.com/Derpy-Leggies/OnlyLegs.git
synced 2025-06-29 11:36:16 +00:00
Update to reccommended file structure
Use reccommended database structure Switch to SQLite and update scheme along with it
This commit is contained in:
parent
29d204f95e
commit
a499e6c840
41 changed files with 544 additions and 342 deletions
139
.gitignore
vendored
139
.gitignore
vendored
|
@ -1,139 +1,22 @@
|
||||||
# Remove all development files
|
# Remove all development files
|
||||||
uploads/
|
uploads/
|
||||||
static/theme/*
|
gallery/static/theme/*
|
||||||
|
|
||||||
# remove all PyCharm files
|
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
# remove all VSCode files
|
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
|
||||||
__pycache__/
|
|
||||||
*.py[cod]
|
|
||||||
*$py.class
|
|
||||||
|
|
||||||
# C extensions
|
|
||||||
*.so
|
|
||||||
|
|
||||||
# Distribution / packaging
|
|
||||||
.Python
|
|
||||||
build/
|
|
||||||
develop-eggs/
|
|
||||||
dist/
|
|
||||||
downloads/
|
|
||||||
eggs/
|
|
||||||
.eggs/
|
|
||||||
lib/
|
|
||||||
lib64/
|
|
||||||
parts/
|
|
||||||
sdist/
|
|
||||||
var/
|
|
||||||
wheels/
|
|
||||||
pip-wheel-metadata/
|
|
||||||
share/python-wheels/
|
|
||||||
*.egg-info/
|
|
||||||
.installed.cfg
|
|
||||||
*.egg
|
|
||||||
MANIFEST
|
|
||||||
|
|
||||||
# PyInstaller
|
|
||||||
# Usually these files are written by a python script from a template
|
|
||||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
||||||
*.manifest
|
|
||||||
*.spec
|
|
||||||
|
|
||||||
# Installer logs
|
|
||||||
pip-log.txt
|
|
||||||
pip-delete-this-directory.txt
|
|
||||||
|
|
||||||
# Unit test / coverage reports
|
|
||||||
htmlcov/
|
|
||||||
.tox/
|
|
||||||
.nox/
|
|
||||||
.coverage
|
|
||||||
.coverage.*
|
|
||||||
.cache
|
|
||||||
nosetests.xml
|
|
||||||
coverage.xml
|
|
||||||
*.cover
|
|
||||||
*.py,cover
|
|
||||||
.hypothesis/
|
|
||||||
.pytest_cache/
|
|
||||||
|
|
||||||
# Translations
|
|
||||||
*.mo
|
|
||||||
*.pot
|
|
||||||
|
|
||||||
# Django stuff:
|
|
||||||
*.log
|
|
||||||
local_settings.py
|
|
||||||
db.sqlite3
|
|
||||||
db.sqlite3-journal
|
|
||||||
|
|
||||||
# Flask stuff:
|
|
||||||
instance/
|
|
||||||
.webassets-cache
|
|
||||||
|
|
||||||
# Scrapy stuff:
|
|
||||||
.scrapy
|
|
||||||
|
|
||||||
# Sphinx documentation
|
|
||||||
docs/_build/
|
|
||||||
|
|
||||||
# PyBuilder
|
|
||||||
target/
|
|
||||||
|
|
||||||
# Jupyter Notebook
|
|
||||||
.ipynb_checkpoints
|
|
||||||
|
|
||||||
# IPython
|
|
||||||
profile_default/
|
|
||||||
ipython_config.py
|
|
||||||
|
|
||||||
# pyenv
|
|
||||||
.python-version
|
|
||||||
|
|
||||||
# pipenv
|
|
||||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
||||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
||||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
||||||
# install all needed dependencies.
|
|
||||||
#Pipfile.lock
|
|
||||||
|
|
||||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
||||||
__pypackages__/
|
|
||||||
|
|
||||||
# Celery stuff
|
|
||||||
celerybeat-schedule
|
|
||||||
celerybeat.pid
|
|
||||||
|
|
||||||
# SageMath parsed files
|
|
||||||
*.sage.py
|
|
||||||
|
|
||||||
# Environments
|
|
||||||
.env
|
|
||||||
.venv
|
|
||||||
env/
|
|
||||||
venv/
|
venv/
|
||||||
ENV/
|
.env
|
||||||
env.bak/
|
|
||||||
venv.bak/
|
|
||||||
|
|
||||||
# Spyder project settings
|
*.pyc
|
||||||
.spyderproject
|
__pycache__/
|
||||||
.spyproject
|
|
||||||
|
|
||||||
# Rope project settings
|
instance/
|
||||||
.ropeproject
|
|
||||||
|
|
||||||
# mkdocs documentation
|
.pytest_cache/
|
||||||
/site
|
.coverage
|
||||||
|
htmlcov/
|
||||||
|
|
||||||
# mypy
|
dist/
|
||||||
.mypy_cache/
|
build/
|
||||||
.dmypy.json
|
*.egg-info/
|
||||||
dmypy.json
|
|
||||||
|
|
||||||
# Pyre type checker
|
|
||||||
.pyre/
|
|
161
app.py
161
app.py
|
@ -1,161 +0,0 @@
|
||||||
print("""
|
|
||||||
___ _ _
|
|
||||||
/ _ \\ _ __ | |_ _| | ___ __ _ ___
|
|
||||||
| | | | '_ \\| | | | | | / _ \\/ _` / __|
|
|
||||||
| |_| | | | | | |_| | |__| __/ (_| \\__ \\
|
|
||||||
\\___/|_| |_|_|\\__, |_____\\___|\\__, |___/
|
|
||||||
|___/ |___/
|
|
||||||
Created by Fluffy Bean - Version 100123
|
|
||||||
""")
|
|
||||||
|
|
||||||
# Import base packages
|
|
||||||
import time
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
|
|
||||||
# Import required OnlyLegs packages
|
|
||||||
from packages import onlylegsDB
|
|
||||||
onlylegsDB = onlylegsDB.DBmanager()
|
|
||||||
onlylegsDB.initialize()
|
|
||||||
|
|
||||||
from packages import onlylegsSass
|
|
||||||
onlylegsSass = onlylegsSass.Sassy('default')
|
|
||||||
|
|
||||||
# Import flask
|
|
||||||
from flask import Flask, render_template, send_from_directory, abort, url_for, jsonify, redirect, request, session
|
|
||||||
from werkzeug.utils import secure_filename
|
|
||||||
|
|
||||||
# Set flask config
|
|
||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
UPLOAD_FOLDER = os.path.join(BASE_DIR, 'usr', 'uploads')
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
|
||||||
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# ERROR HANDLERS
|
|
||||||
#
|
|
||||||
@app.errorhandler(405)
|
|
||||||
def method_not_allowed(e):
|
|
||||||
error = '405'
|
|
||||||
msg = 'Method sussy wussy'
|
|
||||||
return render_template('error.html', error=error, msg=msg), 404
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
|
||||||
def page_not_found(e):
|
|
||||||
error = '404'
|
|
||||||
msg = 'Could not find what you need!'
|
|
||||||
return render_template('error.html', error=error, msg=msg), 404
|
|
||||||
|
|
||||||
@app.errorhandler(403)
|
|
||||||
def forbidden(e):
|
|
||||||
error = '403'
|
|
||||||
msg = 'Go away! This is no place for you!'
|
|
||||||
return render_template('error.html', error=error, msg=msg), 403
|
|
||||||
|
|
||||||
@app.errorhandler(410)
|
|
||||||
def gone(e):
|
|
||||||
error = '410'
|
|
||||||
msg = 'The page is no longer available! *sad face*'
|
|
||||||
return render_template('error.html', error=error, msg=msg), 410
|
|
||||||
|
|
||||||
@app.errorhandler(500)
|
|
||||||
def internal_server_error(e):
|
|
||||||
error = '500'
|
|
||||||
msg = 'Server died inside :c'
|
|
||||||
return render_template('error.html', error=error, msg=msg), 500
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# ROUTES
|
|
||||||
#
|
|
||||||
@app.route('/')
|
|
||||||
def home():
|
|
||||||
return render_template('home.html')
|
|
||||||
|
|
||||||
@app.route('/group')
|
|
||||||
def group():
|
|
||||||
return render_template('group.html', group_id='gwa gwa')
|
|
||||||
|
|
||||||
@app.route('/group/<group_id>')
|
|
||||||
def group_id(group_id):
|
|
||||||
try:
|
|
||||||
group_id = int(group_id)
|
|
||||||
except ValueError:
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
return render_template('group.html', group_id=group_id)
|
|
||||||
|
|
||||||
@app.route('/upload')
|
|
||||||
def upload():
|
|
||||||
return render_template('upload.html')
|
|
||||||
|
|
||||||
@app.route('/upload/form', methods=['POST'])
|
|
||||||
def upload_form():
|
|
||||||
if request.method != 'POST':
|
|
||||||
abort(405)
|
|
||||||
|
|
||||||
return 'balls'
|
|
||||||
|
|
||||||
@app.route('/profile')
|
|
||||||
def profile():
|
|
||||||
return render_template('profile.html', user_id='gwa gwa')
|
|
||||||
|
|
||||||
@app.route('/profile/<user_id>')
|
|
||||||
def profile_id(user_id):
|
|
||||||
try:
|
|
||||||
user_id = int(user_id)
|
|
||||||
except ValueError:
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
return render_template('profile.html', user_id=user_id)
|
|
||||||
|
|
||||||
@app.route('/settings')
|
|
||||||
def settings():
|
|
||||||
return render_template('settings.html')
|
|
||||||
|
|
||||||
@app.route('/image/<request_id>')
|
|
||||||
def image(request_id):
|
|
||||||
# Check if request_id is valid
|
|
||||||
try:
|
|
||||||
request_id = int(request_id)
|
|
||||||
except ValueError:
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
result = onlylegsDB.getImage(request_id)
|
|
||||||
|
|
||||||
return render_template('image.html', fileName=result[1], id=request_id)
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# METHODS
|
|
||||||
#
|
|
||||||
@app.route('/fileList/<item_type>', methods=['GET'])
|
|
||||||
def image_list(item_type):
|
|
||||||
if request.method != 'GET':
|
|
||||||
abort(405)
|
|
||||||
|
|
||||||
cursor = onlylegsDB.database.cursor()
|
|
||||||
cursor.execute("SELECT * FROM posts ORDER BY id DESC")
|
|
||||||
|
|
||||||
item_list = cursor.fetchall()
|
|
||||||
|
|
||||||
return jsonify(item_list)
|
|
||||||
|
|
||||||
@app.route('/uploads/<quality>/<request_file>', methods=['GET'])
|
|
||||||
def uploads(quality, request_file):
|
|
||||||
if request.method != 'GET':
|
|
||||||
abort(405)
|
|
||||||
|
|
||||||
quality = secure_filename(quality)
|
|
||||||
quality_dir = os.path.join(app.config['UPLOAD_FOLDER'], quality)
|
|
||||||
if not os.path.isdir(quality_dir):
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
request_file = secure_filename(request_file)
|
|
||||||
|
|
||||||
if not os.path.isfile(os.path.join(quality_dir, request_file)):
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
return send_from_directory(quality_dir, request_file)
|
|
126
gallery/__init__.py
Normal file
126
gallery/__init__.py
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
print("""
|
||||||
|
___ _ _
|
||||||
|
/ _ \\ _ __ | |_ _| | ___ __ _ ___
|
||||||
|
| | | | '_ \\| | | | | | / _ \\/ _` / __|
|
||||||
|
| |_| | | | | | |_| | |__| __/ (_| \\__ \\
|
||||||
|
\\___/|_| |_|_|\\__, |_____\\___|\\__, |___/
|
||||||
|
|___/ |___/
|
||||||
|
Created by Fluffy Bean - Version 100123
|
||||||
|
""")
|
||||||
|
|
||||||
|
# Import base packages
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Import required OnlyLegs packages
|
||||||
|
#from packages import onlylegsDB
|
||||||
|
#onlylegsDB = onlylegsDB.DBmanager()
|
||||||
|
#onlylegsDB.initialize()
|
||||||
|
|
||||||
|
#from packages import onlylegsSass
|
||||||
|
#onlylegsSass = onlylegsSass.Sassy('default')
|
||||||
|
|
||||||
|
# Import flask
|
||||||
|
from flask import *
|
||||||
|
from werkzeug.utils import secure_filename
|
||||||
|
|
||||||
|
def create_app(test_config=None):
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
load_dotenv(os.path.join('./gallery', 'user', '.env'))
|
||||||
|
|
||||||
|
# create and configure the app
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
app.config.from_mapping(
|
||||||
|
SECRET_KEY=os.environ.get('FLASK_SECRET'),
|
||||||
|
DATABASE=os.path.join(app.instance_path, 'gallery.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
|
||||||
|
try:
|
||||||
|
os.makedirs(app.instance_path)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@app.errorhandler(405)
|
||||||
|
def method_not_allowed(e):
|
||||||
|
error = '405'
|
||||||
|
msg = 'Method sussy wussy'
|
||||||
|
return render_template('error.html', error=error, msg=msg), 404
|
||||||
|
|
||||||
|
@app.errorhandler(404)
|
||||||
|
def page_not_found(e):
|
||||||
|
error = '404'
|
||||||
|
msg = 'Could not find what you need!'
|
||||||
|
return render_template('error.html', error=error, msg=msg), 404
|
||||||
|
|
||||||
|
@app.errorhandler(403)
|
||||||
|
def forbidden(e):
|
||||||
|
error = '403'
|
||||||
|
msg = 'Go away! This is no place for you!'
|
||||||
|
return render_template('error.html', error=error, msg=msg), 403
|
||||||
|
|
||||||
|
@app.errorhandler(410)
|
||||||
|
def gone(e):
|
||||||
|
error = '410'
|
||||||
|
msg = 'The page is no longer available! *sad face*'
|
||||||
|
return render_template('error.html', error=error, msg=msg), 410
|
||||||
|
|
||||||
|
@app.errorhandler(500)
|
||||||
|
def internal_server_error(e):
|
||||||
|
error = '500'
|
||||||
|
msg = 'Server died inside :c'
|
||||||
|
return render_template('error.html', error=error, msg=msg), 500
|
||||||
|
|
||||||
|
from . import auth
|
||||||
|
app.register_blueprint(auth.bp)
|
||||||
|
|
||||||
|
from . import routes
|
||||||
|
app.register_blueprint(routes.bp)
|
||||||
|
app.add_url_rule('/', endpoint='index')
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# METHODS
|
||||||
|
#
|
||||||
|
@app.route('/fileList/<item_type>', methods=['GET'])
|
||||||
|
def image_list(item_type):
|
||||||
|
if request.method != 'GET':
|
||||||
|
abort(405)
|
||||||
|
|
||||||
|
cursor = onlylegsDB.database.cursor()
|
||||||
|
cursor.execute("SELECT * FROM posts ORDER BY id DESC")
|
||||||
|
|
||||||
|
item_list = cursor.fetchall()
|
||||||
|
|
||||||
|
return jsonify(item_list)
|
||||||
|
|
||||||
|
@app.route('/uploads/<quality>/<request_file>', methods=['GET'])
|
||||||
|
def uploads(quality, request_file):
|
||||||
|
if request.method != 'GET':
|
||||||
|
abort(405)
|
||||||
|
|
||||||
|
quality = secure_filename(quality)
|
||||||
|
quality_dir = os.path.join(app.config['UPLOAD_FOLDER'], quality)
|
||||||
|
if not os.path.isdir(quality_dir):
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
request_file = secure_filename(request_file)
|
||||||
|
|
||||||
|
if not os.path.isfile(os.path.join(quality_dir, request_file)):
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
return send_from_directory(quality_dir, request_file)
|
||||||
|
|
||||||
|
from . import db
|
||||||
|
db.init_app(app)
|
||||||
|
|
||||||
|
return app
|
93
gallery/auth.py
Normal file
93
gallery/auth.py
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
import functools
|
||||||
|
from flask import (
|
||||||
|
Blueprint, flash, g, redirect, render_template, request, session, url_for
|
||||||
|
)
|
||||||
|
from werkzeug.security import check_password_hash, generate_password_hash
|
||||||
|
from gallery.db import get_db
|
||||||
|
|
||||||
|
bp = Blueprint('auth', __name__, url_prefix='/auth')
|
||||||
|
|
||||||
|
|
||||||
|
@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 users WHERE id = ?', (user_id,)
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/register', methods=('GET', 'POST'))
|
||||||
|
def register():
|
||||||
|
if request.method == 'POST':
|
||||||
|
username = request.form['username']
|
||||||
|
password = request.form['password']
|
||||||
|
db = get_db()
|
||||||
|
error = None
|
||||||
|
|
||||||
|
if not username:
|
||||||
|
error = 'Username is required.'
|
||||||
|
elif not password:
|
||||||
|
error = 'Password is required.'
|
||||||
|
|
||||||
|
if error is None:
|
||||||
|
try:
|
||||||
|
db.execute(
|
||||||
|
"INSERT INTO users (username, email, password) VALUES (?, ?, ?)",
|
||||||
|
(username,'dummy@email.com' , generate_password_hash(password)),
|
||||||
|
)
|
||||||
|
db.commit()
|
||||||
|
except db.IntegrityError:
|
||||||
|
error = f"User {username} is already registered."
|
||||||
|
else:
|
||||||
|
return redirect(url_for("auth.login"))
|
||||||
|
|
||||||
|
flash(error)
|
||||||
|
|
||||||
|
return render_template('auth/register.html')
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/login', methods=('GET', 'POST'))
|
||||||
|
def login():
|
||||||
|
if request.method == 'POST':
|
||||||
|
username = request.form['username']
|
||||||
|
password = request.form['password']
|
||||||
|
db = get_db()
|
||||||
|
error = None
|
||||||
|
user = db.execute(
|
||||||
|
'SELECT * FROM users WHERE username = ?', (username,)
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
|
if user is None:
|
||||||
|
error = 'Incorrect username.'
|
||||||
|
elif not check_password_hash(user['password'], password):
|
||||||
|
error = 'Incorrect password.'
|
||||||
|
|
||||||
|
if error is None:
|
||||||
|
session.clear()
|
||||||
|
session['user_id'] = user['id']
|
||||||
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
|
flash(error)
|
||||||
|
|
||||||
|
return render_template('auth/login.html')
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/logout')
|
||||||
|
def logout():
|
||||||
|
session.clear()
|
||||||
|
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
|
41
gallery/db.py
Normal file
41
gallery/db.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
import click
|
||||||
|
from flask import current_app, g
|
||||||
|
|
||||||
|
|
||||||
|
def get_db():
|
||||||
|
if 'db' not in g:
|
||||||
|
g.db = sqlite3.connect(
|
||||||
|
current_app.config['DATABASE'],
|
||||||
|
detect_types=sqlite3.PARSE_DECLTYPES
|
||||||
|
)
|
||||||
|
g.db.row_factory = sqlite3.Row
|
||||||
|
|
||||||
|
return g.db
|
||||||
|
|
||||||
|
|
||||||
|
def close_db(e=None):
|
||||||
|
db = g.pop('db', None)
|
||||||
|
|
||||||
|
if db is not None:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
|
def init_db():
|
||||||
|
db = get_db()
|
||||||
|
|
||||||
|
with current_app.open_resource('schema.sql') as f:
|
||||||
|
db.executescript(f.read().decode('utf8'))
|
||||||
|
|
||||||
|
|
||||||
|
@click.command('init-db')
|
||||||
|
def init_db_command():
|
||||||
|
"""Create tables if not already created"""
|
||||||
|
init_db()
|
||||||
|
click.echo('Initialized the database!')
|
||||||
|
|
||||||
|
|
||||||
|
def init_app(app):
|
||||||
|
app.teardown_appcontext(close_db)
|
||||||
|
app.cli.add_command(init_db_command)
|
69
gallery/routes.py
Normal file
69
gallery/routes.py
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
from flask import (
|
||||||
|
Blueprint, flash, g, redirect, render_template, request, url_for
|
||||||
|
)
|
||||||
|
from werkzeug.exceptions import abort
|
||||||
|
|
||||||
|
from gallery.auth import login_required
|
||||||
|
from gallery.db import get_db
|
||||||
|
|
||||||
|
bp = Blueprint('routes', __name__)
|
||||||
|
|
||||||
|
#
|
||||||
|
# ROUTES
|
||||||
|
#
|
||||||
|
@bp.route('/')
|
||||||
|
def index():
|
||||||
|
return render_template('index.html')
|
||||||
|
|
||||||
|
@bp.route('/group')
|
||||||
|
def group():
|
||||||
|
return render_template('group.html', group_id='gwa gwa')
|
||||||
|
|
||||||
|
@bp.route('/group/<group_id>')
|
||||||
|
def group_id(group_id):
|
||||||
|
try:
|
||||||
|
group_id = int(group_id)
|
||||||
|
except ValueError:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
return render_template('group.html', group_id=group_id)
|
||||||
|
|
||||||
|
@bp.route('/upload')
|
||||||
|
def upload():
|
||||||
|
return render_template('upload.html')
|
||||||
|
|
||||||
|
@bp.route('/upload/form', methods=['POST'])
|
||||||
|
def upload_form():
|
||||||
|
if request.method != 'POST':
|
||||||
|
abort(405)
|
||||||
|
|
||||||
|
return 'balls'
|
||||||
|
|
||||||
|
@bp.route('/profile')
|
||||||
|
def profile():
|
||||||
|
return render_template('profile.html', user_id='gwa gwa')
|
||||||
|
|
||||||
|
@bp.route('/profile/<user_id>')
|
||||||
|
def profile_id(user_id):
|
||||||
|
try:
|
||||||
|
user_id = int(user_id)
|
||||||
|
except ValueError:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
return render_template('profile.html', user_id=user_id)
|
||||||
|
|
||||||
|
@bp.route('/settings')
|
||||||
|
def settings():
|
||||||
|
return render_template('settings.html')
|
||||||
|
|
||||||
|
@bp.route('/image/<request_id>')
|
||||||
|
def image(request_id):
|
||||||
|
# Check if request_id is valid
|
||||||
|
try:
|
||||||
|
request_id = int(request_id)
|
||||||
|
except ValueError:
|
||||||
|
abort(404)
|
||||||
|
|
||||||
|
result = onlylegsDB.getImage(request_id)
|
||||||
|
|
||||||
|
return render_template('image.html', fileName=result[1], id=request_id)
|
78
gallery/schema.sql
Normal file
78
gallery/schema.sql
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
username TEXT NOT NULL UNIQUE,
|
||||||
|
email TEXT NOT NULL,
|
||||||
|
password TEXT NOT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS posts (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
file_name TEXT NOT NULL UNIQUE,
|
||||||
|
author_id INTEGER NOT NULL,
|
||||||
|
description TEXT NOT NULL,
|
||||||
|
alt TEXT NOT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (author_id) REFERENCES users (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS groups (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
author_id INTEGER NOT NULL,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (author_id) REFERENCES users (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS group_junction (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
group_id INTEGER NOT NULL,
|
||||||
|
image_id INTEGER NOT NULL,
|
||||||
|
FOREIGN KEY (group_id) REFERENCES groups (id),
|
||||||
|
FOREIGN KEY (image_id) REFERENCES posts (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS permissions (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
user_id INTEGER NOT NULL,
|
||||||
|
admin BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
create_posts BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS devices (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
user_id INTEGER NOT NULL,
|
||||||
|
device_id TEXT NOT NULL,
|
||||||
|
cookie TEXT NOT NULL,
|
||||||
|
ip TEXT NOT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS tokens (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
token TEXT NOT NULL UNIQUE,
|
||||||
|
is_used BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
used_by INTEGER DEFAULT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (used_by) REFERENCES users (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS logs (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
ip TEXT NOT NULL,
|
||||||
|
user_id INTEGER DEFAULT NULL,
|
||||||
|
code INTEGER NOT NULL,
|
||||||
|
note TEXT DEFAULT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users (id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS bans (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
ip TEXT NOT NULL,
|
||||||
|
code INTEGER NOT NULL,
|
||||||
|
note TEXT DEFAULT NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
24
gallery/templates/auth/login.html
Normal file
24
gallery/templates/auth/login.html
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{% extends 'layout.html' %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="app">
|
||||||
|
<h1>Login</h1>
|
||||||
|
<div id="login" class="login">
|
||||||
|
<form method="post">
|
||||||
|
<label for="username">Username</label>
|
||||||
|
<input name="username" id="username" required>
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input type="password" name="password" id="password" required>
|
||||||
|
<input type="submit" value="Log In">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% for message in get_flashed_messages() %}
|
||||||
|
<div class="flash">{{ message }}</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
24
gallery/templates/auth/register.html
Normal file
24
gallery/templates/auth/register.html
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{% extends 'layout.html' %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="app">
|
||||||
|
<h1>register</h1>
|
||||||
|
<div id="register" class="register">
|
||||||
|
<form method="post">
|
||||||
|
<label for="username">Username</label>
|
||||||
|
<input name="username" id="username" required>
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input type="password" name="password" id="password" required>
|
||||||
|
<input type="submit" value="Register">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% for message in get_flashed_messages() %}
|
||||||
|
<div class="flash">{{ message }}</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
12
gallery/templates/error.html
Normal file
12
gallery/templates/error.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{% extends 'layout.html' %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="app err-warning">
|
||||||
|
<h1>{{error}}</h1>
|
||||||
|
<p>{{msg}}</p>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
12
gallery/templates/group.html
Normal file
12
gallery/templates/group.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{% extends 'layout.html' %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="app">
|
||||||
|
<h1>Image Group</h1>
|
||||||
|
<p>{{group_id}}</p>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -1,6 +1,10 @@
|
||||||
{% extends 'layout.html' %}
|
{% extends 'layout.html' %}
|
||||||
{% block content %}
|
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
<div class="app">
|
<div class="app">
|
||||||
<div class="image__container">
|
<div class="image__container">
|
||||||
<img class="image__item" src="/uploads/original/{{ fileName }}" onload="imgFade(this)" style="display:none;"/>
|
<img class="image__item" src="/uploads/original/{{ fileName }}" onload="imgFade(this)" style="display:none;"/>
|
|
@ -1,9 +1,10 @@
|
||||||
{% extends 'layout.html' %}
|
{% extends 'layout.html' %}
|
||||||
{% block content %}
|
|
||||||
<header>
|
{% block header %}
|
||||||
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
||||||
<span></span>
|
{% endblock %}
|
||||||
</header>
|
|
||||||
|
{% block content %}
|
||||||
<div class="app">
|
<div class="app">
|
||||||
<h1>Gallery</h1>
|
<h1>Gallery</h1>
|
||||||
<div id="gallery" class="gallery"></div>
|
<div id="gallery" class="gallery"></div>
|
|
@ -14,7 +14,7 @@
|
||||||
<body>
|
<body>
|
||||||
<nav id="navRoot">
|
<nav id="navRoot">
|
||||||
<div>
|
<div>
|
||||||
<a href="{{url_for('home')}}">
|
<a href="{{url_for('index')}}">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-2 -2 24 24" width="24" fill="currentColor">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-2 -2 24 24" width="24" fill="currentColor">
|
||||||
<path d="M2 8v10h12V8H2zm2-2V2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2v4a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2zm2 0h8a2 2 0 0 1 2 2v4h2V2H6v4zm0 9a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm0-2a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"></path><path d="M7 6a3 3 0 1 1 6 0h-2a1 1 0 0 0-2 0H7zm1.864 13.518l2.725-4.672a1 1 0 0 1 1.6-.174l1.087 1.184 1.473-1.354-1.088-1.183a3 3 0 0 0-4.8.52L7.136 18.51l1.728 1.007zm6.512-12.969a2.994 2.994 0 0 1 3.285.77l1.088 1.183-1.473 1.354-1.087-1.184A1 1 0 0 0 16 8.457V8c0-.571-.24-1.087-.624-1.451z"></path>
|
<path d="M2 8v10h12V8H2zm2-2V2a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2v4a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h2zm2 0h8a2 2 0 0 1 2 2v4h2V2H6v4zm0 9a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm0-2a1 1 0 1 0 0-2 1 1 0 0 0 0 2z"></path><path d="M7 6a3 3 0 1 1 6 0h-2a1 1 0 0 0-2 0H7zm1.864 13.518l2.725-4.672a1 1 0 0 1 1.6-.174l1.087 1.184 1.473-1.354-1.088-1.183a3 3 0 0 0-4.8.52L7.136 18.51l1.728 1.007zm6.512-12.969a2.994 2.994 0 0 1 3.285.77l1.088 1.183-1.473 1.354-1.087-1.184A1 1 0 0 0 16 8.457V8c0-.571-.24-1.087-.624-1.451z"></path>
|
||||||
</svg>
|
</svg>
|
||||||
|
@ -52,6 +52,11 @@
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<main>
|
<main>
|
||||||
|
<header>
|
||||||
|
{% block header %}{% endblock %}
|
||||||
|
<span></span>
|
||||||
|
</header>
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<i class="ph-arrow-circle-up" id="topButton"></i>
|
<i class="ph-arrow-circle-up" id="topButton"></i>
|
22
gallery/templates/profile.html
Normal file
22
gallery/templates/profile.html
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{% extends 'layout.html' %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="app">
|
||||||
|
<h1>User</h1>
|
||||||
|
<p>{{user_id}}</p>
|
||||||
|
<ul>
|
||||||
|
{% if g.user %}
|
||||||
|
<li><span>{{ g.user['username'] }}</span>
|
||||||
|
<li><a href="{{ url_for('auth.logout') }}">Log Out</a>
|
||||||
|
{% else %}
|
||||||
|
<li><a href="{{ url_for('auth.register') }}">Register</a>
|
||||||
|
<li><a href="{{ url_for('auth.login') }}">Log In</a>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
11
gallery/templates/settings.html
Normal file
11
gallery/templates/settings.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{% extends 'layout.html' %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="app">
|
||||||
|
<h1>Settings</h1>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -1,9 +1,10 @@
|
||||||
{% extends 'layout.html' %}
|
{% extends 'layout.html' %}
|
||||||
|
|
||||||
|
{% block header %}
|
||||||
|
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<header>
|
|
||||||
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
|
||||||
<span></span>
|
|
||||||
</header>
|
|
||||||
<div class="app">
|
<div class="app">
|
||||||
<h1>Upload!!!!!</h1>
|
<h1>Upload!!!!!</h1>
|
||||||
<div id="upload" class="upload">
|
<div id="upload" class="upload">
|
0
setup.py
Normal file
0
setup.py
Normal file
|
@ -1,11 +0,0 @@
|
||||||
{% extends 'layout.html' %}
|
|
||||||
{% block content %}
|
|
||||||
<header>
|
|
||||||
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
|
||||||
<span></span>
|
|
||||||
</header>
|
|
||||||
<div class="app err-warning">
|
|
||||||
<h1>{{error}}</h1>
|
|
||||||
<p>{{msg}}</p>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
|
@ -1,11 +0,0 @@
|
||||||
{% extends 'layout.html' %}
|
|
||||||
{% block content %}
|
|
||||||
<header>
|
|
||||||
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
|
||||||
<span></span>
|
|
||||||
</header>
|
|
||||||
<div class="app">
|
|
||||||
<h1>Image Group</h1>
|
|
||||||
<p>{{group_id}}</p>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
|
@ -1,11 +0,0 @@
|
||||||
{% extends 'layout.html' %}
|
|
||||||
{% block content %}
|
|
||||||
<header>
|
|
||||||
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
|
||||||
<span></span>
|
|
||||||
</header>
|
|
||||||
<div class="app">
|
|
||||||
<h1>User</h1>
|
|
||||||
<p>{{user_id}}</p>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
|
@ -1,10 +0,0 @@
|
||||||
{% extends 'layout.html' %}
|
|
||||||
{% block content %}
|
|
||||||
<header>
|
|
||||||
<img src="{{ url_for('static', filename='images/leaves.jpg') }}" alt="leaves" onload="imgFade(this)" style="display: none;"/>
|
|
||||||
<span></span>
|
|
||||||
</header>
|
|
||||||
<div class="app">
|
|
||||||
<h1>Settings</h1>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
Loading…
Add table
Add a link
Reference in a new issue