diff --git a/api/api.go b/api/api.go index e3c9340..d82ddc4 100755 --- a/api/api.go +++ b/api/api.go @@ -70,7 +70,7 @@ type ViewData struct { } const ( - Version = "1.1.1" + Version = "1.1.2" DefaultPaginationStart = 0 DefaultPaginationLimit = 30 DefaultSort = "desc" @@ -163,7 +163,7 @@ func NewAPI(conf *config.Config, s service.Service, configFile string) *API { adminGroup.DELETE("/users", api.adminDeleteUser) adminGroup.GET("/users/:id", api.adminGetUser) adminGroup.PUT("/users/:id", api.adminUpdateUser) - adminGroup.POST("/users/rotate", api.adminRotateUserToken) + adminGroup.GET("/users/:id/rotate", api.adminRotateUserToken) adminGroup.GET("/logout", api.adminLogout) adminGroup.GET("/settings", api.adminGetSettings) adminGroup.POST("/settings", api.adminUpdateSettings) @@ -176,7 +176,7 @@ func NewAPI(conf *config.Config, s service.Service, configFile string) *API { // Documentation url := echoSwagger.URL("swagger.json") - api.HTTP.Static("/docs/swagger.json", "./docs/swagger.json") + api.HTTP.File("/docs/swagger.json", "docs/swagger.json") api.HTTP.GET("/docs/*", echoSwagger.EchoWrapHandler(url)) // Chains @@ -428,20 +428,20 @@ func (api *API) adminUpdateUser(c echo.Context) error { func (api *API) adminRotateUserToken(c echo.Context) error { - req := &model.User{} - - // bind input data - if err := c.Bind(req); err != nil { - return api.ErrorResponse(errors.New(errors.BindDataError, err), c) + userID, err := strconv.Atoi(c.Param("id")) + if err != nil { + return api.ErrorResponse(errors.New(errors.ValidationError, err), c) } - req.AccessToken = req.GenerateAccessToken(AccessTokenLength) + user := api.service.GetUser(&model.User{ID: userID}) + + user.AccessToken = user.GenerateAccessToken(AccessTokenLength) - if err := api.service.UpdateUser(req); err != nil { + if err := api.service.UpdateUser(user); err != nil { return api.ErrorResponse(errors.New(errors.ServiceError, err), c) } - return api.SuccessResponse(req, c) + return api.SuccessResponse(user, c) } diff --git a/ui/src/components/admin/Users.js b/ui/src/components/admin/Users.js index 4576cc7..dd924f8 100644 --- a/ui/src/components/admin/Users.js +++ b/ui/src/components/admin/Users.js @@ -92,7 +92,7 @@ const Users = () => { const rotateToken = user => { axios - .post('/admin/users/rotate', { id: user.id }) + .get('/admin/users/' + user.id + '/rotate') .then(function(response) { const array = [...users]; const index = array.findIndex(v => v.id === user.id); @@ -245,7 +245,7 @@ const Users = () => { cancelText="No" > - +  Rotate token