From e9085d6b9e60e610dd14bec83b2834b814afbba2 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 25 Jul 2022 12:29:02 -0500 Subject: [PATCH] Fix PIN generator --- CHANGELOG.md | 1 + src/User.hs | 6 +++--- src/ZGoBackend.hs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4d4e29..28861f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed the PIN generation - Fixed calculation of order total to ensure 8 decimal places - Fixed test for looking for an order with incorrect ID - Fixed payment scan to focus only on new transactions diff --git a/src/User.hs b/src/User.hs index da2ae10..7e933d6 100644 --- a/src/User.hs +++ b/src/User.hs @@ -99,9 +99,9 @@ validateUser session = (select ["session" =: session] "users") ["$set" =: ["validated" =: True]] -generatePin :: IO T.Text -generatePin = do - g <- newStdGen +generatePin :: Int -> IO T.Text +generatePin s = do + let g = mkStdGen s pure $ T.pack (padLeft (show . head $ randomRs (1 :: Integer, 10000000) g) '0' 7) diff --git a/src/ZGoBackend.hs b/src/ZGoBackend.hs index d9ab820..d3f6b8a 100644 --- a/src/ZGoBackend.hs +++ b/src/ZGoBackend.hs @@ -405,7 +405,7 @@ addUser _ _ _ _ _ Nothing = return () --`debug` "addUser got Nothing" addUser nodeUser nodePwd p db node (Just tx) = do isNew <- liftIO $ isUserNew p db tx when isNew $ do - let newPin = unsafePerformIO generatePin + let newPin = unsafePerformIO (generatePin (fromIntegral $ blocktime tx)) _ <- sendPin nodeUser nodePwd node (address tx) newPin insert_ "users"