mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: User/Me
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"cloudreve/models"
|
||||
"cloudreve/pkg/serializer"
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gopkg.in/go-playground/validator.v8"
|
||||
)
|
||||
|
||||
@@ -47,3 +49,13 @@ func ErrorResponse(err error) serializer.Response {
|
||||
|
||||
return serializer.ParamErr("参数错误", err)
|
||||
}
|
||||
|
||||
// CurrentUser 获取当前用户
|
||||
func CurrentUser(c *gin.Context) *model.User {
|
||||
if user, _ := c.Get("user"); user != nil {
|
||||
if u, ok := user.(*model.User); ok {
|
||||
return u
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"cloudreve/pkg/serializer"
|
||||
"cloudreve/service/user"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -16,3 +17,11 @@ func UserLogin(c *gin.Context) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// UserMe 获取当前登录的用户
|
||||
func UserMe(c *gin.Context) {
|
||||
user := CurrentUser(c)
|
||||
res := serializer.BuildUserResponse(*user)
|
||||
c.JSON(200, res)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user