diff --git a/gallery/__init__.py b/gallery/__init__.py
index 99d6b5b..80f403b 100644
--- a/gallery/__init__.py
+++ b/gallery/__init__.py
@@ -54,7 +54,7 @@ def create_app(test_config=None):
# App configuration
app.config.from_mapping(
SECRET_KEY=os.environ.get('FLASK_SECRET'),
- DATABASE=os.path.join(app.instance_path, 'gallery.sqlite'),
+ DATABASE=os.path.join(app.instance_path, 'gallery.sqlite3'),
UPLOAD_FOLDER=os.path.join(USER_DIR, 'uploads'),
ALLOWED_EXTENSIONS=conf['upload']['allowed-extensions'],
MAX_CONTENT_LENGTH=1024 * 1024 * conf['upload']['max-size'],
diff --git a/gallery/auth.py b/gallery/auth.py
index 6872c7e..dd11190 100644
--- a/gallery/auth.py
+++ b/gallery/auth.py
@@ -3,9 +3,7 @@ OnlyLegs - Authentication
User registration, login and logout and locking access to pages behind a login
"""
import re
-from uuid import uuid4
import logging
-from datetime import datetime as dt
from flask import Blueprint, flash, redirect, request, url_for, abort, jsonify
from werkzeug.security import check_password_hash, generate_password_hash
@@ -34,7 +32,7 @@ def login():
user = db_session.query(db.Users).filter_by(username=username).first()
- if not user and not check_password_hash(user.password, password):
+ if not user or not check_password_hash(user.password, password):
logging.error('Login attempt from %s', request.remote_addr)
error.append('Username or Password is incorrect!')
@@ -45,7 +43,7 @@ def login():
logging.info('User %s logged in from %s', username, request.remote_addr)
flash(['Logged in successfully!', '4'])
- return 'gwa gwa'
+ return 'ok', 200
@blueprint.route('/register', methods=['POST'])
@@ -87,16 +85,16 @@ def register():
# If there are errors, return them
if error:
- return jsonify(error)
+ print(error)
+ return jsonify(error), 400
- register_user = db.Users(alt_id=str(uuid4()), username=username, email=email,
- password=generate_password_hash(password, method='sha256'),
- created_at=dt.utcnow())
+ register_user = db.Users(username=username, email=email,
+ password=generate_password_hash(password, method='sha256'))
db_session.add(register_user)
db_session.commit()
logging.info('User %s registered', username)
- return 'gwa gwa'
+ return 'ok', 200
@blueprint.route('/logout')
@@ -106,4 +104,5 @@ def logout():
Clear the current session, including the stored user id
"""
logout_user()
+ flash(['Goodbye!!!', '4'])
return redirect(url_for('gallery.index'))
diff --git a/gallery/db.py b/gallery/db.py
index a41db1b..a302855 100644
--- a/gallery/db.py
+++ b/gallery/db.py
@@ -1,8 +1,10 @@
"""
OnlyLegs - Database models and functions for SQLAlchemy
"""
+from uuid import uuid4
import os
import platformdirs
+from datetime import datetime as dt
from sqlalchemy import create_engine, Column, Integer, String, DateTime, ForeignKey, PickleType
from sqlalchemy.orm import declarative_base, relationship
@@ -11,7 +13,7 @@ from flask_login import UserMixin
USER_DIR = platformdirs.user_config_dir('onlylegs')
-DB_PATH = os.path.join(USER_DIR, 'gallery.sqlite')
+DB_PATH = os.path.join(USER_DIR, 'instance', 'gallery.sqlite3')
# In the future, I want to add support for other databases
@@ -28,11 +30,12 @@ class Users (base, UserMixin): # pylint: disable=too-few-public-methods, C0103
# Gallery used information
id = Column(Integer, primary_key=True)
- alt_id = Column(String, unique=True, nullable=False)
+ alt_id = Column(String, unique=True, nullable=False, default=str(uuid4()))
+ profile_picture = Column(String, nullable=True, default=None)
username = Column(String, unique=True, nullable=False)
email = Column(String, unique=True, nullable=False)
password = Column(String, nullable=False)
- created_at = Column(DateTime, nullable=False)
+ joined_at = Column(DateTime, nullable=False, default=dt.utcnow())
posts = relationship('Posts', backref='users')
groups = relationship('Groups', backref='users')
@@ -51,20 +54,16 @@ class Posts (base): # pylint: disable=too-few-public-methods, C0103
id = Column(Integer, primary_key=True)
author_id = Column(Integer, ForeignKey('users.id'))
- created_at = Column(DateTime, nullable=False)
-
- file_name = Column(String, unique=True, nullable=False)
- file_type = Column(String, nullable=False)
-
- image_exif = Column(PickleType, nullable=False)
- image_colours = Column(PickleType, nullable=False)
-
- post_description = Column(String, nullable=False)
- post_alt = Column(String, nullable=False)
+ created_at = Column(DateTime, nullable=False, default=dt.utcnow())
+ filename = Column(String, unique=True, nullable=False)
+ mimetype = Column(String, nullable=False)
+ exif = Column(PickleType, nullable=False)
+ colours = Column(PickleType, nullable=False)
+ description = Column(String, nullable=False)
+ alt = Column(String, nullable=False)
junction = relationship('GroupJunction', backref='posts')
-
class Groups (base): # pylint: disable=too-few-public-methods, C0103
"""
Group table
@@ -76,7 +75,7 @@ class Groups (base): # pylint: disable=too-few-public-methods, C0103
name = Column(String, nullable=False)
description = Column(String, nullable=False)
author_id = Column(Integer, ForeignKey('users.id'))
- created_at = Column(DateTime, nullable=False)
+ created_at = Column(DateTime, nullable=False, default=dt.utcnow())
junction = relationship('GroupJunction', backref='groups')
@@ -89,7 +88,7 @@ class GroupJunction (base): # pylint: disable=too-few-public-methods, C0103
__tablename__ = 'group_junction'
id = Column(Integer, primary_key=True)
- date_added = Column(DateTime, nullable=False)
+ date_added = Column(DateTime, nullable=False, default=dt.utcnow())
group_id = Column(Integer, ForeignKey('groups.id'))
post_id = Column(Integer, ForeignKey('posts.id'))
@@ -105,8 +104,8 @@ class Logs (base): # pylint: disable=too-few-public-methods, C0103
user_id = Column(Integer, ForeignKey('users.id'))
ip_address = Column(String, nullable=False)
code = Column(Integer, nullable=False)
- msg = Column(String, nullable=False)
- created_at = Column(DateTime, nullable=False)
+ note = Column(String, nullable=False)
+ created_at = Column(DateTime, nullable=False, default=dt.utcnow())
class Bans (base): # pylint: disable=too-few-public-methods, C0103
@@ -118,8 +117,8 @@ class Bans (base): # pylint: disable=too-few-public-methods, C0103
id = Column(Integer, primary_key=True)
ip_address = Column(String, nullable=False)
code = Column(Integer, nullable=False)
- msg = Column(String, nullable=False)
- created_at = Column(DateTime, nullable=False)
+ note = Column(String, nullable=False)
+ banned_at = Column(DateTime, nullable=False, default=dt.utcnow())
# check if database file exists, if not create it
diff --git a/gallery/templates/groups/group.html b/gallery/templates/groups/group.html
index 845c3f7..21297b7 100644
--- a/gallery/templates/groups/group.html
+++ b/gallery/templates/groups/group.html
@@ -2,7 +2,7 @@
{% block nav_groups %}selected{% endblock %}
{% block head %}
{% if images %}
-
+
{% endif %}