diff options
author | William Carroll <wpcarro@gmail.com> | 2020-08-02T15·30+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-08-02T15·30+0100 |
commit | e9e84f6a08c0711c498c7f1f0c9aefc39520c7a7 (patch) | |
tree | bde2d3e291d59d134d230e9ff446a47a0f65dc37 /src/Invitations.hs | |
parent | 25334080b9bcdf238f75069feb92fba65896da5e (diff) |
Support POST /accept-invitation
Allow users to accept invitations that we email to them. TL;DR: - I learned how to write FromHttpApiData instances, which allows me to parse/validate data at the edges of my application; this substantially cleans up my Handler code.
Diffstat (limited to 'src/Invitations.hs')
-rw-r--r-- | src/Invitations.hs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/Invitations.hs b/src/Invitations.hs index 62038bb03646..0c700470f3e2 100644 --- a/src/Invitations.hs +++ b/src/Invitations.hs @@ -12,3 +12,10 @@ create :: FilePath -> T.InvitationSecret -> T.Email -> T.Role -> IO () create dbFile secret email role = withConnection dbFile $ \conn -> do execute conn "INSERT INTO Invitations (email,role,secret) VALUES (?,?,?)" (email, role, secret) + +get :: FilePath -> T.Email -> IO (Maybe T.Invitation) +get dbFile email = withConnection dbFile $ \conn -> do + res <- query conn "SELECT email,role,secret FROM Invitations WHERE email = ?" (Only email) + case res of + [x] -> pure (Just x) + _ -> pure Nothing |