From 3a5cb7c5ac3de77b28d506fe6e42c563f09b8bf0 Mon Sep 17 00:00:00 2001 From: nek0 Date: Mon, 14 Oct 2019 17:39:28 +0200 Subject: [PATCH] do not ask for user id, it comes from auth anyway --- src/API.hs | 3 +-- src/Control/User.hs | 15 ++++----------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/API.hs b/src/API.hs index 7ef3dc6..2599e42 100644 --- a/src/API.hs +++ b/src/API.hs @@ -33,8 +33,7 @@ type MateAPI = :> ReqBody '[JSON] Int :> Delete '[JSON] () :<|> "user" :> ReqBody '[JSON] UserSubmit :> Post '[JSON] Int - :<|> "user" :> AuthProtect "header-auth" - :> Capture "uid'" Int :> Get '[JSON] UserDetails + :<|> "user" :> AuthProtect "header-auth" :> Get '[JSON] UserDetails :<|> "user" :> AuthProtect "header-auth" :> ReqBody '[JSON] UserDetailsSubmit :> Patch '[JSON] () :<|> "user" :> "list" :> QueryParam "refine" UserRefine :> Get '[JSON] [UserSummary] diff --git a/src/Control/User.hs b/src/Control/User.hs index 5b14bd3..34b1be1 100644 --- a/src/Control/User.hs +++ b/src/Control/User.hs @@ -32,21 +32,14 @@ userNew (UserSubmit ident email passhash) = do userGet :: Maybe (Int, AuthMethod) - -> Int -> MateHandler UserDetails -userGet Nothing _ = +userGet Nothing = throwError $ err401 { errBody = "No Authentication present." } -userGet (Just (aid, method)) uid = - if aid == uid && any (== method) [PrimaryPass, ChallengeResponse] - then do - conn <- rsConnection <$> ask - userDetailsSelect uid conn - else - throwError $ err401 - { errBody = "Wrong Authentication present." - } +userGet (Just (uid, _)) = do + conn <- rsConnection <$> ask + userDetailsSelect uid conn userUpdate :: Maybe (Int, AuthMethod)