From a580138e0d82e248d09ba2c906ad36a464c4ab88 Mon Sep 17 00:00:00 2001 From: Mats Rauhala Date: Wed, 29 Aug 2018 23:34:19 +0300 Subject: [PATCH] wip --- backend/src/Database/Schema.hs | 3 --- backend/src/Server/Auth.hs | 15 +-------------- common/common.cabal | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/backend/src/Database/Schema.hs b/backend/src/Database/Schema.hs index 598abdb..c329789 100644 --- a/backend/src/Database/Schema.hs +++ b/backend/src/Database/Schema.hs @@ -18,9 +18,6 @@ newtype PlainPassword = PlainPassword Text deriving (Show, ToJSON, FromJSON, ToH newtype HashedPassword = HashedPassword {unHashed :: ByteString} data NoPassword = NoPassword -newtype Email = Email { unEmail :: Text } deriving (Show, ToJSON, FromJSON, ToHttpApiData, FromHttpApiData) - -newtype Username = Username { unUsername :: Text } deriving (Show, ToJSON, FromJSON, ToHttpApiData, FromHttpApiData) instance SqlType HashedPassword where mkLit = LCustom . LBlob . unHashed diff --git a/backend/src/Server/Auth.hs b/backend/src/Server/Auth.hs index d6ef079..19db528 100644 --- a/backend/src/Server/Auth.hs +++ b/backend/src/Server/Auth.hs @@ -24,21 +24,8 @@ import Control.Lens (view) import Data.Generics.Product import Servant (err401) import Control.Monad.Logger +import Auth (SafeUser(..)) --- generic-lens can convert similar types to this --- I'm trying out servant-auth-server which uses a jwt style login. IIRC anyone --- can open the jwt token and view what's inside, you just can't modify it. --- --- Is it a problem that a human readable username and email are visible? -data SafeUser = SafeUser { email :: Email - , username :: Username - , role :: Role } - deriving (Show, Generic) - -instance ToJSON SafeUser where -instance FromJSON SafeUser where -instance ToJWT SafeUser where -instance FromJWT SafeUser where type instance BasicAuthCfg = BasicAuthData -> IO (AuthResult SafeUser) diff --git a/common/common.cabal b/common/common.cabal index fe763b6..ac9db0c 100644 --- a/common/common.cabal +++ b/common/common.cabal @@ -15,14 +15,27 @@ cabal-version: >=1.10 library exposed-modules: Configuration , Data.Versioned + , API + , API.Books + , API.Catalogue + , API.Channels + , API.Users + , Auth -- other-extensions: build-depends: base >=4.10 && <4.11 + , aeson , classy-prelude , dhall , foreign-store , generic-lens , lens , mtl + , servant + , servant-auth + , servant-auth-server + , servant-docs + , servant-lucid + , servant-multipart , text , transformers hs-source-dirs: src @@ -30,4 +43,6 @@ library , NoImplicitPrelude , OverloadedStrings , RecordWildCards + , TypeOperators + , DataKinds default-language: Haskell2010