user login part 2

This commit is contained in:
crunk 2024-03-30 12:00:47 +01:00
parent c18f7735f5
commit 6010b76309
9 changed files with 47 additions and 8 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ library/data/*.csv
library/data/*.seg
library/data/MAIN_WRITELOCK
library/files/*.pdf
settings_development.toml

View File

@ -80,6 +80,8 @@ def index_books(filename: str, image_folder: str):
def settings_from_file():
settings = {}
if os.path.isfile("settings_development.toml"):
with open("settings_development.toml", "rb") as settings_file:
return tomllib.load(settings_file)
with open("settings.toml", "rb") as settings_file:
settings = tomllib.load(settings_file)
return settings
return tomllib.load(settings_file)

View File

@ -11,7 +11,7 @@ from sqlalchemy.exc import (
InterfaceError,
InvalidRequestError,
)
from usermodel import User
from application.models.usermodel import User
def ForgotPassword(mail):

View File

@ -2,7 +2,7 @@ from flask import abort, flash, redirect, render_template, request, url_for
from flask_bcrypt import check_password_hash
from flask_login import login_user
from forms.loginform import LoginForm
from usermodel import User
from application.models.usermodel import User
def LoginUser():
@ -26,4 +26,4 @@ def LoginUser():
return render_template("login.html", loginform=loginform)
except Exception as e:
flash(e, "danger")
return render_template("login.html", loginform=loginform)
return render_template("user/login.html", loginform=loginform)

View File

@ -10,7 +10,7 @@ from sqlalchemy.exc import (
InterfaceError,
InvalidRequestError,
)
from usermodel import User
from application.models.usermodel import User
from werkzeug.routing import BuildError
@ -62,4 +62,4 @@ def RegisterUser():
db.session.rollback()
registerform.email.errors.append("Unknown error occured!")
flash("An error occured !", "danger")
return render_template("register.html", registerform=registerform)
return render_template("user/register.html", registerform=registerform)

View File

@ -12,7 +12,7 @@ from sqlalchemy.exc import (
InterfaceError,
InvalidRequestError,
)
from usermodel import User
from application.models.usermodel import User
from werkzeug.routing import BuildError

View File

@ -9,6 +9,11 @@ import os
import bcrypt
from app import create_app, login_manager
from application.csvparser import CsvParser
from application.user.loginuser import LoginUser
from application.user.registeruser import RegisterUser
from application.user.forgotpassword import ForgotPassword
from application.user.resetpassword import ResetPassword
from flask import Blueprint, redirect, render_template, request, session
from flask_wtf.csrf import CSRFProtect, CSRFError
from flask_login import (
@ -24,6 +29,8 @@ from requests import get
from search import search
from werkzeug.utils import secure_filename
APP = create_app()
csrf = CSRFProtect()
csrf.init_app(APP)

View File

@ -179,3 +179,12 @@ a:active { text-decoration: none; }
margin: 3em 1em 1em 1em;
}
}
div#auth_buttons{
position: fixed;
top: 0.5em;
right: 0.5em;
display:flex;
flex-direction: row;
justify-content: center;
align-items: center;
}

View File

@ -4,6 +4,26 @@
<nav id="nav" class="container">
{% include 'menu.html' %}
</nav>
<div id="auth_buttons">
{% if not current_user.is_authenticated %}
<div class="signin">
<a href="/login">
<input type="button" name="button" value="Sign in"></input>
</a>
</div>
<div class="signin">
<a href="/register">
<input type="button" name="button" value="Register"></input>
</a>
</div>
{% else %}
<div class="logout">
<a href="/logout">
<input type="button" name="button" value="Logout"></input>
</a>
</div>
{% endif %}
</div>
<div id="bookshelf">
{% for id, pubinfo in publications.items() %}
<div id="{{ id }}" class='book filter {{ pubinfo["Type"] }} {{ pubinfo["Year"] }} {{ pubinfo["License"] }}'>