mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
- Introduced environment variables for database and email configurations. - Implemented email verification code generation and validation. - Added password reset feature with email verification. - Updated user registration and profile management APIs. - Refactored user security settings to include email and password updates. - Enhanced console layout with internationalization support. - Removed deprecated settings page and integrated global settings. - Added new reset password page and form components. - Updated localization files for new features and translations.
33 lines
711 B
Go
33 lines
711 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
|
|
}
|