commit 9aaa5307e7671bc8bcc444733a6e38999f346772 Author: James Eversole <james@eversole.co> Date: Mon Jul 18 16:03:43 2022 -0500 Completed migration to SQLite, full feature parity with original Mongo/Couch implementations. Added ability to submit new passwords with full frontend functionality. Generation of random links now functions as expected and Unix Epoch Timestamps are now included in DB entries.
37 lines
946 B
Haskell
37 lines
946 B
Haskell
module Feature.Sharing.HTTP ( routes ) where
|
|
|
|
import Core.Types
|
|
import Core.Templates (renderIndex)
|
|
|
|
import Feature.Generation.Links (genLink)
|
|
import Feature.Sharing.SQLite (findByLink, insertNewSecret)
|
|
import Feature.Sharing.Templates (renderPw)
|
|
import Feature.Sharing.Types
|
|
|
|
import qualified Data.Text as T
|
|
import qualified Data.Text.Lazy as LT
|
|
|
|
import Control.Monad.Reader (ask, lift, liftIO)
|
|
import Data.Maybe (listToMaybe)
|
|
import Web.Scotty.Trans
|
|
import Prelude
|
|
|
|
routes :: PurrApp ()
|
|
routes = do
|
|
|
|
get "/pw/:id" $ do
|
|
reqId <- param "id"
|
|
res <- findByLink reqId
|
|
html $ renderIndex reqId (secret <$> res)
|
|
|
|
post "/pw" $ do
|
|
reqId <- param "userLink"
|
|
res <- findByLink reqId
|
|
html $ renderPw reqId (secret <$> res)
|
|
|
|
post "/new" $ do
|
|
reqSecret <- param "newSec"
|
|
link <- liftIO $ genLink 24 ""
|
|
insertNewSecret reqSecret (T.pack link)
|
|
html $ renderPw link (Just reqSecret)
|