feat(auth): 添加用户存储服务实现

- 实现了基于内存的用户存储服务
- 支持通过ID和名称查找用户
- 注册了用户存储服务的单例模式
- 添加了基础用户数据初始化逻辑
This commit is contained in:
2025-11-09 18:32:25 +08:00
parent 0c5447eb39
commit 9fdfcdd6e7

View File

@@ -0,0 +1,36 @@
package auth
import (
"platform/authorization/identity"
"platform/services"
"strings"
)
func RegisterUserStoreService() {
err := services.AddSingleton(func() identity.UserStore {
return &userStore{}
})
if err != nil {
panic(err)
}
}
var users = map[int]identity.User{
1: identity.NewBasicUser(1, "Alice", "Administrator"),
}
type userStore struct{}
func (store *userStore) GetUserById(id int) (identity.User, bool) {
user, found := users[id]
return user, found
}
func (store *userStore) GetUserByName(name string) (identity.User, bool) {
for _, user := range users {
if strings.EqualFold(user.GetDisplayName(), name) {
return user, true
}
}
return nil, false
}