Files
neo-blog/internal/ctxutils/user.go
Snowykami 9ca307f4d9 ️ feat: add main page layout with navigation and footer
feat: create random labels page

feat: implement login page with OpenID Connect support

feat: add Gravatar component for user avatars

feat: create Navbar component with navigation menu

chore: create Sidebar component placeholder

feat: implement login form with OIDC and email/password options

feat: add reusable button component

feat: create card component for structured content display

feat: implement input component for forms

feat: create label component for form labels

feat: add navigation menu component for site navigation

chore: add configuration file for site metadata

feat: implement device context for responsive design

feat: add utility functions for class name management

feat: define OIDC configuration model

feat: define base response model for API responses

feat: define user model for user data

feat: implement i18n for internationalization support

feat: add English and Chinese translations for login

chore: create index for locale resources

chore: add blog home view placeholder
2025-07-24 09:22:50 +08:00

29 lines
601 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ctxutils
import (
"context"
"github.com/snowykami/neo-blog/internal/model"
"github.com/snowykami/neo-blog/internal/repo"
)
func GetCurrentUser(ctx context.Context) *model.User {
userIDValue := ctx.Value("user_id").(uint)
if userIDValue <= 0 {
return nil
}
user, err := repo.User.GetUserByID(userIDValue)
if err != nil || user == nil || user.ID == 0 {
return nil
}
return user
}
// GetCurrentUserID 获取当前用户ID如果未认证则返回0
func GetCurrentUserID(ctx context.Context) uint {
user := GetCurrentUser(ctx)
if user == nil {
return 0
}
return user.ID
}