alist/pkg/utils
千石 c64f899a63
feat: implement session management (#9286)
* feat(auth): Added device session management

- Added the `handleSession` function to manage user device sessions and verify client identity
- Updated `auth.go` to call `handleSession` for device handling when a user logs in
- Added the `Session` model to database migrations
- Added `device.go` and `session.go` files to handle device session logic
- Updated `settings.go` to add device-related configuration items, such as the maximum number of devices, device eviction policy, and session TTL

* feat(session): Adds session management features

- Added `SessionInactive` error type in `device.go`
- Added session-related APIs in `router.go` to support listing and evicting sessions
- Added `ListSessionsByUser`, `ListSessions`, and `MarkInactive` methods in `session.go`
- Returns an appropriate error when the session state is `SessionInactive`

* feat(auth): Marks the device session as invalid.

- Import the `session` package into the `auth` module to handle device session status.
- Add a check in the login logic. If `device_key` is obtained, call `session.MarkInactive` to mark the device session as invalid.
- Store the invalid status in the context variable `session_inactive` for subsequent middleware checks.
- Add a check in the session refresh logic to abort the process if the current session has been marked invalid.

* feat(auth, session): Added device information processing and session management changes

- Updated device handling logic in `auth.go` to pass user agent and IP information
- Adjusted database queries in `session.go` to optimize session query fields and add `user_agent` and `ip` fields
- Modified the `Handle` method to add `ua` and `ip` parameters to store the user agent and IP address
- Added the `SessionResp` structure to return a session response containing `user_agent` and `ip`
- Updated the `/admin/user/create` and `/webdav` endpoints to pass the user agent and IP address to the device handler
2025-08-25 19:46:38 +08:00
..
hash fix: hash gcid empty file (#5394) 2023-10-18 16:27:07 +08:00
random feat(security): generating random string with crypto rand (#7525) 2024-11-21 22:37:19 +08:00
balance.go fix(search): empty parent where update (close #2810) 2023-01-16 17:33:24 +08:00
bool.go feat: optimize file operation interface (#2757) 2022-12-20 15:02:40 +08:00
ctx.go feat: cancel copy for upload 2022-06-25 15:14:03 +08:00
email.go feat(123): support mail login (close #2218 pr #2276) 2022-11-10 09:34:48 +08:00
file.go perf: use io copy with buffer pool (#6389) 2024-04-25 20:11:15 +08:00
hash.go feat(webdav): support `oc:checksums` (#8064 close #7472) 2025-03-15 00:21:07 +08:00
hash_test.go perf: use io copy with buffer pool (#6389) 2024-04-25 20:11:15 +08:00
io.go refactor(net): pass request header (#8031 close #8008) 2025-03-01 18:35:34 +08:00
ip.go fix(123): pass ip when getting download link 2022-09-10 13:54:10 +08:00
json.go fix(ci): sort lang json file 2022-12-05 14:40:46 +08:00
log.go feat: use `lumberjack` for log rotate 2022-08-30 15:22:54 +08:00
map.go feat: add `139yun` driver 2022-09-05 13:35:01 +08:00
mask.go feat: implement session management (#9286) 2025-08-25 19:46:38 +08:00
oauth2.go fix(pikpak): refresh_token contention (#6501 close #6511) 2024-05-27 21:31:59 +08:00
path.go feat(user): enhance path management and role handling (#9249) 2025-08-06 16:31:36 +08:00
path_test.go refactor: obj name mapping and internal path processing (#2733) 2022-12-17 19:49:05 +08:00
slice.go feat(search): search with `meilisearch` (#6060) 2024-02-23 15:37:40 +08:00
str.go feat(crypt): customize `filename_encoding` (#5148) 2023-09-03 18:06:44 +08:00
time.go fix(189pc): transfer rename (#7958) 2025-02-16 12:21:34 +08:00
url.go fix: different url encoding (close #3423) 2023-02-15 16:20:30 +08:00