aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-26 22:26:10 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-26 22:40:16 +0200
commit4d930c0c8cb585979798fac2bb254f991faa62fb (patch)
tree0c33e0e0f2a2f47b0f64843f7d9a3eb299abb260 /cmd
parentd4e1ca3a48e74573df6965ceee217e119ff899ae (diff)
downloadlens-4d930c0c8cb585979798fac2bb254f991faa62fb.tar.gz
lens-4d930c0c8cb585979798fac2bb254f991faa62fb.tar.bz2
lens-4d930c0c8cb585979798fac2bb254f991faa62fb.zip
feat: Add initial user setup
Diffstat (limited to 'cmd')
-rw-r--r--cmd/server/main.go28
1 files changed, 15 insertions, 13 deletions
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)
)