on master help sign in
Merge pull request #104 from ilyakooo0/develop
54a2ebfiko
denis/src/Data/Query.hs+1−1
@@ -589,7 +589,7 @@ updateTokenQ :: Manipulation Schema (TuplePG Token) '[]
589updateTokenQ = update_ #tokens (
589updateTokenQ = update_ #tokens (
590 Same `as` #tokenUserId :*
590 Same `as` #tokenUserId :*
591 Same `as` #tokenValue :*
591 Same `as` #tokenValue :*
592− Same `as` #tokenExpiryDate :*
592+ Set (param @3) `as` #tokenExpiryDate :*
593 Set (param @4) `as` #tokenVerificationCode :*
593 Set (param @4) `as` #tokenVerificationCode :*
594 Set (param @5) `as` #tokenActivationTriesLeft)
594 Set (param @5) `as` #tokenActivationTriesLeft)
595 (#tokenUserId .== param @1 .&& #tokenValue .== param @2)
595 (#tokenUserId .== param @1 .&& #tokenValue .== param @2)
denis/src/Server/Auth.hs+5−3
@@ -71,7 +71,7 @@ type LoginDescription = Description "Try to log in with the given email\n\nRespo
71
71
72type LogoutDescription = Description "Log out with the given cookie"
72type LogoutDescription = Description "Log out with the given cookie"
73
73
74−type VerifyDescription = Description "Verify token with the verification code from the user.\n\nReturns 400 if the token was not supplied.\n\nReturns 498 if the token was parsed but is invalid.\n\n"
74+type VerifyDescription = Description "Verify token with the verification code from the user.\n\nReturns 400 if the token was not supplied.\n\nReturns 498 if the token was parsed but is invalid.\n\nRetusn 403 if the token/code compination is invalid."
75
75
76type RegisterDescription = Description "Register the user for a new account.\n\nReturns 409 if a user can not be created. (Most likely the email is already registered).\n\nSets the token if creation was successful.\n\nYou should prompt user for code and verify the token with `/verify`."
76type RegisterDescription = Description "Register the user for a new account.\n\nReturns 409 if a user can not be created. (Most likely the email is already registered).\n\nSets the token if creation was successful.\n\nYou should prompt user for code and verify the token with `/verify`."
77
77
@@ -159,8 +159,10 @@ verifyToken (Just cookie) code = do
159 case mbToken of
159 case mbToken of
160 Nothing -> throwError err400
160 Nothing -> throwError err400
161 (Just (AuthenticationCookieData uId tokenData)) -> do
161 (Just (AuthenticationCookieData uId tokenData)) -> do
162− _ <- runQ invalidToken $ tryVerifyToken uId tokenData code
162+ token <- runQ invalidToken $ tryVerifyToken uId tokenData code
163+ case token of
163− return NoContent
164+ Just _ -> return NoContent
165+ Nothing -> throwError err403
164
166
165logOut :: Maybe String -> App (Headers '[Header "Set-Cookie" String] NoContent)
167logOut :: Maybe String -> App (Headers '[Header "Set-Cookie" String] NoContent)
166logOut cookie' = do
168logOut cookie' = do
denis/src/Server/Auth/Token.hs+1−1
@@ -33,7 +33,7 @@ data Token = Token {
33 tokenExpiryDate :: UTCTime,
33 tokenExpiryDate :: UTCTime,
34 tokenVerificationCode :: Maybe TokenVerificationCode,
34 tokenVerificationCode :: Maybe TokenVerificationCode,
35 tokenActivationTriesLeft :: Int32
35 tokenActivationTriesLeft :: Int32
36−} deriving (GHC.Generic, SOP.Generic, SOP.HasDatatypeInfo)
36+} deriving (Show, GHC.Generic, SOP.Generic, SOP.HasDatatypeInfo)
37
37
38generateToken :: (MonadIO m, CryptoRNG m) => UserId -> m Token
38generateToken :: (MonadIO m, CryptoRNG m) => UserId -> m Token
39generateToken uId = do
39generateToken uId = do