feat: add get-user-by-token api

This commit is contained in:
710leo 2021-09-09 23:18:58 +08:00
parent 0d19ec267f
commit 6d24b07573
3 changed files with 18 additions and 5 deletions

View File

@ -209,6 +209,7 @@ func configRoutes(r *gin.Engine) {
v1.GET("/can-do-op-by-name", login(), canDoOpByName)
v1.GET("/can-do-op-by-token", login(), canDoOpByToken)
v1.GET("/get-user-by-name", login(), getUserByName)
v1.GET("/get-user-by-token", login(), getUserByToken)
}
push := r.Group("/v1/n9e/series").Use(gzip.Gzip(gzip.DefaultCompression))

View File

@ -90,8 +90,3 @@ func canDoOpByToken(c *gin.Context) {
can, err := user.CanDo(queryStr(c, "op"))
renderData(c, can, err)
}
func getUserByName(c *gin.Context) {
user, err := models.UserGetByUsername(queryStr(c, "name"))
renderData(c, user, err)
}

View File

@ -178,3 +178,20 @@ func userDel(c *gin.Context) {
func contactChannelsGet(c *gin.Context) {
renderData(c, config.Config.ContactKeys, nil)
}
func getUserByName(c *gin.Context) {
user, err := models.UserGetByUsername(queryStr(c, "name"))
renderData(c, user, err)
}
func getUserByToken(c *gin.Context) {
userToken, err := models.UserTokenGet("token=?", queryStr(c, "token"))
dangerous(err)
if userToken == nil {
renderMessage(c, nil)
return
}
user, err := models.UserGetByUsername(userToken.Username)
renderData(c, user, err)
}