From 4d3761e0e08e40614d057f79891489c83587542f Mon Sep 17 00:00:00 2001 From: vinland100 Date: Mon, 5 Jan 2026 13:47:48 +0800 Subject: [PATCH] feat: Add Gitea username integration, refactor password hashing with direct bcrypt, and remove frontend version displays. --- ...07418d_add_gitea_username_to_user_model.py | 34 ++++++++++++++++ backend/app/core/security.py | 40 ++++++++++++++----- backend/app/models/user.py | 1 + backend/app/schemas/user.py | 1 + backend/app/services/init_templates.py | 18 +++++++-- .../audit/TerminalProgressDialog.tsx | 1 - frontend/src/pages/Account.tsx | 14 +++++++ .../AgentAudit/components/SplashScreen.tsx | 7 +--- frontend/src/shared/types/index.ts | 1 + 9 files changed, 96 insertions(+), 21 deletions(-) create mode 100644 backend/alembic/versions/08a73307418d_add_gitea_username_to_user_model.py diff --git a/backend/alembic/versions/08a73307418d_add_gitea_username_to_user_model.py b/backend/alembic/versions/08a73307418d_add_gitea_username_to_user_model.py new file mode 100644 index 0000000..0453be0 --- /dev/null +++ b/backend/alembic/versions/08a73307418d_add_gitea_username_to_user_model.py @@ -0,0 +1,34 @@ +"""add gitea_username to user model + +Revision ID: 08a73307418d +Revises: ecc7c0ff0957 +Create Date: 2026-01-05 13:36:16.845876 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '08a73307418d' +down_revision = 'ecc7c0ff0957' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('users', sa.Column('gitea_username', sa.String(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('users', 'gitea_username') + # ### end Alembic commands ### + + + + + + diff --git a/backend/app/core/security.py b/backend/app/core/security.py index cb9ca20..e13d3ca 100644 --- a/backend/app/core/security.py +++ b/backend/app/core/security.py @@ -1,18 +1,10 @@ from datetime import datetime, timedelta, timezone from typing import Any, Union from jose import jwt -import bcrypt # Import first +import bcrypt -# MonkeyPatch passlib/bcrypt compatibility (passlib expects __about__) -if not hasattr(bcrypt, "__about__"): - from types import SimpleNamespace - bcrypt.__about__ = SimpleNamespace(__version__=bcrypt.__version__) - -from passlib.context import CryptContext from app.core.config import settings -pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") - ALGORITHM = settings.ALGORITHM def create_access_token( @@ -29,10 +21,36 @@ def create_access_token( return encoded_jwt def verify_password(plain_password: str, hashed_password: str) -> bool: - return pwd_context.verify(plain_password, hashed_password) + """ + Verify a password against a hash. + Explicitly truncate to 72 bytes to avoid bcrypt ValueError and maintain compatibility. + """ + if not plain_password or not hashed_password: + return False + + try: + password_bytes = plain_password.encode("utf-8") + if len(password_bytes) > 72: + password_bytes = password_bytes[:72] + + return bcrypt.checkpw( + password_bytes, + hashed_password.encode("utf-8") + ) + except Exception: + return False def get_password_hash(password: str) -> str: - return pwd_context.hash(password) + """ + Generate a bcrypt hash of the password. + Explicitly truncate to 72 bytes for consistency. + """ + password_bytes = password.encode("utf-8") + if len(password_bytes) > 72: + password_bytes = password_bytes[:72] + + salt = bcrypt.gensalt() + return bcrypt.hashpw(password_bytes, salt).decode("utf-8") diff --git a/backend/app/models/user.py b/backend/app/models/user.py index 89d6157..3f6148e 100644 --- a/backend/app/models/user.py +++ b/backend/app/models/user.py @@ -19,6 +19,7 @@ class User(Base): role = Column(String, default="member") github_username = Column(String, nullable=True) gitlab_username = Column(String, nullable=True) + gitea_username = Column(String, nullable=True) created_at = Column(DateTime(timezone=True), server_default=func.now()) updated_at = Column(DateTime(timezone=True), onupdate=func.now()) diff --git a/backend/app/schemas/user.py b/backend/app/schemas/user.py index 88825e9..0f53794 100644 --- a/backend/app/schemas/user.py +++ b/backend/app/schemas/user.py @@ -13,6 +13,7 @@ class UserBase(BaseModel): role: str = "member" github_username: Optional[str] = None gitlab_username: Optional[str] = None + gitea_username: Optional[str] = None class UserCreate(UserBase): email: EmailStr diff --git a/backend/app/services/init_templates.py b/backend/app/services/init_templates.py index dbe4c8a..ef854c7 100644 --- a/backend/app/services/init_templates.py +++ b/backend/app/services/init_templates.py @@ -275,8 +275,8 @@ SYSTEM_RULE_SETS = [ "description": "基于 OWASP Top 10 2021 的安全审计规则集", "language": "all", "rule_type": "security", - "is_default": True, - "sort_order": 0, + "is_default": False, + "sort_order": 1, "severity_weights": {"critical": 10, "high": 5, "medium": 2, "low": 1}, "rules": [ { @@ -386,8 +386,8 @@ SYSTEM_RULE_SETS = [ "description": "通用代码质量检查规则集", "language": "all", "rule_type": "quality", - "is_default": False, - "sort_order": 1, + "is_default": True, + "sort_order": 0, "severity_weights": {"critical": 10, "high": 5, "medium": 2, "low": 1}, "rules": [ { @@ -550,6 +550,11 @@ async def init_system_templates(db: AsyncSession) -> None: ) db.add(template) logger.info(f"✓ 创建系统提示词模板: {template_data['name']}") + else: + # 更新已存在的系统模板的默认状态和排序 + existing.is_default = template_data.get("is_default", False) + existing.sort_order = template_data.get("sort_order", 0) + db.add(existing) await db.flush() @@ -599,6 +604,11 @@ async def init_system_rule_sets(db: AsyncSession) -> None: db.add(rule) logger.info(f"✓ 创建系统规则集: {rule_set_data['name']} ({len(rule_set_data.get('rules', []))} 条规则)") + else: + # 更新已存在的系统规则集的默认状态和排序 + existing.is_default = rule_set_data.get("is_default", False) + existing.sort_order = rule_set_data.get("sort_order", 0) + db.add(existing) await db.flush() diff --git a/frontend/src/components/audit/TerminalProgressDialog.tsx b/frontend/src/components/audit/TerminalProgressDialog.tsx index 76c057f..ba4173b 100644 --- a/frontend/src/components/audit/TerminalProgressDialog.tsx +++ b/frontend/src/components/audit/TerminalProgressDialog.tsx @@ -467,7 +467,6 @@ export default function TerminalProgressDialog({
AUDIT_TERMINAL - v3.0
diff --git a/frontend/src/pages/Account.tsx b/frontend/src/pages/Account.tsx index 9e2d14c..2f529a3 100644 --- a/frontend/src/pages/Account.tsx +++ b/frontend/src/pages/Account.tsx @@ -38,6 +38,7 @@ export default function Account() { phone: "", github_username: "", gitlab_username: "", + gitea_username: "", }); const [passwordForm, setPasswordForm] = useState({ current_password: "", @@ -60,6 +61,7 @@ export default function Account() { phone: res.data.phone || "", github_username: res.data.github_username || "", gitlab_username: res.data.gitlab_username || "", + gitea_username: res.data.gitea_username || "", }); } catch (error) { console.error('Failed to load profile:', error); @@ -288,6 +290,18 @@ export default function Account() { className="cyber-input" /> +
+ + setForm({ ...form, gitea_username: e.target.value })} + placeholder="your-gitea-username" + className="cyber-input" + /> +
diff --git a/frontend/src/pages/AgentAudit/components/SplashScreen.tsx b/frontend/src/pages/AgentAudit/components/SplashScreen.tsx index 23c233c..6708e24 100644 --- a/frontend/src/pages/AgentAudit/components/SplashScreen.tsx +++ b/frontend/src/pages/AgentAudit/components/SplashScreen.tsx @@ -15,7 +15,7 @@ interface SplashScreenProps { // Enhanced boot sequence messages with icons const BOOT_SEQUENCE = [ { text: "[INIT] Loading DeepAudit Core...", delay: 0, type: 'init' }, - { text: "[SCAN] AI Code Review Engine v3.0", delay: 200, type: 'scan' }, + { text: "[SCAN] AI Code Review Engine", delay: 200, type: 'scan' }, { text: "[LOAD] Vulnerability Pattern Database", delay: 400, type: 'load' }, { text: "[SYNC] Agent Orchestration Module", delay: 600, type: 'sync' }, { text: "[READY] System Online", delay: 800, type: 'ready' }, @@ -234,10 +234,7 @@ export function SplashScreen({ onComplete }: SplashScreenProps) { - {/* Version tag */} -
- [ v3.0.0 // NEURAL_CORE ] -
+ {/* Version tag removed */} {/* Terminal window - adaptive styling */} diff --git a/frontend/src/shared/types/index.ts b/frontend/src/shared/types/index.ts index db57b01..dc97f0d 100644 --- a/frontend/src/shared/types/index.ts +++ b/frontend/src/shared/types/index.ts @@ -16,6 +16,7 @@ export interface Profile { role: 'admin' | 'member'; github_username?: string; gitlab_username?: string; + gitea_username?: string; created_at: string; updated_at: string; }