summaryrefslogtreecommitdiff
path: root/fig-web/src/Fig/Web/Auth.hs
blob: 5017b3e8177380d2b13c08b376ba2d84e4cb1a05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module Fig.Web.Auth
  ( Credentials(..)
  , authed
  ) where

import Fig.Prelude

import qualified Web.Scotty as Sc

import Fig.Web.Types
import Fig.Web.Utils

data Credentials = Credentials
  { user :: Text
  , email :: Text
  }
authed :: SecureModuleArgs -> (Credentials -> Sc.ActionM ()) -> Sc.ActionM ()
authed args h = do
  muser <- header "Remote-User"
  memail <- header "Remote-Email"
  case (muser, memail) of
    (Just user, Just email) -> do
      let auth = Credentials{..}
      h auth
    _else -> do
      status status401
      respondText "you're not logged in buddy (this is probably a bug, go message clonk)"