✨ 新增几大中心功能
This commit is contained in:
37
server/api/v1/app/app_auth.go
Normal file
37
server/api/v1/app/app_auth.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.echol.cn/loser/Go-Web-Template/server/global"
|
||||
appModel "git.echol.cn/loser/Go-Web-Template/server/model/app"
|
||||
"git.echol.cn/loser/Go-Web-Template/server/model/common/response"
|
||||
"git.echol.cn/loser/Go-Web-Template/server/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type AppAuthApi struct{}
|
||||
|
||||
func (a *AppAuthApi) Me(c *gin.Context) {
|
||||
uid := utils.GetUserID(c)
|
||||
if uid == 0 {
|
||||
response.NoAuth("未登录或非法访问,请登录", c)
|
||||
return
|
||||
}
|
||||
var user appModel.AppUser
|
||||
if err := global.GVA_DB.First(&user, uid).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
response.NoAuth("用户不存在", c)
|
||||
return
|
||||
}
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(gin.H{
|
||||
"id": user.ID,
|
||||
"uuid": user.UUID,
|
||||
"username": user.Username,
|
||||
"enable": user.Enable,
|
||||
}, c)
|
||||
}
|
||||
Reference in New Issue
Block a user