User information

This commit is contained in:
Aurélie Delhaie
2022-05-25 13:11:06 +02:00
parent 87957cb2d5
commit d0ee7df3f5
3 changed files with 22 additions and 1 deletions

View File

@@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS `games` (
`name` varchar(255) NOT NULL DEFAULT '0', `name` varchar(255) NOT NULL DEFAULT '0',
`revision` bigint unsigned NOT NULL DEFAULT '0', `revision` bigint unsigned NOT NULL DEFAULT '0',
`path_storage` text NOT NULL, `path_storage` text NOT NULL,
`hash` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL, `hash` varchar(128) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`last_update` datetime DEFAULT NULL, `last_update` datetime DEFAULT NULL,
`user_id` bigint unsigned NOT NULL DEFAULT '0', `user_id` bigint unsigned NOT NULL DEFAULT '0',
`available` tinyint unsigned NOT NULL DEFAULT '0', `available` tinyint unsigned NOT NULL DEFAULT '0',

View File

@@ -221,3 +221,19 @@ func Download(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r) http.NotFound(w, r)
} }
} }
func UserInformation(w http.ResponseWriter, r *http.Request) {
userId, err := userIdFromContext(r.Context())
if err != nil {
internalServerError(w, r)
log.Println(err)
return
}
user, err := database.UserById(userId)
if err != nil {
internalServerError(w, r)
log.Println(err)
return
}
ok(user, w, r)
}

View File

@@ -34,6 +34,11 @@ func Serve() {
} }
r.Route("/system", func(systemRouter chi.Router) { r.Route("/system", func(systemRouter chi.Router) {
systemRouter.Get("/information", Information) systemRouter.Get("/information", Information)
})
r.Route("/user", func(secureRouter chi.Router) {
secureRouter.Use(authMiddleware)
secureRouter.Get("/information", UserInformation)
}) })
r.Route("/game", func(secureRouter chi.Router) { r.Route("/game", func(secureRouter chi.Router) {
secureRouter.Use(authMiddleware) secureRouter.Use(authMiddleware)