BXGLKYRXO2O4NRM3BLNWQ7AWVPQXAMFS57MFYHJNOZZEZZW5BH6AC
-- data CreateUser = CreateUser
-- { _user :: User
-- , _password :: ByteString
-- }
-- makeLenses ''CreateUser
instance FromJSON CreateUser where
parseJSON (Object v) =
let u = User <$> (UserName <$> v .: "username")
<*> (BtcAddr <$> v .: "btcAddr")
<*> v .: "email"
in CreateUser <$> u <*> (fromString <$> v .: "password")
parseJSON _ = mzero
registerHandler = ok
registerHandler = do
QDB{..} <- view qdb <$> with qm get
requestBody <- readRequestBody 0
userData <- maybe (snapError 400 "Could not parse user data") pure $ A.decode requestBody
authUser <- with auth $
AU.createUser (userData ^. (cuser.username._UserName)) (userData ^. password)
let createQUser = liftPG $ runReaderT (createUser $ userData ^. cuser)
void $ either throwDenied (\_ -> createQUser) authUser