mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
feat: profile api
This commit is contained in:
parent
94e7e47375
commit
6322c22b49
@ -71,6 +71,7 @@ func routers(r *gin.Engine) {
|
||||
auth.GET("/file", commonHandler(createFM))
|
||||
auth.GET("/ws/file/:id", commonHandler(fmStream))
|
||||
|
||||
auth.GET("/profile", commonHandler(getProfile))
|
||||
auth.GET("/user", commonHandler(listUser))
|
||||
auth.POST("/user", commonHandler(createUser))
|
||||
auth.POST("/batch-delete/user", commonHandler(batchDeleteUser))
|
||||
|
@ -19,6 +19,7 @@ func initParams() *jwt.GinJWTMiddleware {
|
||||
Realm: singleton.Conf.SiteName,
|
||||
Key: []byte(singleton.Conf.JWTSecretKey),
|
||||
CookieName: "nz-jwt",
|
||||
SendCookie: true,
|
||||
Timeout: time.Hour,
|
||||
MaxRefresh: time.Hour,
|
||||
IdentityKey: model.CtxKeyAuthorizedUser,
|
||||
|
@ -7,6 +7,23 @@ import (
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
// Get profile
|
||||
// @Summary Get profile
|
||||
// @Security BearerAuth
|
||||
// @Schemes
|
||||
// @Description Get profile
|
||||
// @Tags auth required
|
||||
// @Produce json
|
||||
// @Success 200 {object} model.CommonResponse[model.User]
|
||||
// @Router /profile [get]
|
||||
func getProfile(c *gin.Context) (*model.User, error) {
|
||||
auth, ok := c.Get(model.CtxKeyAuthorizedUser)
|
||||
if !ok {
|
||||
return nil, singleton.Localizer.ErrorT("unauthorized")
|
||||
}
|
||||
return auth.(*model.User), nil
|
||||
}
|
||||
|
||||
// List user
|
||||
// @Summary List user
|
||||
// @Security BearerAuth
|
||||
|
Loading…
Reference in New Issue
Block a user