This commit is contained in:
Michał 2023-04-04 14:00:00 +00:00
parent a4d19bf32a
commit 97119ced54
4 changed files with 30 additions and 14 deletions

View file

@ -76,13 +76,30 @@ def create_app(test_config=None):
@login_manager.unauthorized_handler
def unauthorized():
return render_template('error.html', error=401,
msg='You are not authorized to view this page!!!!'), 401
error = 401
msg = 'You are not authorized to view this page!!!!'
return render_template('error.html', error=error, msg=msg), error
# Load JS assets
assets.register('js_pre', Bundle('js/pre/*.js', output='gen/pre_packed.js', depends='js/pre/*.js'))
assets.register('js_post', Bundle('js/post/*.js', output='gen/post_packed.js', depends='js/pre/*.js'))
assets.register('styles', Bundle('sass/*.sass', filters='libsass', output='gen/styles.css', depends='sass/**/*.sass'))
js_pre = Bundle(
'js/pre/*.js',
output='gen/pre_packed.js',
depends='js/pre/*.js'
)
js_post = Bundle(
'js/post/*.js',
output='gen/post_packed.js',
depends='js/post/*.js'
)
styles = Bundle(
'sass/*.sass',
filters='libsass',
output='gen/styles.css',
depends='sass/**/*.sass'
)
assets.register('js_pre', js_pre)
assets.register('js_post', js_post)
assets.register('styles', styles)
# Error handlers, if the error is not a HTTP error, return 500
@app.errorhandler(Exception)

View file

@ -7,7 +7,7 @@ from uuid import uuid4
import logging
from datetime import datetime as dt
from flask import Blueprint, flash, redirect, request, url_for, abort, jsonify, session
from flask import Blueprint, flash, redirect, request, url_for, abort, jsonify
from werkzeug.security import check_password_hash, generate_password_hash
from flask_login import login_user, logout_user, login_required
@ -27,14 +27,14 @@ def login():
Log in a registered user by adding the user id to the session
"""
error = []
username = request.form['username'].strip()
password = request.form['password'].strip()
user = db_session.query(db.Users).filter_by(username=username).first()
if not user and not check_password_hash(user.password, password):
logging.error('Login attempt from %s', username, request.remote_addr)
logging.error('Login attempt from %s', request.remote_addr)
error.append('Username or Password is incorrect!')
if error:
@ -53,7 +53,7 @@ def register():
Register a new user
"""
error = []
# Thanks Fennec for reminding me to strip out the whitespace lol
username = request.form['username'].strip()
email = request.form['email'].strip()
@ -79,7 +79,7 @@ def register():
error.append('Enter password again!')
elif password_repeat != password:
error.append('Passwords do not match!')
user_exists = db_session.query(db.Users).filter_by(username=username).first()
if user_exists:
error.append('User already exists!')

View file

@ -4,8 +4,7 @@ OnlyLegs - Database models and functions for SQLAlchemy
import os
import platformdirs
from sqlalchemy import (
create_engine, Column, Integer, String, Boolean, DateTime, ForeignKey, PickleType)
from sqlalchemy import create_engine, Column, Integer, String, DateTime, ForeignKey, PickleType
from sqlalchemy.orm import declarative_base, relationship
from flask_login import UserMixin

View file

@ -26,7 +26,7 @@ class OnlyLegs(Application):
return cfg
@staticmethod
def prog(self): # pylint: disable=C0116, E0202
def prog(): # pylint: disable=C0116, E0202
return 'OnlyLegs'
def load(self):