Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
np committed Jul 7, 2016
1 parent 5d27900 commit bb34766
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
5 changes: 5 additions & 0 deletions aula.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ library
, vector
, wai
, wai-app-static
, wai-extra
, warp
, yaml
exposed-modules:
Expand Down Expand Up @@ -211,6 +212,7 @@ executable aula-avatars
, vector
, wai
, wai-app-static
, wai-extra
, warp
, yaml
, aula
Expand Down Expand Up @@ -279,6 +281,7 @@ executable aula-html-dummies
, vector
, wai
, wai-app-static
, wai-extra
, warp
, yaml
, aula
Expand Down Expand Up @@ -350,6 +353,7 @@ executable aula-server
, vector
, wai
, wai-app-static
, wai-extra
, warp
, yaml
, aula
Expand Down Expand Up @@ -419,6 +423,7 @@ test-suite spec
, vector
, wai
, wai-app-static
, wai-extra
, warp
, yaml
, aula
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ dependencies:
- vector
- wai
- wai-app-static
- wai-extra
- warp
- yaml

Expand Down
1 change: 1 addition & 0 deletions src/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ modifyCurrentUser ev =
isLoggedIn :: ActionUserHandler m => m Bool
isLoggedIn = userState $ to validLoggedIn

-- TODO this is not checking much?
validLoggedIn :: UserState -> Bool
validLoggedIn us = isJust (us ^. usUserId) && isJust (us ^. usSessionToken)

Expand Down
11 changes: 10 additions & 1 deletion src/Action/Implementation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import qualified Data.ByteString.Lazy as LBS
import qualified Thentos.Frontend.CSRF as CSRF (checkCsrfToken)

import Action
--import Access
import Config
import Logger.EventLog
import Persistent
Expand Down Expand Up @@ -173,7 +174,15 @@ instance ActionAvatar Action where
mkRunAction :: ActionEnv -> Action :~> ExceptT ServantErr IO
mkRunAction env = Nat run
where
run = withExceptT runActionExcept . ExceptT . fmap (view _1) . runRWSTflip env userLoggedOut
handleExns m = ExceptT $ do
(e, s, _) <- m
pure $ e & _Left %~ mayRedirectToLogin s . runActionExcept
-- withExceptT runActionExcept . ExceptT . fmap (view _1) . _H
mayRedirectToLogin :: UserState -> ServantErr -> ServantErr
mayRedirectToLogin _s e = e {-| validLoggedIn s = e
-- | errHTTPCode e == 303 = e
| otherwise = redirectLoginErr-}
run = handleExns . runRWSTflip env userLoggedOut
. runExceptT . unAction . (checkCurrentUser >>)
runRWSTflip r s comp = runRWST comp r s

Expand Down
12 changes: 11 additions & 1 deletion src/Frontend.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import Network.Wai.Application.Static
( StaticSettings
, ssRedirectToIndex, ssAddTrailingSlash, ssGetMimeType, defaultFileServerSettings, staticApp
)
import Network.Wai.Middleware.RequestLogger -- (mkRequestLogger, OutputFormat(..))
import Network.Wai.Middleware.RequestLogger.JSON (formatAsJSON)
import Servant
import System.FilePath (addTrailingPathSeparator)
import Web.Cookie (SetCookie, def, setCookieName, setCookiePath)
Expand All @@ -51,6 +53,7 @@ import Frontend.Testing
import Logger
import Persistent.Api (RunPersist)
import Persistent (withPersist, findUser)
import System.IO

import qualified Action
import qualified Backend
Expand Down Expand Up @@ -97,9 +100,15 @@ runFrontend' cfg log rp = do
. setPort (cfg ^. listenerPort)
$ Warp.defaultSettings

h <- openFile "log.json" AppendMode
reqLogging <- mkRequestLogger def
{ outputFormat = CustomOutputFormatWithDetails formatAsJSON
, destination = Handle h }

runSettings settings
. createPageSamples
. catch404
. catch404 -- TODO
. reqLogging
. serve aulaTopProxy $ aulaTop cfg app


Expand Down Expand Up @@ -432,6 +441,7 @@ aulaAdmin =
postAdminRemRole user = runPostHandler (pure NeedAdmin) . Page.adminRemRole user


-- TODO
catch404 :: Middleware
catch404 app req cont = app req $ \resp -> cont $ f resp
where
Expand Down
1 change: 1 addition & 0 deletions src/Persistent/Pure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ deriveSafeCopy 0 'base ''PersistExcept
runPersistExcept :: PersistExcept -> ServantErr
runPersistExcept (PersistError500 msg) = err500 { errBody = cs msg }
runPersistExcept (PersistError404 msg) = err404 { errBody = cs msg }
-- TODO
runPersistExcept (PersistErrorNotImplemented msg) = err500 { errBody = cs msg }
runPersistExcept (UserLoginInUse li) =
err403 { errBody = "user login in use: " <> cs (show li) }
Expand Down

0 comments on commit bb34766

Please sign in to comment.