Skip to content

Commit

Permalink
v0.1.7 fix.2
Browse files Browse the repository at this point in the history
Merge pull request #16 from adk23333/dev
  • Loading branch information
adk23333 authored Apr 12, 2024
2 parents 2190be8 + 38750ad commit 3cb92e6
Show file tree
Hide file tree
Showing 14 changed files with 273 additions and 146 deletions.
17 changes: 9 additions & 8 deletions tieba-admin-server/core/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ async def first_login_api(rqt: Request):
@protected()
@scoped(Permission.ordinary(), False)
async def change_password(rqt: Request, user: User):
"""用于修改自己密码的接口
"""
if not rqt.form.get("password"):
return json("参数错误", status_code=400)
raise ArgException

try:
validate_password(rqt.form.get("password"))
user.password = rqt.app.shared_ctx.password_hasher.hash(rqt.form.get('password'))
await user.save()
return json("修改密码成功")
except ArgException as e:
return json(e.message, status_code=e.status_code)
validate_password(rqt.form.get("password"))
user.password = rqt.app.shared_ctx.password_hasher.hash(rqt.form.get('password'))
await user.save()
return json("修改密码成功")
14 changes: 2 additions & 12 deletions tieba-admin-server/core/exception.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
from typing import Optional

from sanic import SanicException, response
from sanic import SanicException


class ArgException(SanicException):
status_code = 400
message = "参数错误"

def __init__(self, message: str = "参数错误"):
self.message = message


def err_rps(e: Optional[SanicException] = None):
"""
快速返回发生错误时的response
Args:
e: 发生的错误
"""
return response.json({"status": e.status_code, "msg": e.message}, e.status_code)
3 changes: 2 additions & 1 deletion tieba-admin-server/core/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from sanic.log import LOGGING_CONFIG_DEFAULTS
from sanic_jwt import protected, scoped

from core.exception import ArgException
from core.models import Permission, ExecuteLog
from core.utils import json

Expand Down Expand Up @@ -58,7 +59,7 @@ async def get_log(rqt: Request):
if pn < 1:
pn = 1
except (TypeError, ValueError):
return json("参数错误")
raise ArgException
offset = (pn - 1) * limit
logs = await ExecuteLog.all().offset(offset).limit(limit)
return json(data={"items": [await log.to_dict() for log in logs], "total": await ExecuteLog.all().count()})
4 changes: 2 additions & 2 deletions tieba-admin-server/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ async def get(self, rqt: Request):
@scoped(Permission.super(), False)
async def post(self, rqt: Request, user: User):
if not rqt.form.get("user") or not rqt.form.get("forum") or not rqt.form.get("pm"):
return json("参数错误")
raise ArgException
if rqt.form.get("pm") not in [i.value for i in Permission]:
return json("参数错误")
raise ArgException

try:
async with aiotieba.Client() as client:
Expand Down
18 changes: 13 additions & 5 deletions tieba-admin-server/plugins/review/checker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import re
from enum import Enum
from typing import Union, Callable, Coroutine, Dict, Any, Literal, List

Expand Down Expand Up @@ -139,7 +138,7 @@ async def check_keyword(t: Union[Thread, Post, Comment], client: Client):
if t.user.level in Level.LOW.value:
keywords = await Keyword.all()
for kw in keywords:
if re.search(kw.keyword, t.text):
if t.text.find(kw.keyword) != -1:
return delete(client, t)
return empty()

Expand All @@ -152,8 +151,17 @@ async def check_black(t: Union[Thread, Post, Comment], client: Client):
return empty()


@manager.thread()
async def ban_low_user(thread: Thread, client: Client):
if thread.user.level == 1:
def _level_wall(level: int, thread: Thread, client: Client):
if thread.user.level == level:
return delete(client, thread)
return empty()


@manager.thread()
async def level_wall_1(thread: Thread, client: Client):
return _level_wall(1, thread, client)


@manager.thread()
async def level_wall_3(thread: Thread, client: Client):
return _level_wall(3, thread, client)
13 changes: 13 additions & 0 deletions tieba-admin-server/plugins/review/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ def exec_compare(self, exec2):
elif exec2.option == self.option and exec2.opt_day > self.opt_day:
self.opt_day = exec2.opt_day

def __str__(self):
return str(self.__dict__)

@property
def __dict__(self):
return {
"obj": self.obj.__dict__,
"user_opt": self.user_opt.name,
"option": self.option.name,
"user_day": self.user_day,
"opt_day": self.opt_day
}


def empty():
"""
Expand Down
Loading

0 comments on commit 3cb92e6

Please sign in to comment.