add GET /tokens/self

This commit is contained in:
Howl
2016-06-14 12:01:30 +02:00
parent 4d9ec829a8
commit fc38503bdd
4 changed files with 32 additions and 8 deletions

View File

@@ -169,6 +169,26 @@ func TokenGET(md common.MethodData) common.CodeMessager {
return r
}
type tokenSingleResponse struct {
common.ResponseBase
token
}
// TokenSelfGET retrieves information about the token the user is connecting with.
func TokenSelfGET(md common.MethodData) common.CodeMessager {
var r tokenSingleResponse
// md.User.ID = token id, userid would have been md.User.UserID. what a clusterfuck
err := md.DB.QueryRow("SELECT id, privileges, description FROM tokens WHERE id = ?", md.User.ID).Scan(
&r.ID, &r.Privileges, &r.Description,
)
if err != nil {
md.Err(err)
return Err500
}
r.Code = 200
return r
}
// TokenFixPrivilegesGET fixes the privileges on the token of the given user,
// or of all the users if no user is given.
func TokenFixPrivilegesGET(md common.MethodData) common.CodeMessager {