From 4d930c0c8cb585979798fac2bb254f991faa62fb Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Mon, 26 Jun 2023 22:26:10 +0200 Subject: feat: Add initial user setup --- cmd/server/main.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'cmd/server') diff --git a/cmd/server/main.go b/cmd/server/main.go index f58366f..4942ac3 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -72,16 +72,6 @@ func main() { r := router.New() r.GET("/static/{filepath:*}", ext.FileServer(img.StaticFS, "static/")) - authMiddleware := ext.NewAuthMiddleware(hexKey, logger.WithField("context", "auth")) - logMiddleware := ext.NewLogMiddleare(logger.WithField("context", "http")) - - extRouter := ext.NewRouter(r) - extRouter.AddMiddleware(logMiddleware.HTTP) - extRouter.AddMiddleware(authMiddleware.LoggedIn) - extRouter.AddMiddleware(ext.HTML) - - scheduler := worker.NewScheduler(*schedulerCount) - // repository var ( userRepository = sql.NewUserRepository(db) @@ -90,12 +80,24 @@ func main() { mediaRepository = sql.NewMediaRepository(db) ) - //TODO: remove later - userRepository.EnsureAdmin(context.Background()) + // middleware + var ( + authMiddleware = ext.NewAuthMiddleware(hexKey, logger.WithField("context", "auth")) + logMiddleware = ext.NewLogMiddleare(logger.WithField("context", "http")) + initialMiddleware = ext.NewInitialSetupMiddleware(userRepository) + ) + + extRouter := ext.NewRouter(r) + extRouter.AddMiddleware(ext.HTML) + extRouter.AddMiddleware(initialMiddleware.Check) + extRouter.AddMiddleware(authMiddleware.LoggedIn) + extRouter.AddMiddleware(logMiddleware.HTTP) + + scheduler := worker.NewScheduler(*schedulerCount) // controller var ( - userController = auth.NewController(userRepository, hexKey) + userController = auth.NewController(userRepository, userRepository, hexKey) fileSystemController = filesystem.NewController(fileSystemRepository) ) -- cgit v1.2.3