From 554a80d7f78a20a1825fd6c540a2557220ea9f46 Mon Sep 17 00:00:00 2001 From: ytqh Date: Sun, 27 Apr 2025 10:23:34 +0800 Subject: [PATCH] feat: add DEBUG_ADMIN_PHONE configuration for demo features --- api/configs/school/__init__.py | 5 +++++ api/controllers/admin/auth/login.py | 11 +++++++---- docker/.env.example | 3 ++- docker/docker-compose.yaml | 1 + 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/api/configs/school/__init__.py b/api/configs/school/__init__.py index e80fd72fa9..1490d3919d 100644 --- a/api/configs/school/__init__.py +++ b/api/configs/school/__init__.py @@ -48,3 +48,8 @@ class SchoolConfig(BaseSettings): description="App id for image generation.", default=None, ) + + DEBUG_ADMIN_PHONE: Optional[str] = Field( + description="Debug admin phone for DEMO school-level features.", + default=None, + ) diff --git a/api/controllers/admin/auth/login.py b/api/controllers/admin/auth/login.py index 54b7a52568..1e8dd855db 100644 --- a/api/controllers/admin/auth/login.py +++ b/api/controllers/admin/auth/login.py @@ -1,10 +1,11 @@ from typing import cast import flask_login # type: ignore +from configs import dify_config from controllers.admin import api from controllers.service_api_with_auth.auth.error import InvalidTokenError from controllers.service_api_with_auth.error import AccountInFreezeError, AccountNotFound -from flask import Blueprint, request +from flask import request from flask_restful import Api, Resource, reqparse # type: ignore from libs.helper import extract_remote_ip from models.account import Account @@ -52,20 +53,22 @@ class SendVerificationCodeApi(Resource): parser.add_argument("phone", type=str, required=True, location="json") args = parser.parse_args() + phone = args["phone"] + ip_address = extract_remote_ip(request) - if AccountService.is_phone_send_ip_limit(ip_address): + if AccountService.is_phone_send_ip_limit(ip_address) and phone != dify_config.DEBUG_ADMIN_PHONE: return {"result": "fail", "data": "Too many requests from this IP address"}, 429 try: # find account by phone number & chech role is end_admin - account = AccountService.get_admin_through_phone(args["phone"]) + account = AccountService.get_admin_through_phone(phone) except AccountRegisterError: raise AccountInFreezeError() if account is None: return {"result": "fail", "data": "Phone number not registered as admin"}, 404 - token = AccountService.send_phone_code_login(phone=args["phone"]) + token = AccountService.send_phone_code_login(phone=phone) return {"result": "success", "data": token} diff --git a/docker/.env.example b/docker/.env.example index 65d79a17b8..e9b5c9fae3 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -962,4 +962,5 @@ ALIYUN_TEMPLATE_CODE= # Image Generation IMAGE_GENERATION_DAILY_LIMIT=5 IMAGE_GENERATION_MIN_CONVERSATION_ROUNDS=10 -IMAGE_GENERATION_APP_ID= \ No newline at end of file +IMAGE_GENERATION_APP_ID= +DEBUG_ADMIN_PHONE= \ No newline at end of file diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 6ec68fa9aa..62fa556606 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -409,6 +409,7 @@ x-shared-env: &shared-api-worker-env IMAGE_GENERATION_DAILY_LIMIT: ${IMAGE_GENERATION_DAILY_LIMIT:-5} IMAGE_GENERATION_MIN_CONVERSATION_ROUNDS: ${IMAGE_GENERATION_MIN_CONVERSATION_ROUNDS:-10} IMAGE_GENERATION_APP_ID: ${IMAGE_GENERATION_APP_ID:-} + DEBUG_ADMIN_PHONE: ${DEBUG_ADMIN_PHONE:-} services: # API service