on master help sign in
Closes #92
commit88acccbfcaa5f5248e5384d623d93acea7dc87f9 authoriko <ilyakooo0@gmail.com> dateSun 12 May 2019, 13:16 (7 years ago) parent974b5e1
2 files changed+17−2
denis/src/Data/Query.hs+8−1 denis/src/Server/API.hs+9−1
denis/src/Data/Query.hs+8−1
@@ -59,7 +59,8 @@ module Data.Query (
5959 searchUsers,
6060 searchTags,
6161 updateUser,
62− UserUpdateRow(..)
62+ UserUpdateRow(..),
63+ killAllTokens
6364 ) where
6465
6566import Squeal.PostgreSQL
@@ -737,6 +738,10 @@ getVerifiedTokenQ = selectStar (from (table #tokens) &
737738 isNull #tokenVerificationCode .&&
738739 currentTimestamp .< #tokenExpiryDate))
739740
741+killAllTokensQ :: Manipulation Schema (TuplePG (Only UserId)) '[]
742+killAllTokensQ = deleteFrom_ #tokens
743+ (#tokenUserId .== param @1)
744+
740745-- MARK: FrontEnd Data Structures
741746
742747data UserCreation = UserCreation {
@@ -1031,6 +1036,8 @@ searchTags query = map fromOnly <$>
10311036createToken :: Token -> StaticPQ ()
10321037createToken token = void $ manipulateParams createTokenQ token
10331038
1039+killAllTokens :: UserId -> StaticPQ ()
1040+killAllTokens = void . manipulateParams killAllTokensQ . Only
10341041
10351042-- NOTE: Not transactional
10361043validateToken :: Token -> StaticPQ ()
denis/src/Server/API.hs+9−1
@@ -46,6 +46,8 @@ type UserSearchDescription = Description "Searches for users with the given stri
4646
4747type UpdateUserDescription = Description "Updates the current user.\n\nThrow 401 if you try to change email or something like that."
4848
49+type DeactivateAllDescription = Description "Deactivates all tokens for the logged in user including the one used to authenticate this request."
50+
4951-- MARK: Implementation
5052
5153type Authentication = AuthProtect "basicAuth"
@@ -55,6 +57,8 @@ type API =
5557 "authentication" :> AuthenticationHandler :<|>
5658 Authentication :> ComplexQuery :> (
5759 "authentication" :> "me" :> Post '[JSON] UserId :<|>
60+ "deactivateAll" :> DeactivateAllDescription
61+ :> DeleteNoContent '[JSON, PlainText, FormUrlEncoded] NoContent :<|>
5862 "users" :> ReqBody '[JSON] [UserId] :> Post '[JSON] [User Faculty] :<|>
5963 "users" :> "all" :> Post '[JSON] [User Faculty] :<|>
6064 "users" :> "search" :> UserSearchDescription :> ReqBody '[JSON, PlainText] Text :> Post '[JSON] [User Faculty] :<|>
@@ -74,6 +78,7 @@ mkServerAPI l =
7478 l :<|>
7579 authenticationAPI :<|> (\uId ->
7680 return uId :<|>
81+ deactivateApi uId :<|>
7782 maybeNotFound . runQnotFound . getUsers :<|>
7883 runQerror getAllUsers :<|>
7984 runQerror . searchUsers :<|>
@@ -96,4 +101,7 @@ updateUserApi uId UserUpdate{..} = do
96101 }
97102 if isJust res
98103 then return NoContent
99− else throwError err401
104+ else throwError err401
105+
106+deactivateApi :: UserId -> App NoContent
107+deactivateApi uId = runQerror (killAllTokens uId) >> return NoContent