Browse Source

user login part 2

main
crunk 1 month ago
parent
commit
6010b76309
  1. 1
      .gitignore
  2. 6
      library/app.py
  3. 2
      library/application/user/forgotpassword.py
  4. 4
      library/application/user/loginuser.py
  5. 4
      library/application/user/registeruser.py
  6. 2
      library/application/user/resetpassword.py
  7. 7
      library/page.py
  8. 9
      library/static/css/style.css
  9. 20
      library/templates/index.html

1
.gitignore

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

6
library/app.py

@ -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)

2
library/application/user/forgotpassword.py

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

4
library/application/user/loginuser.py

@ -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)

4
library/application/user/registeruser.py

@ -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)

2
library/application/user/resetpassword.py

@ -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

7
library/page.py

@ -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)

9
library/static/css/style.css

@ -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;
}

20
library/templates/index.html

@ -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"] }}'>

Loading…
Cancel
Save