diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-11-17 14:51:58 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-11-17 14:51:58 +0100 |
commit | f21f24f442e05fa452adac177cd0ba696e5f2c8f (patch) | |
tree | 1088f823c44931c9c137d7336fcc9f4d77d1f8d2 | |
parent | e7ead98e5aaf294b2c498925bdc3dc9b63fdc980 (diff) |
fix rendering of mails in home folder
moved some logic into .read_mails.login
-rw-r--r-- | src/jwebmail/__init__.py | 2 | ||||
-rw-r--r-- | src/jwebmail/read_mails.py | 23 | ||||
-rw-r--r-- | src/jwebmail/render_mail.py | 6 | ||||
-rw-r--r-- | src/jwebmail/webmail.py | 8 |
4 files changed, 18 insertions, 21 deletions
diff --git a/src/jwebmail/__init__.py b/src/jwebmail/__init__.py index 01cb70b..aecc817 100644 --- a/src/jwebmail/__init__.py +++ b/src/jwebmail/__init__.py @@ -36,7 +36,7 @@ else: toml_read_file = dict(load=toml_load, text=True) -__version__ = "2.6.0.dev3" +__version__ = "2.6.0.dev4" csrf = CSRFProtect() diff --git a/src/jwebmail/read_mails.py b/src/jwebmail/read_mails.py index b173b35..54bd139 100644 --- a/src/jwebmail/read_mails.py +++ b/src/jwebmail/read_mails.py @@ -3,7 +3,7 @@ from contextlib import closing from os.path import join as path_join from flask import current_app, g -from flask_login import UserMixin, current_user +from flask_login import UserMixin, current_user, login_user from .model.read_mails import QMailAuthuser @@ -115,7 +115,7 @@ class SqliteTimeoutSession: self.conn.close() -def select_timeout_session(): +def _select_timeout_session(): session_type = current_app.config["JWEBMAIL"]["READ_MAILS"]["SESSION_TYPE"] user = "jwebmail" @@ -136,7 +136,7 @@ def select_timeout_session(): raise ValueError(f"unknown session_type {session_type!r}") -def build_qma(username, password): +def _build_qma(username, password): authenticator = current_app.config["JWEBMAIL"]["READ_MAILS"]["AUTHENTICATOR"] backend = current_app.config["JWEBMAIL"]["READ_MAILS"]["BACKEND"] @@ -163,17 +163,18 @@ def build_qma(username, password): def login(username, password): - return build_qma(username, password).verify_user() - - -def add_user(user: JWebmailUser): - r = select_timeout_session() - r.set(user.get_id(), user.password) + if not _build_qma(username, password).verify_user(): + return False + r = _select_timeout_session() + r.set(username, password) r.close() + user = JWebmailUser(username, password) + login_user(user) + return True def load_user(username: str) -> JWebmailUser: - r = select_timeout_session() + r = _select_timeout_session() passwd = r.get(username) r.close() if passwd is None: @@ -185,6 +186,6 @@ def get_read_mails_logged_in(): if "read_mails" in g: return g.read_mails - qma = build_qma(current_user.get_id(), current_user.password) + qma = _build_qma(current_user.get_id(), current_user.password) g.read_mails = qma return qma diff --git a/src/jwebmail/render_mail.py b/src/jwebmail/render_mail.py index eec6e30..c36150d 100644 --- a/src/jwebmail/render_mail.py +++ b/src/jwebmail/render_mail.py @@ -11,7 +11,7 @@ def render_text_html(_subtype, _content, path): if path: url = url_for( "read", - folder=request.view_args["folder"], + folder=request.view_args.get("folder", ""), msgid=request.view_args["msgid"], format="raw", path=".".join(map(str, path)), @@ -19,7 +19,7 @@ def render_text_html(_subtype, _content, path): else: url = url_for( "read", - folder=request.view_args["folder"], + folder=request.view_args.get("folder", ""), msgid=request.view_args["msgid"], format="raw", ) @@ -78,7 +78,7 @@ def render_multipart(_subtype, content, path): ref_url = url_for( "read", - folder=request.view_args["folder"], + folder=request.view_args.get("folder", ""), msgid=request.view_args["msgid"], path=".".join(map(str, [*path, i])), format="raw", diff --git a/src/jwebmail/webmail.py b/src/jwebmail/webmail.py index 7b2e352..1b61daa 100644 --- a/src/jwebmail/webmail.py +++ b/src/jwebmail/webmail.py @@ -13,7 +13,7 @@ from urllib.parse import urlparse from flask import abort, current_app, flash, redirect, render_template, request, url_for from flask_babel import gettext, lazy_gettext -from flask_login import current_user, login_user, logout_user +from flask_login import current_user, logout_user from flask_paginate import Pagination, get_page_parameter, get_per_page_parameter from flask_wtf import FlaskForm from werkzeug.utils import secure_filename @@ -28,7 +28,7 @@ from wtforms import ( ) from .model.read_mails import QMAuthError -from .read_mails import JWebmailUser, add_user, get_read_mails_logged_in +from .read_mails import get_read_mails_logged_in from .read_mails import login as rm_login from .render_mail import to_mime_type @@ -61,10 +61,6 @@ def login(): if form.validate_on_submit(): if rm_login(form.username.data, form.password.data): - user = JWebmailUser(form.username.data, form.password.data) - add_user(user) - login_user(user) - nxt = request.args.get("next") if urlparse(nxt).netloc: |