diff --git a/src/Gargantext/API/Admin/Auth.hs b/src/Gargantext/API/Admin/Auth.hs index c05a0f452fb22693058aa350747fde3fbc9d024a..a9782d04e1fc128fdf448efeab3d476b90c8c583 100644 --- a/src/Gargantext/API/Admin/Auth.hs +++ b/src/Gargantext/API/Admin/Auth.hs @@ -70,7 +70,7 @@ checkAuthRequest u (GargPassword p) = do candidate <- head <$> getUsersWith u case candidate of Nothing -> pure InvalidUser - Just (UserLight _id _u _email h) -> + Just (UserLight id _u _email h) -> case Auth.checkPassword (Auth.mkPassword p) (Auth.PasswordHash h) of Auth.PasswordCheckFail -> pure InvalidPassword Auth.PasswordCheckSuccess -> do @@ -79,7 +79,7 @@ checkAuthRequest u (GargPassword p) = do Nothing -> pure InvalidUser Just uid -> do token <- makeTokenForUser uid - pure $ Valid token uid + pure $ Valid token uid id auth :: (HasSettings env, HasConnectionPool env, HasJoseError err, HasConfig env, HasMail env) => AuthRequest -> Cmd' env err AuthResponse @@ -88,7 +88,7 @@ auth (AuthRequest u p) = do case checkAuthRequest' of InvalidUser -> pure $ AuthResponse Nothing (Just $ AuthInvalid "Invalid user") InvalidPassword -> pure $ AuthResponse Nothing (Just $ AuthInvalid "Invalid password") - Valid to trId -> pure $ AuthResponse (Just $ AuthValid to trId) Nothing + Valid to trId uId -> pure $ AuthResponse (Just $ AuthValid to trId uId) Nothing --type instance BasicAuthCfg = BasicAuthData -> IO (AuthResult AuthenticatedUser) diff --git a/src/Gargantext/API/Admin/Auth/Types.hs b/src/Gargantext/API/Admin/Auth/Types.hs index f859bc9adbea2e3820bee440b43d2e9c369167dd..66295868549bd5f7b0e62b067b99925e6185ea54 100644 --- a/src/Gargantext/API/Admin/Auth/Types.hs +++ b/src/Gargantext/API/Admin/Auth/Types.hs @@ -23,7 +23,7 @@ import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary) import Gargantext.Core.Types.Individu (Username, GargPassword(..), arbitraryUsername, arbitraryPassword) import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger) -import Gargantext.Database.Admin.Types.Node (NodeId(..), ListId, DocId) +import Gargantext.Database.Admin.Types.Node (NodeId(..), ListId, DocId, UserId) import Gargantext.Prelude hiding (reverse) --------------------------------------------------- @@ -45,13 +45,14 @@ data AuthInvalid = AuthInvalid { _authInv_message :: Text } data AuthValid = AuthValid { _authVal_token :: Token , _authVal_tree_id :: TreeId + , _authVal_user_id :: UserId } deriving (Generic) type Token = Text type TreeId = NodeId -data CheckAuth = InvalidUser | InvalidPassword | Valid Token TreeId +data CheckAuth = InvalidUser | InvalidPassword | Valid Token TreeId UserId deriving (Eq) newtype AuthenticatedUser = AuthenticatedUser @@ -99,9 +100,10 @@ $(deriveJSON (unPrefix "_authVal_") ''AuthValid) instance ToSchema AuthValid where declareNamedSchema = genericDeclareNamedSchema (unPrefixSwagger "_authVal_") instance Arbitrary AuthValid where - arbitrary = elements [ AuthValid to tr + arbitrary = elements [ AuthValid to tr u | to <- ["token0", "token1"] , tr <- [1..3] + , u <- [1..3] ] data PathId = PathNode NodeId | PathNodeNode ListId DocId \ No newline at end of file