Feat: User/Me

This commit is contained in:
HFO4
2019-11-12 15:34:54 +08:00
parent 80f30465e9
commit 589c399488
9 changed files with 148 additions and 17 deletions

View File

@@ -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
}