mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
remove last_login
This commit is contained in:
@@ -35,16 +35,9 @@ class Connection:
|
|||||||
|
|
||||||
def get_user(self, addr: str) -> {}:
|
def get_user(self, addr: str) -> {}:
|
||||||
"""Get a row from the users table."""
|
"""Get a row from the users table."""
|
||||||
q = "SELECT addr, password, last_login from users WHERE addr = ?"
|
q = "SELECT addr, password from users WHERE addr = ?"
|
||||||
row = self._sqlconn.execute(q, (addr,)).fetchone()
|
row = self._sqlconn.execute(q, (addr,)).fetchone()
|
||||||
result = {}
|
return dict(user=row[0], password=row[1]) if row else {}
|
||||||
if row:
|
|
||||||
result = dict(
|
|
||||||
user=row[0],
|
|
||||||
password=row[1],
|
|
||||||
last_login=row[2],
|
|
||||||
)
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import json
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from .config import Config, read_config
|
from .config import Config, read_config
|
||||||
@@ -82,7 +81,7 @@ def lookup_userdb(db, config: Config, user):
|
|||||||
return get_user_data(db, config, user)
|
return get_user_data(db, config, user)
|
||||||
|
|
||||||
|
|
||||||
def lookup_passdb(db, config: Config, user, cleartext_password, last_login=None):
|
def lookup_passdb(db, config: Config, user, cleartext_password):
|
||||||
if user == f"echo@{config.mail_domain}":
|
if user == f"echo@{config.mail_domain}":
|
||||||
# Echobot writes password it wants to log in with into /run/echobot/password
|
# Echobot writes password it wants to log in with into /run/echobot/password
|
||||||
try:
|
try:
|
||||||
@@ -98,18 +97,9 @@ def lookup_passdb(db, config: Config, user, cleartext_password, last_login=None)
|
|||||||
password=encrypt_password(password),
|
password=encrypt_password(password),
|
||||||
)
|
)
|
||||||
|
|
||||||
if last_login is None:
|
with db.read_connection() as conn:
|
||||||
last_login = time.time()
|
|
||||||
last_login = int(last_login)
|
|
||||||
|
|
||||||
with db.write_transaction() as conn:
|
|
||||||
userdata = conn.get_user(user)
|
userdata = conn.get_user(user)
|
||||||
if userdata:
|
if userdata:
|
||||||
# Update last login time.
|
|
||||||
conn.execute(
|
|
||||||
"UPDATE users SET last_login=? WHERE addr=?", (last_login, user)
|
|
||||||
)
|
|
||||||
|
|
||||||
userdata["home"] = str(config.get_user_maildir(user))
|
userdata["home"] = str(config.get_user_maildir(user))
|
||||||
userdata["uid"] = "vmail"
|
userdata["uid"] = "vmail"
|
||||||
userdata["gid"] = "vmail"
|
userdata["gid"] = "vmail"
|
||||||
@@ -117,10 +107,10 @@ def lookup_passdb(db, config: Config, user, cleartext_password, last_login=None)
|
|||||||
if not is_allowed_to_create(config, user, cleartext_password):
|
if not is_allowed_to_create(config, user, cleartext_password):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
with db.write_transaction() as conn:
|
||||||
encrypted_password = encrypt_password(cleartext_password)
|
encrypted_password = encrypt_password(cleartext_password)
|
||||||
q = """INSERT INTO users (addr, password, last_login)
|
q = "INSERT INTO users (addr, password) VALUES (?, ?)"
|
||||||
VALUES (?, ?, ?)"""
|
conn.execute(q, (user, encrypted_password))
|
||||||
conn.execute(q, (user, encrypted_password, last_login))
|
|
||||||
print(f"Created address: {user}", file=sys.stderr)
|
print(f"Created address: {user}", file=sys.stderr)
|
||||||
return dict(
|
return dict(
|
||||||
home=str(config.get_user_maildir(user)),
|
home=str(config.get_user_maildir(user)),
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ from chatmaild.doveauth import (
|
|||||||
get_user_data,
|
get_user_data,
|
||||||
is_allowed_to_create,
|
is_allowed_to_create,
|
||||||
iter_userdb,
|
iter_userdb,
|
||||||
iter_userdb_lastlogin_before,
|
|
||||||
lookup_passdb,
|
lookup_passdb,
|
||||||
)
|
)
|
||||||
from chatmaild.newemail import create_newemail_dict
|
from chatmaild.newemail import create_newemail_dict
|
||||||
@@ -38,25 +37,6 @@ def test_iterate_addresses(db, example_config):
|
|||||||
assert res == addresses
|
assert res == addresses
|
||||||
|
|
||||||
|
|
||||||
def test_iterate_addresses_lastlogin_before(db, example_config):
|
|
||||||
addresses = []
|
|
||||||
|
|
||||||
cutoff_date = 1000
|
|
||||||
for i in range(10):
|
|
||||||
addr = f"oldold{i:03}@chat.example.org"
|
|
||||||
lookup_passdb(
|
|
||||||
db, example_config, addr, "q9mr3faue", last_login=cutoff_date - 10
|
|
||||||
)
|
|
||||||
addresses.append(addr)
|
|
||||||
|
|
||||||
for i in range(5):
|
|
||||||
addr = f"newnew{i:03}@chat.example.org"
|
|
||||||
lookup_passdb(db, example_config, addr, "q9mr3faue", last_login=cutoff_date + i)
|
|
||||||
|
|
||||||
res = iter_userdb_lastlogin_before(db, cutoff_date)
|
|
||||||
assert sorted(res) == sorted(addresses)
|
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_username_length(example_config):
|
def test_invalid_username_length(example_config):
|
||||||
config = example_config
|
config = example_config
|
||||||
config.username_min_length = 6
|
config.username_min_length = 6
|
||||||
|
|||||||
Reference in New Issue
Block a user