Add route for accepting an invitation with an existing account

[?]
Jul 24, 2015, 1:43 AM
MB5SHULBN3WP7TGUWZDP6BRGP423FTYKF67T5IF5YHHLNXKQ5REAC

Dependencies

  • [2] LCBJULKE Fix swapped default and key in QConfig.
  • [3] M3KUPGZK Add invitation email template.
  • [4] A6HKMINB Attempting to improve JSON handling.
  • [5] QMRKFEPG Refactor QDB to use a free monad algebra instead.
  • [6] 2XQD6KKK Add invitation logic and clean up DBProg error handling.
  • [7] PBD7LZYQ Postgres & auth are beginning to function.
  • [8] 45QJYWN3 Fixing up the README. Still struggling with the ending.
  • [9] Z7KS5XHH Very WIP. Wow.
  • [10] EZQG2APB Update task list.
  • [*] 64C6AWH6 Rename Ananke -> Quixotic, project reboot.
  • [*] BROSTG5K Beginning of modularization of server.
  • [*] I2KHGVD4 Require project permissions for access to most data.
  • [*] BXGLKYRX Added primitive user registration handler.
  • [*] ADMKQQGC Initial empty Snap project.
  • [*] O5FVTOM6 Undo JSON silliness, enable a couple more routes.

Change contents

  • edit in TASKS.md at line 26
    [3.79][3.883:1224](),[3.883][3.883:1224](),[3.1224][3.80:112]()
    * Invite
    * When a new participant is invited to the project, allow them to create an account.
    - user creates account ands provides initial payout address
    - inviting user asked to sign a txn that transfers a specific amount of btc from their
    current payout address to the invitee's payout address as confirmation of
    the invitation + script
  • edit in TASKS.md at line 29
    [3.17290][3.226:227](),[3.226][3.226:227]()
  • edit in TASKS.md at line 88
    [3.326]
    [3.326]
    * Invite
    * When a new participant is invited to the project, allow them to create an account.
    - inviting user asked to sign a txn that transfers a specific amount of btc from their
    current payout address to the invitee's payout address as confirmation of
    the invitation + script -- is this actually worth it?
  • replacement in lib/Aftok/Database.hs at line 116
    [3.5907][3.5907:6009]()
    acceptInvitation :: UserId -> InvitationCode -> C.UTCTime -> DBProg ()
    acceptInvitation uid ic t = do
    [3.5907]
    [3.6009]
    acceptInvitation :: UserId -> C.UTCTime -> InvitationCode-> DBProg ()
    acceptInvitation uid t ic = do
  • edit in server/Aftok/Snaplet/Users.hs at line 5
    [14.3157]
    [13.3476]
    , acceptInvitationHandler
  • edit in server/Aftok/Snaplet/Users.hs at line 12
    [15.165]
    [3.10402]
    import Data.Text as T
  • replacement in server/Aftok/Snaplet/Users.hs at line 57
    [3.11180][3.11180:11270]()
    void $ traverse (\c -> acceptInvitation userId c t) (userData ^. invitationCodes)
    [3.11180]
    [3.11270]
    void $ traverse (acceptInvitation userId t) (userData ^. invitationCodes)
  • edit in server/Aftok/Snaplet/Users.hs at line 61
    [3.11344]
    acceptInvitationHandler :: Handler App App ()
    acceptInvitationHandler = do
    uid <- requireUserId
    t <- liftIO C.getCurrentTime
    params <- getParams
    invCodes <- maybe
    (snapError 400 "invCode parameter is required")
    (pure . traverse (parseInvCode . decodeUtf8))
    (lookup "invCode" params)
    either
    (\e -> snapError 400 $ "Invitation code was rejected as invalid: " <> T.pack e)
    (\cx -> void . snapEval $ traverse (acceptInvitation uid t) cx)
    invCodes
  • edit in server/Main.hs at line 40
    [17.2397]
    [3.12580]
    acceptInviteRoute = void $ method POST acceptInvitationHandler
  • edit in server/Main.hs at line 55
    [17.2968]
    [3.12972]
    , ("accept_invitation", acceptInviteRoute)
  • replacement in server/templates/invitation_email.st at line 3
    [3.754][2.86:488]()
    A friend of yours ($from_email$) has invited you to join the "$project_name$" project at http://aftok.com. Here's what you need to do to accept their invitation. At present, there's no user interface for the service other than bare HTTP requests with a JSON payload. A script has been provided below that you can edit to include your own information. You'll need to replace the following three tokens:
    [3.754]
    [3.1157]
    A friend of yours ($from_email$) has invited you to join the "$project_name$"
    project at http://aftok.com. Here's what you need to do to accept their
    invitation. At present, there's no user interface for the service other than
    bare HTTP requests with a JSON payload. A couple of scripts have been provided
    below that you can edit to include your own information.
    If you don't have an aftok.com account:
    If you do not yet have an account on aftok.com, you can create a new account and
    accept your invitation in one step. If you already have an aftok.com account that
    you want to use, then then skip to the "For an existing account" section below.
    To create a new account and accept the invitation, you'll need to replace
    the following three tokens in the curl command below:
  • replacement in server/templates/invitation_email.st at line 20
    [3.1254][3.1254:1531]()
    BTC_ADDR -- the bitcoin address that you want payouts to be initially sent to. You'll be able to change this later, but because changes of payout addresses are validated by checking transactions on the blockchain, it's important that this be a usable address that you control.
    [3.1254]
    [3.1531]
    BTC_ADDR -- the bitcoin address that you want payouts to be initially sent to.
    You'll be able to change this later, but because changes of payout addresses
    are validated by checking transactions on the blockchain, it's important that
    this be a usable address that you control.
  • replacement in server/templates/invitation_email.st at line 25
    [3.1532][3.1532:1715]()
    Substitute your own values for the tokens in the script below, then run it! Also, if you'd prefer that a different email address be associated with your account, change that as well.
    [3.1532]
    [3.1715]
    Substitute your own values for the tokens in the script below, then run it!
    Also, if you'd prefer that a different email address be associated with your
    account, change that as well.
  • edit in server/templates/invitation_email.st at line 30
    [3.1915]
    For an existing account:
    To accept the invitation using your current aftok.com account, you'll simply need to
    replace the <USER> token in the command below with your username:
    curl -k -v -u <USER> -d '' https://aftok.com/accept_invitation?invCode=$inv_code$