251 Commits (46f01afc9fe57a392066dd739f0f91e4f3ec4ee6)
 

Author SHA1 Message Date
veypi 46f01afc9f feat(auth): Improve OAuth callback and add memory cache fallback
- Add random avatar generation for new users in register
    - Fix OAuth state parsing with type assertions and error handling
    - Add TempToken field to CallbackResponse for bind flow
    - Implement dynamic redirect URI resolution with X-Forwarded headers support
    - Add memory cache fallback when Redis is unavailable
    - Change default port from 4001 to 4000 in Makefile
3 weeks ago
veypi 627439bc4d feat(ui): Add system settings and OAuth providers management pages
- Add new settings page with application, auth, security, email, SMS configuration
    - Add OAuth identity providers management page with CRUD operations
    - Update login page to support dynamic OAuth providers and verification code login
    - Add navigation menu items for settings and OAuth providers
    - Add i18n translations for settings and OAuth provider management
    - Add routes for /settings and /oauth/providers pages
3 weeks ago
veypi 0e8e72b7e7 refactor(api): Improve API parameter handling and add public info endpoint
- Change BindMode from bool to *bool in thirdparty auth for proper optional handling
    - Change Error field from string to *string in OAuth callback request
    - Change Email and Phone to *string pointers in bind with register request
    - Add public /api/info endpoint for frontend configuration
    - Update OAuth token request to use pointers for optional code and refresh_token
    - Add desc tags to various request struct fields for API documentation
    - Fix path parameter binding with explicit @code suffix for OAuth providers
    - Change Description field to *string pointer in role creation
    - Change Category field to *string pointer in settings list
3 weeks ago
veypi be6e07404c feat(ui): Redesign login page with integrated register
- Merge login and register into single page with sliding animation
    - Add dual login modes: username/password and verification code
    - Add OAuth buttons for GitHub, WeChat, Google (placeholder)
    - Add animated bubble background effect
    - Implement responsive design for mobile devices
    - Add comprehensive i18n translations for auth flows
    - Remove separate register.html page
    - Update routes to use new unified auth page
3 weeks ago
veypi de2eda5516 docs: Format auth.md with consistent table spacing
- Fix table alignment in permission level documentation
    - Standardize code block indentation
    - Improve formatting consistency throughout document
3 weeks ago
veypi 5460289957 refactor(ui): Update vbase.js to match new Scoped RBAC permission system
- Replace old permission check methods with new Perm/PermCreate/PermRead/PermWrite/PermAdmin
    - Add Level constants export (None, Create, Read, Write, ReadWrite, Admin)
    - Remove role-based permission checks (hasRole, checkPermAny, checkPermAll)
    - Update core permission checking logic to match backend checkPermissionLevel
    - Remove _isAdmin helper, use Level.Admin check instead
    - Simplify localStorage keys (remove scope prefix from keys)
    - Clean up console.log in env.js
3 weeks ago
veypi 65bd2b5b52 refactor(auth): Use vigo/contrib/auth.Auth interface instead of local definition
- Remove local Auth interface definition from auth/auth.go
    - Import and use pub.Auth from github.com/veypi/vigo/contrib/auth
    - Update authFactory.New() to return pub.Auth type
    - Add compile-time type check: var _ pub.Auth = &appAuth{}
    - Update go.mod dependencies (add redis, update gorm, remove aliyun sms)
3 weeks ago
veypi 56d87ec18a test: Update tests for scoped RBAC and remove org tests
- Remove org-related test cases from edge_case_test.go
    - Remove OrgResp type from main_test.go
    - Update none_auth_test removing org endpoints
    - Add permission grants in OAuth tests for proper access control
    - Fix race condition tests with retry logic for SQLite locking
    - Update resource_perm_test to accept 401 or 403 status codes
    - Add new role_access_test.go for role API permission testing
    - Add new scoped_auth_test.go for scoped permission testing
3 weeks ago
veypi b378c3c5c4 refactor(ui): Remove organization management pages and related i18n
- Delete ui/page/sys/org/ directory (org management UI)
    - Remove org-related navigation from routes.js and layout
    - Remove org translations from langs.json
    - Update dashboard to remove org references
3 weeks ago
veypi 12c55a2997 refactor(api): Update permission codes and remove org-related code
- Update API endpoints to use scoped permission codes (e.g., role:*)
    - Fix role list scope parameter to use pointer type
    - Add Options type alias in init.go for external use
    - Remove org-related cache functions from libs/cache
3 weeks ago
veypi b00e36ca80 refactor(auth): Add permission validation and update design docs
- Add validatePermission function to check depth/level consistency
    - Validate permission codes in Perm, Grant, and Check methods
    - LevelCreate requires odd depth, other levels require even depth
    - Update design.md examples from org to app/role model
    - Add RoleID field to Permission struct documentation
3 weeks ago
veypi 438a84d9fc docs: Update documentation to reflect scoped RBAC and remove org system
- Update CLAUDE.md to describe scoped RBAC instead of multi-tenant org
    - Simplify README.md removing org-related features
    - Update auth.md with comprehensive scoped permission documentation
    - Remove configuration.md (merged into other docs)
    - Update design.md with new architecture decisions
    - Update integration.md with scoped auth examples
    - Update UI documentation removing org references
    - Update test README removing org test references
3 weeks ago
veypi a7ffd15601 refactor: Remove multi-tenant org system and simplify auth
- Delete org API endpoints (add_member, create, del, get, list, member, patch, tree)
    - Delete models/org.go and remove Org/OrgMember models
    - Delete org-related test files (org_crud, org_load_middleware, org_permission, multi_tenant)
    - Delete org test scripts (03_org_permission.sh, 04_org_load_middleware.sh)
    - Simplify auth/auth.go by removing org context and role loading logic
    - Remove org claims from JWT tokens and login/register responses
    - Redesign Permission model with hierarchical level-based access control
    - Add auth/design.md with new permission system specification
    - Update user and role APIs to work without org context
4 weeks ago
veypi ec47bcc192 refactor: Migrate auth to Vigo auth interface and simplify initialization
- Replace GetUserID/GetOrgID with VBaseAuth.UserID/OrgID methods across all APIs
- Integrate vigoauth.Auth interface into appAuth for standard auth methods
- Move AuthMiddleware to PermLogin method in auth package
- Add role management methods: GetRole, ListRoles, GrantRoles, RevokeRoles, ListUserRoles
- Update ListUserPermissions and ListResourceUsers to return vigoauth types
- Export Redis client in cfg package
- Simplify app initialization by separating vigo.New in cli/main.go
- Remove deprecated auth/middleware.go file
4 weeks ago
veypi df0f7f047a refactor: Rename Config to Global and simplify app initialization
- Rename cfg.Config to cfg.Global for consistency
    - Simplify cli/main.go to use vbase.App.Run() pattern
    - Update init.go to create app with vigo.New and Init function
    - Update all references from cfg.Config to cfg.Global across api, libs, models, and tests
    - Fix VBase constructor parameter order in ui/vbase.js
    - Update ui/env.js to use new VBase('vb', '/') initialization
4 weeks ago
veypi 0b22d2c2c8 test: Add comprehensive security and integration tests
- Add wildcard permission tests for RBAC hierarchy
    - Add multi-tenant isolation tests for organization access
    - Add OAuth2 security tests including client ownership and redirect URI
    - Add race condition tests for concurrent operations
    - Add edge case tests for SQL injection, XSS, input validation
    - Add security test report documenting findings and fixes
4 weeks ago
veypi c588962485 fix: Add input validation and OAuth client access control
- Add username validation (required, 3-50 chars, alphanumeric + underscore)
    - Add password validation (required, minimum 8 characters)
    - Add email format validation using regex
    - Add owner check in OAuth client update and delete operations
    - Allow admin users with wildcard permission to access all organizations
4 weeks ago
veypi b2b24df82e refactor(ui): Rebuild permission system in vbase.js with scope support
- Add scope parameter to VBase constructor for multi-tenant support
    - Replace hasPermission with checkPerm, checkPermOnResource, checkPermAny, checkPermAll
    - Implement _isAdmin check for global wildcard permissions (*:*)
    - Add _matchPermission with wildcard support (resource:*, *:*)
    - Remove default 404 page from vrouter in root.html
4 weeks ago
veypi fba42193cf feat(api): Enhance /auth/me endpoint with permissions and roles
- Add UserPermissionInfo and UserInfoWithPerms structs for detailed user info
    - Extend /auth/me to return user permissions and global roles
    - Remove unused isAdmin helper method from auth.go
    - Update updateMe to return UserInfoWithPerms for consistency
4 weeks ago
veypi 7f7591cf6d test: Add integration tests for org, role and oauth client
- Add OAuth client CRUD and access control tests
    - Add organization CRUD, tree and access control tests
    - Add role CRUD, access control and system role protection tests
    - Remove user:read permission from default user role
1 month ago
veypi 63792b449f docs: Add CLAUDE.md for Claude Code guidance
- Add project overview with tech stack (Go 1.24+, Vigo framework, GORM)
    - Document common commands (make run, db operations, tests)
    - Describe onion model request flow and middleware stages
    - Explain RBAC permission system format and usage
    - Document multi-tenancy patterns (B2C/B2B/Platform)
    - Add API response format and error code conventions
    - Include Vigo handler pattern with parameter binding
    - Document vhtml frontend structure
1 month ago
veypi b0322047cd feat: Restrict user APIs to admins and add public user search
- Add /api/auth/users endpoint for authenticated users to search other users
    - Only return public info (id, username, nickname, avatar) in search results
    - Change /api/user routes to require user:admin permission instead of user:read
    - Update auth tests to use /api/auth/me for self updates
    - Add tests for new user search endpoint
1 month ago
veypi b8c894b5cf test: Refactor test infrastructure to use in-memory SQLite database
- Add tests/README.md with comprehensive documentation for running and adding tests
    - Change TestDBFile from file-based 'test.db' to in-memory 'file::memory:?cache=shared'
    - Remove file cleanup in setup() and teardown() functions since memory database requires no cleanup
    - Simplify setup() by removing comments and streamlining database configuration
1 month ago
veypi 01620b3185 refactor(test): restructure integration tests for auth and permissions
- Move and split 'auth/auth_test.go' into the 'tests/' directory
    - Add 'tests/main_test.go' for global test suite setup
    - Add 'tests/helpers_test.go' for shared test utilities
    - Create separate test files for different auth scenarios ('auth_test.go', 'none_auth_test.go')
    - Add focused tests for org permissions and middleware ('org_permission_test.go', 'resource_perm_test.go', 'org_load_middleware_test.go')
1 month ago
veypi f7c4f1ee86 test: improve test stability and documentation
- Add 'clean_run.sh' script to reset database and restart server for clean test environment
    - Update 'README.md' with detailed troubleshooting guide and pitfalls
    - Add '04_org_load_middleware.sh' to test LoadOrg middleware functionality
    - Update 'run_all.sh' to include new middleware test
    - Fix BASE_URL handling in 'lib.sh' and test scripts to support custom environments
    - Update '02_resource_perm.sh' to fix admin permission checks
    - Remove debug logging from 'auth.go'
1 month ago
veypi 1f380587a9 refactor(tests): Restructure test scripts with better coverage
- Add 00_none_auth.sh for unauthenticated access testing
    - Replace 01_basic_auth.sh with 01_setup_users.sh for comprehensive user setup
    - Replace 02_user_permission.sh with 02_resource_perm.sh for cross-user permission tests
    - Update lib.sh to handle non-numeric code fields in response
    - Update README.md with new test structure and usage instructions
    - Update run_all.sh with new test sequence
1 month ago
veypi 95cdcd557c fix(auth): Correct owner ID resolution order in PermWithOwner
- Fix owner ID lookup to prioritize PathParams and Query over Context
    - Prevent incorrect owner match when context contains current user ID
    - Reset InitAdmin.Password to empty so first registered user becomes admin
1 month ago
veypi 9518a9be21 chore(gitignore): Update ignore rules
- Remove outdated entries (oa.db, OneAuth)
    - Add .claude directory to ignore list
1 month ago
veypi a22ad4a155 test(scripts): Fix test scripts and improve curl handling
- Fix api request functions to use array-based curl options
    - Fix token refresh to use refresh_token instead of access_token
    - Fix string comparison operator from == to =
    - Add get_refresh_token helper function
    - Handle empty response in check_http_code
    - Update README with new functions and correct command syntax
    - Remove set -e from lib.sh to avoid premature exits
1 month ago
veypi 11a689f28d fix(auth): Fix permission logic and add org member API
- Add api/org/add_member.go for adding organization members
    - Register POST /api/orgs/{id}/members endpoint
    - Fix PermWithOwner to check owner before permission
    - Remove user:update from user role (should use owner check)
    - Add service enabled check in verification send
1 month ago
veypi e96277ee85 fix(api/settings): wrap batch update in database transaction
Use database transaction for batch settings update to ensure atomicity.
If any individual update fails, the entire batch will be rolled back,
preventing partial configuration updates.

- Wrap all updates in db.Transaction()
- Return detailed error on failure
1 month ago
veypi 5304c30fb9 fix(api/verification): validate purpose parameter
Add validation for the 'purpose' parameter in verification code requests
to ensure only allowed values are accepted.

Valid purposes: register, login, reset_password, bind
Invalid purposes will be rejected with 400 Bad Request.
1 month ago
veypi 241d22dba6 fix(api/verification): handle max_daily_count config correctly
Fix the logic for code.max_daily_count setting to correctly handle:
- 0: Disable verification code service entirely
- -1: No limit on daily sends
- >0: Limit daily sends to the specified number

Previously both 0 and -1 were treated as unlimited, which was incorrect.
The documentation states 0 should disable the service.
1 month ago
veypi 69efc4284b fix(api/oauth): encrypt ClientSecret in database
Encrypt OAuth Provider ClientSecret before storing in database to prevent
sensitive credential exposure in case of database breach.

- Encrypt ClientSecret on create using cfg.Config.Key.Encrypt()
- Encrypt ClientSecret on update when provided
- Decrypt ClientSecret before use in OAuth token exchange
- Add AES-GCM encryption/decryption functions to crypto package
- Gracefully handle legacy plaintext secrets during transition
1 month ago
veypi 4a316e6d67 fix(api/auth): reset count variable before uniqueness checks
Fix a bug where the count variable was not reset before checking
email and phone uniqueness. This could cause false positives if
a previous check had count > 0, incorrectly reporting that email
or phone already exists when they don't.

- Reset count to 0 before email check
- Reset count to 0 before phone check
1 month ago
veypi 9dc866315f fix(api/settings): add admin permission check for settings update
Add permission check in settings update API to ensure only admin users
can modify system settings. This fixes a security vulnerability where
any authenticated user could modify critical configurations.

- Check 'setting:update' permission before allowing updates
- Return 403 Forbidden for non-admin users
1 month ago
veypi 4a57017067 refactor(cfg): Restructure database configuration and initialization flow
- Replace separate DB/DSN fields with unified config.Database struct
    - Remove cfg/db.go and move DB client to config.Database.Client()
    - Update auth to use event-driven initialization via vb.init.auth event
    - Refactor models initialization to use event system (vb.init.settings/oauth/admin)
    - Update CLI to use event.Start() instead of manual InitDB() call
    - Fix auth_test.go to use new DB config structure
    - Update agents.md documentation with new CLI flags format
1 month ago
veypi 23c7f6cb7a refactor(auth): 重构认证系统,支持多种验证方式和 OAuth 提供商管理
- 新增验证模块(api/verification),统一处理短信和邮件验证码发送
    - 新增邮件发送功能(libs/email),支持 SMTP 协议
    - 重构短信模块(libs/sms),简化阿里云和腾讯云短信接口
    - 新增 OAuth 提供商管理 API(api/oauth/providers),支持 CRUD 操作
    - 新增系统设置管理 API(api/settings),支持动态配置更新
    - 重构认证方式管理(api/auth/methods),支持启用/禁用多种登录方式
    - 删除旧的 sms_providers 和 sms API 模块,迁移至新验证体系
    - 新增数据库模型:verification、email、oauth_provider、oauth_templates、setting
    - 更新配置文档,增加新功能的使用说明
1 month ago
veypi 04997496d1 add configuration.md 1 month ago
veypi fa3719cf7d docs(readme): 完善项目 README.md
- 添加项目介绍、核心特性、快速开始指南
- 添加项目结构说明和配置文档
- 添加权限系统使用示例和 API 概览
- 添加多租户场景支持和架构设计说明
1 month ago
veypi 51b3bbc89e refactor(auth): 删除无用的 _scope_info 角色
- 删除创建 appAuth 时自动添加的 _scope_info 占位角色
- 删除对 _scope_info 的保留字检查
- 简化代码,避免在数据库中创建无用记录
1 month ago
veypi ba39611f58 fix(org): 为组织创建者添加权限
创建组织时,为组织特定的 admin 角色添加权限:
- vb:*:* (通配符权限)
- vb:org:read
- vb:org:update
- vb:org:delete

修复了组织创建者无法修改自己创建的组织的问题
1 month ago
veypi d7ee1a1f4e test: 添加集成测试脚本
新增 scripts/tests/ 目录,包含权限测试脚本:
- lib.sh: 公共函数库(API请求、用户/组织操作封装)
- 01_basic_auth.sh: 基础认证测试(注册、登录、改密、刷新token)
- 02_user_permission.sh: 用户权限测试(admin/user角色、信息修改权限)
- 03_org_permission.sh: 组织权限测试(创建组织、成员权限、修改权限)
- run_all.sh: 运行所有测试
- README.md: 测试说明文档

删除旧的 test.sh
1 month ago
veypi 54bb58048e fix(auth): 创建通配符权限前先创建 permission 记录
修复 initRole 中外键约束错误:
- 在创建 scope:*:* 的 role_permission 前,先确保 permission 记录存在
- 避免 Error 1452 外键约束失败
1 month ago
veypi 33eabfa013 refactor(auth): 重构权限系统,简化API并添加缓存支持
主要变更:
- 将权限域从 appKey 改为 scope,权限ID格式为 scope:resource:action
- 新增 AddRole(roleCode, roleName, policies...) 方法,支持动态添加角色
- 简化 Factory.New() 只保留 scope 参数,移除 models.AppConfig 依赖
- PermAny/PermAll 改为变长参数 ...string 形式,使用更简洁
- AuthMiddleware 添加 Redis 缓存组织成员身份和角色信息(5分钟过期)
- 移除 models.AppConfig 和 models.RoleDefinition 结构体
- 更新测试和文档

BREAKING CHANGE: Factory.New() 签名变更,需要使用新的 AddRole API
1 month ago
veypi 37acea3420 feat: 实现组织成员角色管理功能 1 month ago
veypi 691f1df75b feat: 添加角色管理模块(API + UI) 1 month ago
veypi 4101daeed3 refactor: 重构用户/组织/OAuth页面UI 1 month ago
veypi d85cb6ae84 i18n: 添加多语言翻译词条 1 month ago
veypi dce36cb65f feat: 优化组织管理页面交互 1 month ago