Skip to content

Commit

Permalink
Merge branch 'janeczku:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
holta authored Jul 19, 2024
2 parents b9b057e + e3be759 commit 333b646
Show file tree
Hide file tree
Showing 46 changed files with 2,811 additions and 1,086 deletions.
22 changes: 9 additions & 13 deletions cps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@

def hide_console_windows():
import ctypes
import os

hwnd = ctypes.windll.kernel32.GetConsoleWindow()
if hwnd != 0:
try:
import win32process
except ImportError:
print("To hide console window install 'pywin32' using 'pip install pywin32'")
return
ctypes.windll.user32.ShowWindow(hwnd, 0)
ctypes.windll.kernel32.CloseHandle(hwnd)
_, pid = win32process.GetWindowThreadProcessId(hwnd)
os.system('taskkill /PID ' + str(pid) + ' /f')

kernel32 = ctypes.WinDLL('kernel32')
user32 = ctypes.WinDLL('user32')

SW_HIDE = 0

hWnd = kernel32.GetConsoleWindow()
if hWnd:
user32.ShowWindow(hWnd, SW_HIDE)


if __name__ == '__main__':
Expand Down
25 changes: 6 additions & 19 deletions cps/MyLoginManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import ast
import hashlib

from .cw_login import LoginManager
from flask import session

from flask_login import LoginManager, confirm_login
from flask import session, current_app
from flask_login.utils import decode_cookie
from flask_login.signals import user_loaded_from_cookie


class MyLoginManager(LoginManager):
Expand All @@ -36,18 +36,5 @@ def _session_protection_failed(self):
return super(). _session_protection_failed()
return False

def _load_user_from_remember_cookie(self, cookie):
user_id = decode_cookie(cookie)
if user_id is not None:
session["_user_id"] = user_id
session["_fresh"] = False
user = None
if self._user_callback:
user = self._user_callback(user_id)
if user is not None:
app = current_app._get_current_object()
user_loaded_from_cookie.send(app, user=user)
# if session was restored from remember me cookie make login valid
confirm_login()
return user
return None


4 changes: 2 additions & 2 deletions cps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
app = Flask(__name__)
app.config.update(
SESSION_COOKIE_HTTPONLY=True,
SESSION_COOKIE_SAMESITE='Lax',
REMEMBER_COOKIE_SAMESITE='Lax', # will be available in flask-login 0.5.1 earliest
SESSION_COOKIE_SAMESITE='Strict',
REMEMBER_COOKIE_SAMESITE='Strict', # will be available in flask-login 0.5.1 earliest
WTF_CSRF_SSL_STRICT=False
)

Expand Down
4 changes: 2 additions & 2 deletions cps/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
from collections import OrderedDict

import flask
import flask_login
import jinja2
from flask_babel import gettext as _

from . import db, calibre_db, converter, uploader, constants, dep_check
from .render_template import render_title_template
from .usermanagement import user_login_required


about = flask.Blueprint('about', __name__)
Expand Down Expand Up @@ -74,7 +74,7 @@ def collect_stats():


@about.route("/stats")
@flask_login.login_required
@user_login_required
def stats():
counter = calibre_db.session.query(db.Books).count()
authors = calibre_db.session.query(db.Authors).count()
Expand Down
Loading

0 comments on commit 333b646

Please sign in to comment.