on master help sign in
Merge pull request #130 from ilyakooo0/develop

Made tokens actually expire

commite61fa9104d5094ff26684cb42d421910b666d190 authoriko <ilyakooo0@gmail.com> dateSun 12 May 2019, 12:03 (7 years ago) parenta0c811ac050a57
2 files changed+3−2
denis/src/Data/Query.hs+2−1 denis/src/Server/Auth/Token.hs+1−1
denis/src/Data/Query.hs+2−1
@@ -722,7 +722,8 @@ getVerifiedTokenQ :: Query Schema (TuplePG (UserId, ByteString)) (RowPG Token)
722722getVerifiedTokenQ = selectStar (from (table #tokens) &
723723 where_ (#tokenUserId .== param @1 .&&
724724 #tokenValue .== param @2 .&&
725− isNull #tokenVerificationCode))
725+ isNull #tokenVerificationCode .&&
726+ currentTimestamp .< #tokenExpiryDate))
726727
727728-- MARK: FrontEnd Data Structures
728729
denis/src/Server/Auth/Token.hs+1−1
@@ -63,7 +63,7 @@ generateTokenM = do
6363 activationToken <- randomBytes 64
6464 deactivationToken <- randomBytes 64
6565 code <- randomR (0, 999999)
66− expire <- liftIO $ fmap (addUTCTime (nominalDay * 365)) getCurrentTime -- one year
66+ expire <- liftIO $ fmap (addUTCTime (60*30 {- 30 minutes -} {- nominalDay * 365 -})) getCurrentTime -- one year
6767 return $ \ uId ua -> GeneratedToken {
6868 generatedToken = Token uId (hash token) expire (Just . hashVerificationCode $ code) 10 ua (Just . hash $ activationToken) (hash deactivationToken),
6969 generatedTokenValue = token,