Added primitive user registration handler.

[?]
Jan 24, 2015, 2:17 AM
BXGLKYRXO2O4NRM3BLNWQ7AWVPQXAMFS57MFYHJNOZZEZZW5BH6AC

Dependencies

  • [2] BROSTG5K Beginning of modularization of server.
  • [3] IZEVQF62 Work in progress replacing sqlite with postgres.
  • [4] 5W5M56VJ Move library code to 'lib'
  • [5] JKMHA2QG SQLite support is now relatively sane.
  • [6] EMVTF2IW WIP moving back to snap.
  • [7] 64C6AWH6 Rename Ananke -> Quixotic, project reboot.
  • [8] TZQJVHBA Add auction functions to ADB.
  • [9] TNR3TEHK Switch to Postgres + snaplet arch compiles.
  • [10] LAROLAYU WIP

Change contents

  • edit in lib/Quixotic/Database/PostgreSQL.hs at line 1
    [3.456][3.457:532]()
    {-# LANGUAGE ScopedTypeVariables, OverloadedStrings, NoImplicitPrelude #-}
  • replacement in lib/Quixotic/Database.hs at line 1
    [3.4936][3.6503:6555]()
    {-# LANGUAGE NoImplicitPrelude, TemplateHaskell #-}
    [3.4936]
    [3.426]
    {-# LANGUAGE TemplateHaskell #-}
  • edit in lib/Quixotic/Users.hs at line 1
    [3.5932][3.5933:6008]()
    {-# LANGUAGE ScopedTypeVariables, OverloadedStrings, NoImplicitPrelude #-}
  • replacement in server/Quixotic/Api/Users.hs at line 1
    [2.3234][2.3235:3411]()
    {-# LANGUAGE ScopedTypeVariables #-}
    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE NoImplicitPrelude #-}
    {-# LANGUAGE RecordWildCards #-}
    {-# LANGUAGE TemplateHaskell #-}
    [2.3234]
    [2.3411]
    {-# LANGUAGE TemplateHaskell, RecordWildCards #-}
  • edit in server/Quixotic/Api/Users.hs at line 10
    [2.3510]
    [2.3510]
    import Control.Lens
    import Control.Monad.State
    import Data.Aeson as A
  • edit in server/Quixotic/Api/Users.hs at line 17
    [2.3624]
    [2.3624]
    import Quixotic
    import Quixotic.Database
    import Quixotic.Users
  • edit in server/Quixotic/Api/Users.hs at line 25
    [2.3729]
    [2.3729]
    import Snap.Snaplet.PostgresqlSimple
  • edit in server/Quixotic/Api/Users.hs at line 40
    [2.4305]
    [2.4305]
    data CreateUser = CreateUser
    { _cuser :: User
    , _password :: ByteString
    }
    makeLenses ''CreateUser
  • replacement in server/Quixotic/Api/Users.hs at line 47
    [2.4306][2.4306:4424]()
    -- data CreateUser = CreateUser
    -- { _user :: User
    -- , _password :: ByteString
    -- }
    -- makeLenses ''CreateUser
    [2.4306]
    [2.4424]
    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
  • replacement in server/Quixotic/Api/Users.hs at line 64
    [2.4886][2.4886:4907]()
    registerHandler = ok
    [2.4886]
    [2.4907]
    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
  • edit in server/Quixotic/Api/Users.hs at line 84
    [2.5353]