summaryrefslogtreecommitdiff
path: root/src/jwebmail/read_mails.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/jwebmail/read_mails.py')
-rw-r--r--src/jwebmail/read_mails.py23
1 files changed, 12 insertions, 11 deletions
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