TNR3TEHKVADAEZSTOD2XLSUTSW5AWST2YUW4CWK5KE7DSC6XHZNAC
IZEVQF627FA7VV25KJAWYWGGC35LZUUBBQRPN5ZAINTQLPEDRTEAC
64C6AWH66FDKU6UE6Z6JPX2J2GBM2JOPTH2GL6LHKAIUBGNGDZ5AC
TLQ72DSJD7GGPWN6HGBHAVPBRQFKEQ6KSK43U7JWWID4ZWAF47JAC
WO2MINIF4TXOHWSE7JWXRZYN64XRVLYIRFMF4SMPSOXKA2V77KMQC
ADMKQQGCGVSHHIMVQ4XFRDCG544SBJCYALSKZV45CQQBZ4ACUH2AC
EMVTF2IWNQGRL44FC4JNG5FYYQTZSFPNM6SOM7IAEH6T7PPK2NVAC
7XN3I3QJHYMKU2DCUXX34WQMSJ4ZJOWW7FME34EANO3E5W4Q632AC
TCOAKCGGHOIRJCTZYEZQ3K6KCGL2LGAYGYFRGSPCHBTJJY2V6AXAC
Z3M53KTLZMPOISMHE25SZJSWX5TA37IV33IRE7KNRAD3PKEAEJXQC
2Y2QZFVFSKXEFEGYJB5A7GI735ONWPCF7DVTIY5T73AUEVTZTBBQC
W35DDBFYF6Z4ZPCFEO5RPAONZLYCSNTXUSTS6FIUUVZHCI6Q7GHAC
64VI73NPSFNWTL6UXM6YHRFLNJZ3NUJ2R3CL53MO2HSZWFGBIRTQC
findUserByHandle' :: Handle -> ReaderT Connection IO (Maybe QDBUser)
findUserByHandle' = undefined
findUserByUserName' :: UserName -> ReaderT Connection IO (Maybe QDBUser)
findUserByUserName' (UserName h) = do
conn <- ask
users <- lift $ query conn
"SELECT id, handle, btc_addr, email FROM users WHERE handle = ?"
(Only h)
pure . fmap pQDBUser $ headMay users
{-# LANGUAGE ScopedTypeVariables, OverloadedStrings, NoImplicitPrelude #-}
{-# LANGUAGE RecordWildCards, TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens.TH
import Control.Monad.Trans.Reader
import qualified Data.Aeson as A
import Control.Monad.Reader
import Control.Monad.State
requireLogin :: Handler App App a -> Handler App App a
requireLogin = AU.requireUser auth (redirect "/login")
requireUserId :: (UserId -> Handler App App a) -> Handler App App a
requireUserId hf = AU.requireUser auth (redirect "/login") $ do
QDB{..} <- with qdb get
authedUser <- with auth AU.currentUser
qdbUser <- case UserName . AU.unUid <$> (AU.userId =<< authedUser) of
Nothing -> snapError 403 "User is authenticated, but session lacks user identifier"
Just n -> liftPG . runReaderT $ findUserByUserName n
case qdbUser of
Nothing -> snapError 403 "Unable to retrieve user record for authenticated user"
Just u -> hf (u ^. userId)
btcAddr = fmap decodeUtf8 addrBytes >>= parseBtcAddr
storeEv uid addr = runReaderT . recordEvent uid $ LogEntry addr workEvent
maybe (snapError 400 "") (liftPG . storeEv) btcAddr
storeEv addr = runReaderT . recordEvent uid $ LogEntry addr workEvent
case fmap decodeUtf8 addrBytes >>= parseBtcAddr of
Nothing -> snapError 400 $ "Unable to parse bitcoin address from " <> (tshow addrBytes)
Just addr -> liftPG $ storeEv addr