diff options
Diffstat (limited to 'src/App.hs')
-rw-r--r-- | src/App.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/App.hs b/src/App.hs index 273bb3951e65..4f02cb4447db 100644 --- a/src/App.hs +++ b/src/App.hs @@ -126,8 +126,15 @@ server T.Config{..} = createAccount liftIO $ Trips.delete dbFile tripPK pure NoContent - listTrips :: Handler [T.Trip] - listTrips = liftIO $ Trips.list dbFile + listTrips :: T.SessionCookie -> Handler [T.Trip] + listTrips cookie = do + mAccount <- liftIO $ Auth.accountFromCookie dbFile cookie + case mAccount of + Nothing -> throwError err401 { errBody = "Your session cookie is invalid. Try logging out and logging back in." } + Just T.Account{..} -> + case accountRole of + T.Admin -> liftIO $ Trips.listAll dbFile + _ -> liftIO $ Trips.list dbFile accountUsername login :: T.AccountCredentials -> Handler (Headers '[Header "Set-Cookie" SetCookie] NoContent) |