mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
- Introduced new CSS files for rose, violet, and yellow themes with custom color variables. - Implemented dark mode styles for each theme. - Created a color data structure to manage theme colors in the console settings. feat: implement image cropper component - Added an image cropper component for user profile picture editing. - Integrated the image cropper into the user profile page. feat: enhance console sidebar with user permissions - Defined sidebar items with permission checks for admin and editor roles. - Updated user center navigation to reflect user permissions. feat: add user profile and security settings - Developed user profile page with avatar upload and editing functionality. - Implemented user security settings for password and email verification. feat: create reusable dialog and OTP input components - Built a dialog component for modal interactions. - Developed an OTP input component for email verification. fix: improve file handling utilities - Added utility functions for file URI generation. - Implemented permission checks for user roles in the common utilities.
34 lines
733 B
Go
34 lines
733 B
Go
package ctxutils
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/snowykami/neo-blog/internal/model"
|
|
"github.com/snowykami/neo-blog/internal/repo"
|
|
"github.com/snowykami/neo-blog/pkg/constant"
|
|
)
|
|
|
|
// GetCurrentUser 从上下文中获取当前用户
|
|
func GetCurrentUser(ctx context.Context) (*model.User, bool) {
|
|
val := ctx.Value(constant.ContextKeyUserID)
|
|
if val == nil {
|
|
return nil, false
|
|
}
|
|
user, err := repo.User.GetUserByID(val.(uint))
|
|
if err != nil {
|
|
return nil, false
|
|
}
|
|
|
|
return user, true
|
|
}
|
|
|
|
// GetCurrentUserID 从上下文中获取当前用户ID
|
|
func GetCurrentUserID(ctx context.Context) (uint, bool) {
|
|
user, ok := GetCurrentUser(ctx)
|
|
if !ok || user == nil {
|
|
return 0, false
|
|
}
|
|
|
|
return user.ID, true
|
|
}
|