[Enhance] Some config options & Login limiter

- Add limiter for login and API login
- Add some config options

- Delete `setting.py` files
This commit is contained in:
Lost-MSth
2022-10-16 17:07:32 +08:00
parent ba36190f30
commit d150553e6b
8 changed files with 50 additions and 273 deletions

View File

@@ -2,7 +2,9 @@ from hashlib import sha256
from os import urandom
from time import time
from .error import NoAccess, NoData, UserBan
from .config_manager import Config
from .error import NoAccess, NoData, RateLimit, UserBan
from .limiter import ArcLimiter
from .user import UserOnline
@@ -57,6 +59,8 @@ class Role:
class APIUser(UserOnline):
limiter = ArcLimiter(Config.API_LOGIN_RATE_LIMIT, 'api_login')
def __init__(self, c=None, user_id=None) -> None:
super().__init__(c, user_id)
self.api_token: str = None
@@ -109,6 +113,9 @@ class APIUser(UserOnline):
self.password = password
if ip is not None:
self.ip = ip
if not self.limiter.hit(name):
raise RateLimit('Too many login attempts', api_error_code=-205)
self.c.execute('''select user_id, password from user where name = :a''', {
'a': self.name})
x = self.c.fetchone()