feat: return full token when creating one

This commit is contained in:
kolaente 2021-12-12 18:30:59 +01:00
parent f6c7653278
commit a911b53e9e
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 3 additions and 9 deletions

View File

@ -27,10 +27,6 @@ import (
"github.com/labstack/echo/v4"
)
type TokenResponse struct {
Token string `json:"token"`
}
// GenerateCaldavToken is the handler to create a caldav token
// @Summary Generate a caldav token
// @Description Generates a caldav token which can be used for the caldav api. It is not possible to see the token again after it was generated.
@ -38,7 +34,7 @@ type TokenResponse struct {
// @Accept json
// @Produce json
// @Security JWTKeyAuth
// @Success 200 {object} v1.TokenResponse
// @Success 200 {object} user.Token
// @Failure 400 {object} web.HTTPError "Something's invalid."
// @Failure 404 {object} web.HTTPError "User does not exist."
// @Failure 500 {object} models.Message "Internal server error."
@ -55,9 +51,7 @@ func GenerateCaldavToken(c echo.Context) (err error) {
return handler.HandleHTTPError(err, c)
}
return c.JSON(http.StatusCreated, &TokenResponse{
Token: token.ClearTextToken,
})
return c.JSON(http.StatusCreated, token)
}
// GetCaldavTokens is the handler to return a list of all caldav tokens for the current user

View File

@ -44,7 +44,7 @@ type Token struct {
ID int64 `xorm:"bigint autoincr not null unique pk" json:"id"`
UserID int64 `xorm:"not null" json:"-"`
Token string `xorm:"varchar(450) not null index" json:"-"`
ClearTextToken string `xorm:"-" json:"-"`
ClearTextToken string `xorm:"-" json:"token"`
Kind TokenKind `xorm:"not null" json:"-"`
Created time.Time `xorm:"created not null" json:"created"`
}