Add /api/v1/tokens/self/delete
This commit is contained in:
parent
a9b82f99b5
commit
52d7b65493
@ -24,6 +24,7 @@ func Start(conf common.Conf, dbO *sql.DB) *gin.Engine {
|
|||||||
gv1 := api.Group("/v1")
|
gv1 := api.Group("/v1")
|
||||||
{
|
{
|
||||||
gv1.POST("/tokens/new", Method(v1.TokenNewPOST))
|
gv1.POST("/tokens/new", Method(v1.TokenNewPOST))
|
||||||
|
gv1.GET("/tokens/self/delete", Method(v1.TokenSelfDeleteGET))
|
||||||
|
|
||||||
// Auth-free API endpoints
|
// Auth-free API endpoints
|
||||||
gv1.GET("/ping", Method(v1.PingGET))
|
gv1.GET("/ping", Method(v1.PingGET))
|
||||||
|
@ -123,3 +123,17 @@ func TokenNewPOST(md common.MethodData) common.CodeMessager {
|
|||||||
r.Code = 200
|
r.Code = 200
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TokenSelfDeleteGET deletes the token the user is connecting with.
|
||||||
|
func TokenSelfDeleteGET(md common.MethodData) common.CodeMessager {
|
||||||
|
if md.ID() == 0 {
|
||||||
|
return common.SimpleResponse(400, "How should we delete your token if you haven't even given us one?!")
|
||||||
|
}
|
||||||
|
_, err := md.DB.Exec("DELETE FROM tokens WHERE token = ? LIMIT 1",
|
||||||
|
fmt.Sprintf("%x", md5.Sum([]byte(md.User.Value))))
|
||||||
|
if err != nil {
|
||||||
|
md.Err(err)
|
||||||
|
return Err500
|
||||||
|
}
|
||||||
|
return common.SimpleResponse(200, "Bye!")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user