Commit Graph

84 Commits

Author SHA1 Message Date
Lich-Mac-Mini 30f585822b Merge remote-tracking branch 'origin/main' into codex/redeem-subscription
# Conflicts:
#	web/classic/src/components/topup/index.jsx
2026-04-28 16:06:03 +08:00
feitianbubu 02aacb38a2 feat: add user created_at and last_login_at 2026-04-25 12:44:44 +08:00
CaIon c31343ac76 fix(log): hide admin identity in user-visible management logs
Admin username/ID was embedded directly into the log Content for
quota changes and forced 2FA disable, leaking the operator's
identity to the target user via their own usage log page.

Move operator info into Other.admin_info so formatUserLogs strips
it for non-admin viewers, and render it in the expand panel only
for admins as "操作管理员".

Closes #4301
2026-04-18 00:16:52 +08:00
CaIon 9253426223 fix(user): invalidate user and token caches when disabling user
When an admin disables/deletes/promotes/demotes a user via ManageUser,
explicitly evict the user cache and all of the user's token caches from
Redis. This prevents a disabled user from continuing to make successful
API requests until the user cache TTL expires, and ensures subsequent
requests reload fresh status from the database.
2026-04-17 23:58:45 +08:00
Lich-Mac-Mini 06f9bde3c9 Merge tag 'v0.12.12' into codex/redeem-subscription
v0.12.12

# -----BEGIN PGP SIGNATURE-----
#
# iQIzBAABCAAdFiEELDLYXndFTEpGR0CuDPphNSmpkh0FAmnhzLIACgkQDPphNSmp
# kh19mg/+JdGRYXBMPXap8sJCWZ6QNkro5/PtNyy8GOiqDPb42Ud2QM7472P8IZj1
# TIVa/cjU4Vg+BJYKkvJ5oHmJBFLsvLUyjyhKEU7hdrgBBufNGriJsTERYNAwAzHo
# pnzbzVzQClN19ficvbobdkiT4zBpxmyC4kuWRcDePQga10wX2oTyAlBsZ2MZg2Go
# 2ceXPgkfatEMkwjULZtaVC3BxznQ5nhEpSPOSeJufKsf/tHpso3IfcoA7be62Mmd
# gh0syQUV4dH2PJ1kz/ihentLse4SDI1018fn6W2fBxAwcamaFP/Arr366c1pLck0
# IeISGUfoScSHGTu2dHJ3h0nuOqATyd/mXfzNnox58p+eQ+52eSfyiOyjx5sQ04WG
# SRgso3Zl6F/fBcCKy8YPHAIJVuoRJMSfi0QSdMD3pdhdwb6E5GQ+J2y80WDg7XN3
# PPrRRp5Quq4aSSMBVcuCvANIFHu6DeyLm8MIBbeujByXzW6ODDpEo74HxCeUKqE+
# Dbwo7c5GMY4mUdQTGo4QuFVB+OFcPY+d4uSRwt0YDT4s9ySJNyNJg2fv6JOwMQVx
# wIfpI5pOrgGDpQgTjeMw1NzA6oPHaOk41ZcqzJ1onB+hh0KYO+401cXFoVkZqxW/
# uHZTspy56M71HsCqNmB6MtqScNWlQhKuRxa4drMRqT+QddbiWHo=
# =Byz/
# -----END PGP SIGNATURE-----

# Conflicts:
#	model/redemption.go
#	web/package.json
#	web/src/components/table/redemptions/modals/EditRedemptionModal.jsx
2026-04-17 19:29:19 +08:00
feitianbubu d15e14b117 feat: include admin username in quota adjustment logs 2026-04-13 16:09:59 +08:00
CaIon 2819e3a1d1 fix: improve login error handling to distinguish database errors from auth failures
ValidateAndFill now checks the DB query result and returns sentinel errors
(ErrDatabase, ErrInvalidCredentials, ErrUserEmptyCredentials) instead of
hardcoded Chinese strings. The controller maps each sentinel to the
appropriate i18n message, so users see "please contact admin" on DB errors
instead of a misleading "wrong password" message. Non-DB errors still
return a unified vague response to avoid leaking user existence.
2026-04-12 17:11:20 +08:00
CaIon 040e8c1da8 feat: replace quota input with amount-first UI and atomic quota adjustment
- Refactor token, redemption, and user quota inputs to prioritize monetary
  amount entry, with raw quota input collapsed by default
- Add atomic quota adjustment modal for users with add/subtract/override modes,
  bypassing batch update queue for immediate DB consistency
- Make user quota fields readonly in edit form; all modifications go through
  the dedicated adjust-quota modal via POST /api/user/manage
- Add DecreaseUserQuota `db` parameter for direct DB writes, matching
  IncreaseUserQuota behavior
- Support negative quota display in amount conversion helpers
- Add i18n keys for all new UI strings across all locales
2026-04-09 22:44:53 +08:00
lzt c538ebd62f Add subscription redemption code support 2026-04-06 10:23:28 +08:00
CaIon e099117c61 refactor: use POST for account binding endpoints and normalize reset responses
- Switch /api/oauth/email/bind and /api/oauth/wechat/bind from GET to
  POST with JSON body for better REST semantics
- Normalize password reset endpoint to return consistent responses
- Apply url.QueryEscape to WeChat code parameter for robustness
2026-03-31 18:44:40 +08:00
Seefs 70821e2051 feat: auto fetch upstream models (#2979)
* feat: add upstream model update detection with scheduled sync and manual apply flows

* feat: support upstream model removal sync and selectable deletes in update modal

* feat: add detect-only upstream updates and show compact +/- model badges

* feat: improve upstream model update UX

* feat: improve upstream model update UX

* fix: respect model_mapping in upstream update detection

* feat: improve upstream update modal to prevent missed add/remove actions

* feat: add admin upstream model update notifications with digest and truncation

* fix: avoid repeated partial-submit confirmation in upstream update modal

* feat: improve ui/ux

* feat: suppress upstream update alerts for unchanged channel-count within 24h

* fix: submit upstream update choices even when no models are selected

* feat: improve upstream model update flow and split frontend updater

* fix merge conflict
2026-03-02 22:01:53 +08:00
Seefs 62856666c4 feat: move user bindings to dedicated management modal 2026-02-23 14:51:55 +08:00
CaIon 194e89de12 fix(i18n): add missing translations and improve language fallback
- Change default language fallback to English instead of Chinese
- Add ErrRedeemFailed typed error for model layer translation
- Migrate remaining hardcoded messages in controller/user.go
- Add translation keys: redeem.failed, user.create_default_token_error, common.uuid_duplicate, common.invalid_input
2026-02-05 00:16:17 +08:00
CaIon c444746088 feat(i18n): add backend multi-language support with user language preference
- Add go-i18n library for internationalization
- Create i18n package with translation keys and YAML locale files (zh/en)
- Implement i18n middleware for language detection from user settings and Accept-Language header
- Add Language field to UserSetting DTO
- Update API response helpers with i18n support (ApiErrorI18n, ApiSuccessI18n)
- Migrate hardcoded messages in token, redemption, and user controllers
- Add frontend language preference settings component
- Sync language preference across header selector and user settings
- Auto-restore user language preference on login
2026-02-05 00:09:32 +08:00
skynono 7379b68f9f feat: support first bind update password (#2520) 2025-12-26 13:59:56 +08:00
CaIon ceb7ebe5cd feat(user): simplify user response structure in JSON output 2025-12-25 15:39:58 +08:00
StageDog 352801cd35 feat: 关联 discord 账号 2025-11-22 18:38:24 +08:00
CaIon 6aec088693 feat: add special user usable group setting 2025-10-28 23:25:43 +08:00
Seefs 5010f2d004 format: package name -> github.com/QuantumNous/new-api (#2017) 2025-10-11 15:30:09 +08:00
RedwindA 98050ee6e9 feat: add Gotify notification option for quota alerts 2025-10-01 19:15:00 +08:00
RedwindA 9e271b0680 fix: sync third-party binding state in personal settings 2025-09-29 19:23:42 +08:00
Seefs 4f44bbed31 feat: bark notification #1699 2025-09-01 15:57:23 +08:00
creamlike1024 3d86279240 fix: revert a00d8e2 2025-08-31 14:59:55 +08:00
creamlike1024 11fa5042df fix: update sidebar modules role check 2025-08-31 14:54:47 +08:00
creamlike1024 a00d8e25eb fix(user): UpdateSelf 边栏权限检查和类型检查 2025-08-31 14:40:35 +08:00
F。 d0d6168e2f 顶栏和侧边栏管理
增加用户体验
2025-08-31 07:07:40 +08:00
CaIon cf9faeb901 feat: implement concurrent top-up locking mechanism to prevent race conditions 2025-08-15 20:03:38 +08:00
CaIon c9e9a24e99 refactor: centralize logging and update resource initialization
This commit refactors the logging mechanism across the application by replacing direct logger calls with a centralized logging approach using the `common` package. Key changes include:

- Replaced instances of `logger.SysLog` and `logger.FatalLog` with `common.SysLog` and `common.FatalLog` for consistent logging practices.
- Updated resource initialization error handling to utilize the new logging structure, enhancing maintainability and readability.
- Minor adjustments to improve code clarity and organization throughout various modules.

This change aims to streamline logging and improve the overall architecture of the codebase.
2025-08-14 21:10:04 +08:00
CaIon 97ea8b6560 refactor: Introduce pre-consume quota and unify relay handlers
This commit introduces a major architectural refactoring to improve quota management, centralize logging, and streamline the relay handling logic.

Key changes:
- **Pre-consume Quota:** Implements a new mechanism to check and reserve user quota *before* making the request to the upstream provider. This ensures more accurate quota deduction and prevents users from exceeding their limits due to concurrent requests.

- **Unified Relay Handlers:** Refactors the relay logic to use generic handlers (e.g., `ChatHandler`, `ImageHandler`) instead of provider-specific implementations. This significantly reduces code duplication and simplifies adding new channels.

- **Centralized Logger:** A new dedicated `logger` package is introduced, and all system logging calls are migrated to use it, moving this responsibility out of the `common` package.

- **Code Reorganization:** DTOs are generalized (e.g., `dalle.go` -> `openai_image.go`) and utility code is moved to more appropriate packages (e.g., `common/http.go` -> `service/http.go`) for better code structure.
2025-08-14 20:05:06 +08:00
t0ng7u 1ea54eb2ed 🖼️ chore: format code file 2025-08-10 12:11:31 +08:00
Seefs b48d3a6b40 feat: implement two-factor authentication (2FA) support with user login and settings integration 2025-08-02 14:53:28 +08:00
Xyfacai 38c5e0e9f4 refactor: format api page query and err result 2025-07-14 22:03:22 +08:00
Xiangyuan-liu db98c0f4b1 refactor: log params and channel params
refactor: log params and channel params
2025-07-07 14:26:37 +08:00
CaIon f14f4eaf1a feat: refactor environment variable initialization and introduce new constant types for API and context keys 2025-07-03 13:10:25 +08:00
Xiangyuan-liu b206a7c683 feat: 优化分页组件 2025-06-25 18:42:19 +08:00
creamlike1024 c6a9df67b1 feat: auto分组 2025-06-16 22:15:12 +08:00
Apple\Apple 1f6ec0174a feat: add admin-only "remark" support for users
* backend
  - model: add `Remark` field (varchar 255, `json:"remark,omitempty"`); AutoMigrate handles schema change automatically
  - controller:
    * accept `remark` on user create/update endpoints
    * hide remark from regular users (`GetSelf`) by zero-ing the field before JSON marshalling
    * clarify inline comment explaining the omitempty behaviour

* frontend (React / Semi UI)
  - AddUser.js & EditUser.js: add “Remark” input for admins
  - UsersTable.js:
    * remove standalone “Remark” column
    * show remark as a truncated Tag next to username with Tooltip for full text
    * import Tooltip component
  - i18n: reuse existing translations where applicable

This commit enables administrators to label users with private notes while ensuring those notes are never exposed to the users themselves.
2025-06-16 03:20:54 +08:00
Apple\Apple 28c3aef76f 🔒 feat: Add user-configurable IP logging for consume and error logs
- Add IP field to Log model with database index and default empty value
- Implement conditional IP recording based on user setting in RecordConsumeLog and RecordErrorLog
- Add UserSettingRecordIpLog constant and update user settings API to handle record_ip_log field
- Create dedicated "IP记录" tab in personal settings under "其他设置" section
- Add IP column to logs table with help tooltip explaining recording conditions
- Make IP column visible to all users (not admin-only) with proper filtering for consume/error log types
- Restrict display of use_time and retry columns to consume and error log types only
- Update personal settings UI structure: rename "通知设置" to "其他设置" to accommodate new functionality
- Add proper translation support and maintain consistent styling across components

The IP logging feature is disabled by default and only records client IP addresses
for consume (type 2) and error (type 5) logs when explicitly enabled by users
in their personal settings.
2025-06-13 01:34:01 +08:00
creamlike1024 13afcd4266 fix: 修复未输入新密码时提示修改成功 2025-05-06 22:28:32 +08:00
skynono bb596ae8e6 feat: add original password verification when changing password 2025-05-06 14:28:27 +08:00
CaIon f0925dc105 feat: Enhance user settings and notification options 2025-04-03 17:32:48 +08:00
1808837298@qq.com 7a13f9c99a fix: Ensure correct quota warning threshold type conversion 2025-02-22 15:19:55 +08:00
1808837298@qq.com 1ae0a38485 refactor: Optimize user caching and token retrieval methods 2025-02-19 15:12:26 +08:00
1808837298@qq.com 83e161a1d4 refactor: Simplify root user notification and remove global email variable
- Remove global `RootUserEmail` variable
- Modify channel testing and user notification methods to use `GetRootUser()`
- Update user cache and notification service to use more consistent user base type
- Add new channel test notification type
2025-02-18 15:59:17 +08:00
1808837298@qq.com 0fcd243f56 feat: Add user notification settings with quota warning and multiple notification methods
- Implement user notification settings with email and webhook options
- Add new user settings for quota warning threshold and notification preferences
- Create backend API and database support for user notification configuration
- Enhance frontend personal settings with notification configuration UI
- Support custom notification email and webhook URL
- Add service layer for sending user notifications
2025-02-18 14:54:21 +08:00
1808837298@qq.com 6d021b20b7 fix: replace context-based user ID with session-based retrieval #741
- Update user and wechat controllers to use sessions for user ID
- Modify ID retrieval to use `session.Get("id")` instead of `c.GetInt("id")`
- Cast session ID to int when creating user object
2025-02-10 20:52:33 +08:00
CalciumIon 7fec5fa1b3 feat: enhance user search functionality with pagination support
- Updated SearchUsers function to include pagination parameters (startIdx and num) for improved user search results.
- Modified API response structure to return paginated data, including total user count and current page information.
- Adjusted UsersTable component to handle pagination and search parameters, ensuring a seamless user experience.
- Added internationalization support for new search functionality in the UI.
2024-12-31 15:02:59 +08:00
CalciumIon 5a39d2e171 feat: enhance user management and pagination features #518
- Updated GetAllUsers function to return total user count along with paginated results, improving data handling in user retrieval.
- Modified GetAllUsers API endpoint to accept page size as a parameter, allowing for dynamic pagination.
- Enhanced UsersTable component to support customizable page sizes and improved pagination logic.
- Added error handling for empty username and password in AddUser component.
- Updated LogsTable component to display pagination information in a user-friendly format.
2024-12-31 14:52:55 +08:00
CalciumIon 6093ae6f30 fix: prevent duplicate models in user group retrieval 2024-12-27 21:25:44 +08:00
CalciumIon e671b0d357 refactor: improve user group handling and add GetUserUsableGroups function
- Introduced a new function `GetUserUsableGroupsCopy` to return a copy of user usable groups.
- Updated `GetUserUsableGroups` to utilize the new function for better encapsulation.
- Changed variable names from `UserUsableGroups` to `userUsableGroups` for consistency.
- Enhanced `GetUserUsableGroups` logic to ensure it returns a copy of the groups, preventing unintended modifications.
2024-12-27 21:19:22 +08:00