Merge branch 'master' into feature/task-identifier
# Conflicts: # pkg/swagger/docs.go
This commit is contained in:
commit
05eb98c973
|
@ -118,8 +118,10 @@ func RegisterTableStructsForCache(val interface{}) {
|
|||
}
|
||||
|
||||
func initMysqlEngine() (engine *xorm.Engine, err error) {
|
||||
// We're using utf8mb here instead of just utf8 because we want to use non-BMP characters.
|
||||
// See https://stackoverflow.com/a/30074553/10924593 for more info.
|
||||
connStr := fmt.Sprintf(
|
||||
"%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true",
|
||||
"%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true",
|
||||
config.DatabaseUser.GetString(),
|
||||
config.DatabasePassword.GetString(),
|
||||
config.DatabaseHost.GetString(),
|
||||
|
|
|
@ -19,6 +19,7 @@ package v1
|
|||
import (
|
||||
"code.vikunja.io/api/pkg/models"
|
||||
"code.vikunja.io/web/handler"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
"github.com/labstack/echo/v4"
|
||||
"net/http"
|
||||
)
|
||||
|
@ -59,3 +60,36 @@ func Login(c echo.Context) error {
|
|||
|
||||
return c.JSON(http.StatusOK, Token{Token: t})
|
||||
}
|
||||
|
||||
// RenewToken gives a new token to every user with a valid token
|
||||
// If the token is valid is checked in the middleware.
|
||||
// @Summary Renew user token
|
||||
// @Description Returns a new valid jwt user token with an extended length.
|
||||
// @tags user
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} v1.Token
|
||||
// @Failure 400 {object} models.Message "Only user token are available for renew."
|
||||
// @Router /user/token [post]
|
||||
func RenewToken(c echo.Context) error {
|
||||
|
||||
jwtinf := c.Get("user").(*jwt.Token)
|
||||
claims := jwtinf.Claims.(jwt.MapClaims)
|
||||
typ := int(claims["type"].(float64))
|
||||
if typ != AuthTypeUser {
|
||||
return echo.ErrBadRequest
|
||||
}
|
||||
|
||||
user, err := models.GetUserFromClaims(claims)
|
||||
if err != nil {
|
||||
return handler.HandleHTTPError(err, c)
|
||||
}
|
||||
|
||||
// Create token
|
||||
t, err := NewUserJWTAuthtoken(user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, Token{Token: t})
|
||||
}
|
||||
|
|
|
@ -190,6 +190,7 @@ func registerAPIRoutes(a *echo.Group) {
|
|||
a.GET("/user", apiv1.UserShow)
|
||||
a.POST("/user/password", apiv1.UserChangePassword)
|
||||
a.GET("/users", apiv1.UserList)
|
||||
a.POST("/user/token", apiv1.RenewToken)
|
||||
|
||||
listHandler := &handler.WebHandler{
|
||||
EmptyStruct: func() handler.CObject {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
// This file was generated by swaggo/swag at
|
||||
// 2019-12-07 22:51:46.967330871 +0100 CET m=+0.166223609
|
||||
// 2019-12-07 20:29:10.551783293 +0100 CET m=+0.172017440
|
||||
|
||||
package swagger
|
||||
|
||||
|
@ -2649,7 +2649,7 @@ var doc = `{
|
|||
"JWTKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Returns all tasks on any list the user has access to.",
|
||||
"description": "Returns one task by its ID",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
|
@ -2659,53 +2659,27 @@ var doc = `{
|
|||
"tags": [
|
||||
"task"
|
||||
],
|
||||
"summary": "Get tasks",
|
||||
"summary": "Get one task",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "The page number. Used for pagination. If not provided, the first page of results is returned.",
|
||||
"name": "page",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "The maximum number of items per page. Note this parameter is limited by the configured maximum of items per page.",
|
||||
"name": "per_page",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Search tasks by task text.",
|
||||
"name": "s",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The sorting parameter. Possible values to sort by are priority, prioritydesc, priorityasc, duedate, duedatedesc, duedateasc.",
|
||||
"name": "sort",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "The start date parameter to filter by. Expects a unix timestamp. If no end date, but a start date is specified, the end date is set to the current time.",
|
||||
"name": "startdate",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "The end date parameter to filter by. Expects a unix timestamp. If no start date, but an end date is specified, the start date is set to the current time.",
|
||||
"name": "enddate",
|
||||
"in": "query"
|
||||
"description": "The task ID",
|
||||
"name": "ID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "The tasks",
|
||||
"description": "The task",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/models.Task"
|
||||
}
|
||||
"$ref": "#/definitions/models.Task"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Task not found",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.Message"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
|
@ -2775,55 +2749,6 @@ var doc = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/tasks/{ID}": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"JWTKeyAuth": []
|
||||
}
|
||||
],
|
||||
"description": "Returns one task by its ID",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"task"
|
||||
],
|
||||
"summary": "Get one task",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "The task ID",
|
||||
"name": "ID",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "The task",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.Task"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Task not found",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.Message"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.Message"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/tasks/{id}": {
|
||||
"post": {
|
||||
"security": [
|
||||
|
@ -4360,6 +4285,35 @@ var doc = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"/user/token": {
|
||||
"post": {
|
||||
"description": "Returns a new valid jwt user token with an extended length.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Renew user token",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/v1.Token"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Only user token are available for renew.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.Message"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users": {
|
||||
"get": {
|
||||
"security": [
|
||||
|
@ -4527,14 +4481,6 @@ var doc = `{
|
|||
"description": "The unique, numeric id of this task.",
|
||||
"type": "integer"
|
||||
},
|
||||
"identifier": {
|
||||
"description": "The task identifier, based on the list identifier and the task's index",
|
||||
"type": "string"
|
||||
},
|
||||
"index": {
|
||||
"description": "The task index, calculated per list",
|
||||
"type": "integer"
|
||||
},
|
||||
"labels": {
|
||||
"description": "An array of labels which are associated with this task.",
|
||||
"type": "array",
|
||||
|
@ -4717,12 +4663,6 @@ var doc = `{
|
|||
"description": "The unique, numeric id of this list.",
|
||||
"type": "integer"
|
||||
},
|
||||
"identifier": {
|
||||
"description": "The unique list short identifier. Used to build task identifiers.",
|
||||
"type": "string",
|
||||
"maxLength": 10,
|
||||
"minLength": 0
|
||||
},
|
||||
"owner": {
|
||||
"description": "The user who created this list.",
|
||||
"type": "object",
|
||||
|
@ -4954,14 +4894,6 @@ var doc = `{
|
|||
"description": "The unique, numeric id of this task.",
|
||||
"type": "integer"
|
||||
},
|
||||
"identifier": {
|
||||
"description": "The task identifier, based on the list identifier and the task's index",
|
||||
"type": "string"
|
||||
},
|
||||
"index": {
|
||||
"description": "The task index, calculated per list",
|
||||
"type": "integer"
|
||||
},
|
||||
"labels": {
|
||||
"description": "An array of labels which are associated with this task.",
|
||||
"type": "array",
|
||||
|
@ -5070,14 +5002,6 @@ var doc = `{
|
|||
"description": "The unique, numeric id of this task.",
|
||||
"type": "integer"
|
||||
},
|
||||
"identifier": {
|
||||
"description": "The task identifier, based on the list identifier and the task's index",
|
||||
"type": "string"
|
||||
},
|
||||
"index": {
|
||||
"description": "The task index, calculated per list",
|
||||
"type": "integer"
|
||||
},
|
||||
"labels": {
|
||||
"description": "An array of labels which are associated with this task.",
|
||||
"type": "array",
|
||||
|
|
|
@ -4342,6 +4342,35 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/user/token": {
|
||||
"post": {
|
||||
"description": "Returns a new valid jwt user token with an extended length.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Renew user token",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/v1.Token"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Only user token are available for renew.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/models.Message"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/users": {
|
||||
"get": {
|
||||
"security": [
|
||||
|
|
|
@ -3756,6 +3756,25 @@ paths:
|
|||
summary: Request password reset token
|
||||
tags:
|
||||
- user
|
||||
/user/token:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Returns a new valid jwt user token with an extended length.
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/v1.Token'
|
||||
"400":
|
||||
description: Only user token are available for renew.
|
||||
schema:
|
||||
$ref: '#/definitions/models.Message'
|
||||
summary: Renew user token
|
||||
tags:
|
||||
- user
|
||||
/users:
|
||||
get:
|
||||
consumes:
|
||||
|
|
Loading…
Reference in New Issue