mdbq 4.0.104__py3-none-any.whl → 4.0.105__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mdbq might be problematic. Click here for more details.
- mdbq/__version__.py +1 -1
- mdbq/auth/auth_backend.py +27 -39
- {mdbq-4.0.104.dist-info → mdbq-4.0.105.dist-info}/METADATA +1 -1
- {mdbq-4.0.104.dist-info → mdbq-4.0.105.dist-info}/RECORD +6 -6
- {mdbq-4.0.104.dist-info → mdbq-4.0.105.dist-info}/WHEEL +0 -0
- {mdbq-4.0.104.dist-info → mdbq-4.0.105.dist-info}/top_level.txt +0 -0
mdbq/__version__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = '4.0.
|
|
1
|
+
VERSION = '4.0.105'
|
mdbq/auth/auth_backend.py
CHANGED
|
@@ -516,13 +516,7 @@ class StandaloneAuthManager:
|
|
|
516
516
|
|
|
517
517
|
# 检查账户锁定状态
|
|
518
518
|
current_time = datetime.now()
|
|
519
|
-
if locked_until:
|
|
520
|
-
if locked_until.tzinfo is None:
|
|
521
|
-
locked_until = locked_until.replace(tzinfo=timezone.utc)
|
|
522
|
-
elif locked_until.tzinfo != timezone.utc:
|
|
523
|
-
locked_until = locked_until.astimezone(timezone.utc)
|
|
524
|
-
|
|
525
|
-
if locked_until > current_time:
|
|
519
|
+
if locked_until and locked_until > current_time:
|
|
526
520
|
remaining_seconds = int((locked_until - current_time).total_seconds())
|
|
527
521
|
self._log_login_attempt(username_or_email, ip_address, user_agent, 'failure', 'account_locked', user_id)
|
|
528
522
|
self._record_ip_failure(ip_address, 'login')
|
|
@@ -849,7 +843,7 @@ class StandaloneAuthManager:
|
|
|
849
843
|
cursor = conn.cursor()
|
|
850
844
|
|
|
851
845
|
try:
|
|
852
|
-
|
|
846
|
+
current_time = datetime.now()
|
|
853
847
|
|
|
854
848
|
# 先查询要登出的设备数量
|
|
855
849
|
cursor.execute('''
|
|
@@ -864,7 +858,7 @@ class StandaloneAuthManager:
|
|
|
864
858
|
UPDATE refresh_tokens
|
|
865
859
|
SET is_revoked = 1, revoked_at = %s, revoked_reason = 'logout'
|
|
866
860
|
WHERE user_id = %s AND is_revoked = 0
|
|
867
|
-
''', (
|
|
861
|
+
''', (current_time, user_id))
|
|
868
862
|
|
|
869
863
|
# 停用用户的所有设备会话
|
|
870
864
|
cursor.execute('''
|
|
@@ -919,7 +913,7 @@ class StandaloneAuthManager:
|
|
|
919
913
|
new_salt = secrets.token_hex(32)
|
|
920
914
|
new_password_hash = self._hash_password(new_password, new_salt)
|
|
921
915
|
|
|
922
|
-
|
|
916
|
+
current_time = datetime.now()
|
|
923
917
|
|
|
924
918
|
# 更新密码
|
|
925
919
|
cursor.execute('''
|
|
@@ -934,7 +928,7 @@ class StandaloneAuthManager:
|
|
|
934
928
|
UPDATE refresh_tokens
|
|
935
929
|
SET is_revoked = 1, revoked_at = %s, revoked_reason = 'password_changed'
|
|
936
930
|
WHERE user_id = %s AND is_revoked = 0
|
|
937
|
-
''', (
|
|
931
|
+
''', (current_time, user_id))
|
|
938
932
|
|
|
939
933
|
# 停用所有设备会话
|
|
940
934
|
cursor.execute('''
|
|
@@ -1055,7 +1049,7 @@ class StandaloneAuthManager:
|
|
|
1055
1049
|
if len(new_password) < 6:
|
|
1056
1050
|
return {'success': False, 'message': '新密码至少需要6个字符'}
|
|
1057
1051
|
|
|
1058
|
-
|
|
1052
|
+
current_time = datetime.now()
|
|
1059
1053
|
|
|
1060
1054
|
# 查找有效的重置令牌
|
|
1061
1055
|
cursor.execute('''
|
|
@@ -1064,7 +1058,7 @@ class StandaloneAuthManager:
|
|
|
1064
1058
|
WHERE password_reset_token = %s
|
|
1065
1059
|
AND password_reset_expires > %s
|
|
1066
1060
|
AND is_active = 1
|
|
1067
|
-
''', (reset_token,
|
|
1061
|
+
''', (reset_token, current_time))
|
|
1068
1062
|
|
|
1069
1063
|
user = cursor.fetchone()
|
|
1070
1064
|
if not user:
|
|
@@ -1088,7 +1082,7 @@ class StandaloneAuthManager:
|
|
|
1088
1082
|
UPDATE refresh_tokens
|
|
1089
1083
|
SET is_revoked = 1, revoked_at = %s, revoked_reason = 'password_reset'
|
|
1090
1084
|
WHERE user_id = %s AND is_revoked = 0
|
|
1091
|
-
''', (
|
|
1085
|
+
''', (current_time, user['id']))
|
|
1092
1086
|
|
|
1093
1087
|
# 停用所有设备会话
|
|
1094
1088
|
cursor.execute('''
|
|
@@ -1133,16 +1127,10 @@ class StandaloneAuthManager:
|
|
|
1133
1127
|
|
|
1134
1128
|
locked_until = record['locked_until']
|
|
1135
1129
|
|
|
1136
|
-
|
|
1137
|
-
if locked_until:
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
elif locked_until.tzinfo != timezone.utc:
|
|
1141
|
-
locked_until = locked_until.astimezone(timezone.utc)
|
|
1142
|
-
|
|
1143
|
-
if locked_until > current_time_utc:
|
|
1144
|
-
remaining_seconds = int((locked_until - current_time_utc).total_seconds())
|
|
1145
|
-
return {
|
|
1130
|
+
current_time = datetime.now()
|
|
1131
|
+
if locked_until and locked_until > current_time:
|
|
1132
|
+
remaining_seconds = int((locked_until - current_time).total_seconds())
|
|
1133
|
+
return {
|
|
1146
1134
|
'blocked': True,
|
|
1147
1135
|
'remaining_time': remaining_seconds,
|
|
1148
1136
|
'reason': f'IP被锁定,剩余时间: {remaining_seconds}秒'
|
|
@@ -1163,7 +1151,7 @@ class StandaloneAuthManager:
|
|
|
1163
1151
|
cursor = conn.cursor()
|
|
1164
1152
|
|
|
1165
1153
|
try:
|
|
1166
|
-
now = datetime.now(
|
|
1154
|
+
now = datetime.now()
|
|
1167
1155
|
|
|
1168
1156
|
cursor.execute('''
|
|
1169
1157
|
SELECT failure_count, first_failure, lockout_count
|
|
@@ -1179,7 +1167,7 @@ class StandaloneAuthManager:
|
|
|
1179
1167
|
window_start = now - timedelta(minutes=window_minutes)
|
|
1180
1168
|
first_failure = record['first_failure']
|
|
1181
1169
|
|
|
1182
|
-
if first_failure and first_failure
|
|
1170
|
+
if first_failure and first_failure <= window_start:
|
|
1183
1171
|
# 重置计数器
|
|
1184
1172
|
cursor.execute('''
|
|
1185
1173
|
UPDATE ip_rate_limits
|
|
@@ -1225,14 +1213,14 @@ class StandaloneAuthManager:
|
|
|
1225
1213
|
|
|
1226
1214
|
def _revoke_device_session(self, cursor, device_session_id, reason='manual'):
|
|
1227
1215
|
"""撤销设备会话"""
|
|
1228
|
-
|
|
1216
|
+
current_time = datetime.now()
|
|
1229
1217
|
|
|
1230
1218
|
# 撤销设备相关的refresh token
|
|
1231
1219
|
cursor.execute('''
|
|
1232
1220
|
UPDATE refresh_tokens
|
|
1233
1221
|
SET is_revoked = 1, revoked_at = %s, revoked_reason = %s
|
|
1234
1222
|
WHERE device_session_id = %s AND is_revoked = 0
|
|
1235
|
-
''', (
|
|
1223
|
+
''', (current_time, reason, device_session_id))
|
|
1236
1224
|
|
|
1237
1225
|
# 停用设备会话
|
|
1238
1226
|
cursor.execute('''
|
|
@@ -1446,7 +1434,7 @@ class StandaloneAuthManager:
|
|
|
1446
1434
|
cursor = conn.cursor()
|
|
1447
1435
|
|
|
1448
1436
|
try:
|
|
1449
|
-
|
|
1437
|
+
current_time = datetime.now()
|
|
1450
1438
|
|
|
1451
1439
|
if device_id:
|
|
1452
1440
|
# 方式1:通过device_id查找设备(用于设备管理界面)
|
|
@@ -1504,7 +1492,7 @@ class StandaloneAuthManager:
|
|
|
1504
1492
|
UPDATE refresh_tokens
|
|
1505
1493
|
SET is_revoked = 1, revoked_at = %s, revoked_reason = %s
|
|
1506
1494
|
WHERE device_session_id = %s AND is_revoked = 0
|
|
1507
|
-
''', (
|
|
1495
|
+
''', (current_time, logout_reason, device_session_id))
|
|
1508
1496
|
|
|
1509
1497
|
# 停用设备会话
|
|
1510
1498
|
cursor.execute('''
|
|
@@ -1537,7 +1525,7 @@ class StandaloneAuthManager:
|
|
|
1537
1525
|
cursor = conn.cursor()
|
|
1538
1526
|
|
|
1539
1527
|
try:
|
|
1540
|
-
|
|
1528
|
+
current_time = datetime.now()
|
|
1541
1529
|
|
|
1542
1530
|
if access_token:
|
|
1543
1531
|
# 方式1:通过access_token解析出设备会话信息
|
|
@@ -1586,7 +1574,7 @@ class StandaloneAuthManager:
|
|
|
1586
1574
|
UPDATE refresh_tokens
|
|
1587
1575
|
SET is_revoked = 1, revoked_at = %s, revoked_reason = 'current_device_logout'
|
|
1588
1576
|
WHERE device_session_id = %s AND is_revoked = 0
|
|
1589
|
-
''', (
|
|
1577
|
+
''', (current_time, device_session_id))
|
|
1590
1578
|
|
|
1591
1579
|
# 停用设备会话
|
|
1592
1580
|
cursor.execute('''
|
|
@@ -1618,7 +1606,7 @@ class StandaloneAuthManager:
|
|
|
1618
1606
|
cursor = conn.cursor()
|
|
1619
1607
|
|
|
1620
1608
|
try:
|
|
1621
|
-
|
|
1609
|
+
current_time = datetime.now()
|
|
1622
1610
|
|
|
1623
1611
|
# 通过device_id查找设备,确保属于该用户
|
|
1624
1612
|
cursor.execute('''
|
|
@@ -1639,7 +1627,7 @@ class StandaloneAuthManager:
|
|
|
1639
1627
|
UPDATE refresh_tokens
|
|
1640
1628
|
SET is_revoked = 1, revoked_at = %s, revoked_reason = 'specific_device_logout'
|
|
1641
1629
|
WHERE device_session_id = %s AND is_revoked = 0
|
|
1642
|
-
''', (
|
|
1630
|
+
''', (current_time, device_session_id))
|
|
1643
1631
|
|
|
1644
1632
|
# 停用设备会话
|
|
1645
1633
|
cursor.execute('''
|
|
@@ -1735,8 +1723,8 @@ class StandaloneAuthManager:
|
|
|
1735
1723
|
cursor = conn.cursor()
|
|
1736
1724
|
|
|
1737
1725
|
try:
|
|
1738
|
-
|
|
1739
|
-
threshold_time =
|
|
1726
|
+
current_time = datetime.now()
|
|
1727
|
+
threshold_time = current_time - timedelta(days=days_threshold)
|
|
1740
1728
|
|
|
1741
1729
|
# 查找不活跃的设备
|
|
1742
1730
|
cursor.execute('''
|
|
@@ -1757,7 +1745,7 @@ class StandaloneAuthManager:
|
|
|
1757
1745
|
WHERE device_session_id IN ({})
|
|
1758
1746
|
AND is_revoked = 0
|
|
1759
1747
|
'''.format(','.join(['%s'] * len(device_session_ids))),
|
|
1760
|
-
[
|
|
1748
|
+
[current_time] + device_session_ids)
|
|
1761
1749
|
|
|
1762
1750
|
# 停用设备会话
|
|
1763
1751
|
cursor.execute('''
|
|
@@ -1891,8 +1879,8 @@ class StandaloneAuthManager:
|
|
|
1891
1879
|
cursor = conn.cursor()
|
|
1892
1880
|
|
|
1893
1881
|
try:
|
|
1894
|
-
|
|
1895
|
-
threshold_time =
|
|
1882
|
+
current_time = datetime.now()
|
|
1883
|
+
threshold_time = current_time - timedelta(days=days_threshold)
|
|
1896
1884
|
|
|
1897
1885
|
if user_id:
|
|
1898
1886
|
# 清理特定用户的旧记录
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
mdbq/__init__.py,sha256=Il5Q9ATdX8yXqVxtP_nYqUhExzxPC_qk_WXQ_4h0exg,16
|
|
2
|
-
mdbq/__version__.py,sha256=
|
|
2
|
+
mdbq/__version__.py,sha256=D8LsxsVI3wBXABgysGteyLWTKv98AvjXhp7NcQYnB98,19
|
|
3
3
|
mdbq/auth/__init__.py,sha256=pnPMAt63sh1B6kEvmutUuro46zVf2v2YDAG7q-jV_To,24
|
|
4
|
-
mdbq/auth/auth_backend.py,sha256=
|
|
4
|
+
mdbq/auth/auth_backend.py,sha256=ZxKRXPXa2t9ngRZEXKM72MzcMvN-0OtiVDOhZRTrm3w,85948
|
|
5
5
|
mdbq/auth/rate_limiter.py,sha256=1m_Paxp8pDNpmyoFGRpFMVOJpbmeIvfVcfiQ2oH72qM,32850
|
|
6
6
|
mdbq/js/__init__.py,sha256=hpMi3_ZKwIWkzc0LnKL-SY9AS-7PYFHq0izYTgEvxjc,30
|
|
7
7
|
mdbq/js/jc.py,sha256=FOc6HOOTJwnoZLZmgmaE1SQo9rUnVhXmefhKMD2MlDA,13229
|
|
@@ -33,7 +33,7 @@ mdbq/route/routes.py,sha256=QVGfTvDgu0CpcKCvk1ra74H8uojgqTLUav1fnVAqLEA,29433
|
|
|
33
33
|
mdbq/selenium/__init__.py,sha256=AKzeEceqZyvqn2dEDoJSzDQnbuENkJSHAlbHAD0u0ZI,10
|
|
34
34
|
mdbq/selenium/get_driver.py,sha256=1NTlVUE6QsyjTrVVVqTO2LOnYf578ccFWlWnvIXGtic,20903
|
|
35
35
|
mdbq/spider/__init__.py,sha256=RBMFXGy_jd1HXZhngB2T2XTvJqki8P_Fr-pBcwijnew,18
|
|
36
|
-
mdbq-4.0.
|
|
37
|
-
mdbq-4.0.
|
|
38
|
-
mdbq-4.0.
|
|
39
|
-
mdbq-4.0.
|
|
36
|
+
mdbq-4.0.105.dist-info/METADATA,sha256=xvRe6sntR1Gvef1GsuiDUohdy5CHz8XsP4OogQVsBc4,365
|
|
37
|
+
mdbq-4.0.105.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
38
|
+
mdbq-4.0.105.dist-info/top_level.txt,sha256=2FQ-uLnCSB-OwFiWntzmwosW3X2Xqsg0ewh1axsaylA,5
|
|
39
|
+
mdbq-4.0.105.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|