Allow access user info via numeric id

This commit is contained in:
LittleSheep 2024-11-17 00:17:56 +08:00
parent f91be512f3
commit 4695a617d7
2 changed files with 40 additions and 35 deletions

View File

@ -4,9 +4,9 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix auth cache"> <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Allow get realm by numeric auto increment id">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/realms.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/realms.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/http/api/userinfo_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/http/api/userinfo_api.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -45,35 +45,35 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"DefaultGoTemplateProperty": "Go File", &quot;DefaultGoTemplateProperty&quot;: &quot;Go File&quot;,
"Go Build.Backend.executor": "Debug", &quot;Go Build.Backend.executor&quot;: &quot;Debug&quot;,
"Go 构建.Backend.executor": "Run", &quot;Go 构建.Backend.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.git.unshallow": "true", &quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
"RunOnceActivity.go.formatter.settings.were.checked": "true", &quot;RunOnceActivity.go.formatter.settings.were.checked&quot;: &quot;true&quot;,
"RunOnceActivity.go.migrated.go.modules.settings": "true", &quot;RunOnceActivity.go.migrated.go.modules.settings&quot;: &quot;true&quot;,
"RunOnceActivity.go.modules.automatic.dependencies.download": "true", &quot;RunOnceActivity.go.modules.automatic.dependencies.download&quot;: &quot;true&quot;,
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true", &quot;RunOnceActivity.go.modules.go.list.on.any.changes.was.set&quot;: &quot;true&quot;,
"git-widget-placeholder": "master", &quot;git-widget-placeholder&quot;: &quot;master&quot;,
"go.import.settings.migrated": "true", &quot;go.import.settings.migrated&quot;: &quot;true&quot;,
"go.sdk.automatically.set": "true", &quot;go.sdk.automatically.set&quot;: &quot;true&quot;,
"last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hypernet/Passport", &quot;last_opened_file_path&quot;: &quot;/Users/littlesheep/Documents/Projects/Hypernet/Passport&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"run.code.analysis.last.selected.profile": "pProject Default", &quot;run.code.analysis.last.selected.profile&quot;: &quot;pProject Default&quot;,
"settings.editor.selected.configurable": "preferences.intentionPowerPack", &quot;settings.editor.selected.configurable&quot;: &quot;preferences.intentionPowerPack&quot;,
"ts.external.directory.path": "/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/node_modules/typescript/lib", &quot;ts.external.directory.path&quot;: &quot;/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/node_modules/typescript/lib&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}, },
"keyToStringList": { &quot;keyToStringList&quot;: {
"DatabaseDriversLRU": [ &quot;DatabaseDriversLRU&quot;: [
"postgresql" &quot;postgresql&quot;
] ]
} }
}]]></component> }</component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/keys" /> <recent name="$PROJECT_DIR$/keys" />
@ -159,7 +159,6 @@
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /> <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<MESSAGE value=":alien: Support better metadata encoder / decoder" />
<MESSAGE value=":bug: Bug fixes on compile time" /> <MESSAGE value=":bug: Bug fixes on compile time" />
<MESSAGE value=":bug: Fix notification order" /> <MESSAGE value=":bug: Fix notification order" />
<MESSAGE value=":bug: Fix notification order... again" /> <MESSAGE value=":bug: Fix notification order... again" />
@ -184,7 +183,8 @@
<MESSAGE value=":sparkles: Authkit support check user related permission" /> <MESSAGE value=":sparkles: Authkit support check user related permission" />
<MESSAGE value=":sparkles: Authkit can get user" /> <MESSAGE value=":sparkles: Authkit can get user" />
<MESSAGE value=":bug: Fix auth cache" /> <MESSAGE value=":bug: Fix auth cache" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix auth cache" /> <MESSAGE value=":sparkles: Allow get realm by numeric auto increment id" />
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: Allow get realm by numeric auto increment id" />
<option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" /> <option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">

View File

@ -3,8 +3,8 @@ package api
import ( import (
"fmt" "fmt"
"git.solsynth.dev/hypernet/passport/pkg/authkit/models" "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
"github.com/spf13/viper"
"gorm.io/gorm" "gorm.io/gorm"
"strconv"
"strings" "strings"
"git.solsynth.dev/hypernet/passport/pkg/internal/database" "git.solsynth.dev/hypernet/passport/pkg/internal/database"
@ -15,13 +15,18 @@ import (
func getOtherUserinfo(c *fiber.Ctx) error { func getOtherUserinfo(c *fiber.Ctx) error {
alias := c.Params("alias") alias := c.Params("alias")
tx := database.C.Where("name = ?")
numericId, err := strconv.Atoi(alias)
if err == nil {
tx = tx.Where("id = ?", numericId)
}
var account models.Account var account models.Account
if err := database.C. if err := tx.
Where(&models.Account{Name: alias}).
Preload("Profile"). Preload("Profile").
Preload("Badges", func(db *gorm.DB) *gorm.DB { Preload("Badges", func(db *gorm.DB) *gorm.DB {
prefix := viper.GetString("database.prefix") return db.Order("badges.type DESC")
return db.Order(fmt.Sprintf("%sbadges.type DESC", prefix))
}). }).
First(&account).Error; err != nil { First(&account).Error; err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error()) return fiber.NewError(fiber.StatusBadRequest, err.Error())