summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-12-02 15:06:01 -0500
committerAndrew Cady <d@cryptonomic.net>2022-12-02 22:14:35 -0500
commit2d7ced50d94cf5cc83f9565f45a95fd869acea1b (patch)
tree7eb00f16c2328886eda6b0b981a95bc5829c50d5
parentd7684e1b4c448f968d9e06d74c4e380a1ebc984f (diff)
notes in haskell now actually compile
-rw-r--r--types.hs79
1 files changed, 50 insertions, 29 deletions
diff --git a/types.hs b/types.hs
index 0021599..c151d89 100644
--- a/types.hs
+++ b/types.hs
@@ -1,12 +1,9 @@
1 1{-# OPTIONS_GHC -Wall -Wno-unused-top-binds -Wno-unused-matches -Wno-missing-signatures #-}
2-- Invite a user by email address. 2type Text = String
3-- Records the username of the inviting user and the time of the 3type UUID = Text
4-- request. 4type UserID = Int
5data CreateInvitation = CreateInvitation Username Email UTCTime 5type UTCTime = ()
6createInvitation (CreateInvitation u e t) = do 6type EmailAddress = ()
7 x...
8type Username = Text
9data User = User UserID Username
10 7
11-- These ID types use a type parameter "trick." The type parameter is 8-- These ID types use a type parameter "trick." The type parameter is
12-- instantiated twice; once with () for its id field type, and once with an 9-- instantiated twice; once with () for its id field type, and once with an
@@ -14,15 +11,24 @@ data User = User UserID Username
14-- represent database field inputs; and the "indexed" version to represent 11-- represent database field inputs; and the "indexed" version to represent
15-- corresponding outputs. 12-- corresponding outputs.
16 13
17newtype UserAccountID = UserAccountID UserID 14type UserAccountID = UserID
18newtype SheetID = SheetID (UserID, Integer) 15newtype SheetID = SheetID (UserAccountID, Integer)
19newtype SignupCodeID = SignupCodeID Text -- short code for typing 16newtype SignupCodeID = SignupCodeID Text -- short code for typing
20newtype InvitationID = InvitationID UUID 17newtype InvitationID = InvitationID UUID
21newtype PasswordResetID = PasswordResetID UUID 18newtype PasswordResetID = PasswordResetID UUID
22 19
20data PasswordReset' id = PasswordReset'
21 { passwordResetID :: id
22 , passwordResetSharedSecret :: Text
23 , passwordResetUserAccount :: UserAccount
24 , passwordResetCreationTime :: UTCTime
25 }
26type CreatePasswordReset = PasswordReset' ()
27type PasswordReset = PasswordReset' UserID
28
23data UserAccount' id = UserAccount' 29data UserAccount' id = UserAccount'
24 { userAccountID :: id 30 { userAccountID :: id
25 , userAccountInvitation :: Invitation' InvitationID -- Contains inviter 31 , userAccountInvitationID :: InvitationID
26 , userAccountEmail :: EmailAddress 32 , userAccountEmail :: EmailAddress
27 , userAccountCreationTime :: UTCTime 33 , userAccountCreationTime :: UTCTime
28 } 34 }
@@ -35,47 +41,62 @@ type UserAccount = UserAccount' UserID
35-- be submitted with the InvitationID to initiate the password reset in 41-- be submitted with the InvitationID to initiate the password reset in
36-- the browser. 42-- the browser.
37 43
38data Provenance = ProvenanceSheet Sheet | ProvenanceUser User 44data Provenance = ProvenanceSheet SheetID | ProvenanceUser UserAccountID
39data Invitation' id = Invitation' 45data Invitation' id = Invitation'
40 { invitationID :: id 46 { invitationID :: id
41 , invitationCreationTime :: UTCTime 47 , invitationCreationTime :: UTCTime
42 , invitationEmailAddress :: EmailAddress -- invited user 48 , invitationEmailAddress :: EmailAddress -- invited address
43 , invitationProvenance :: Provenance -- inviting user 49 , invitationProvenance :: Provenance -- inviting user
44 } 50 }
51-- data CreateInvitation = CreateInvitation Username Email UTCTime
45type CreateInvitation = Invitation' () 52type CreateInvitation = Invitation' ()
46type Invitation = Invitation' UUID 53type Invitation = Invitation' UUID
54
47createInvitation :: CreateInvitation -> m Invitation 55createInvitation :: CreateInvitation -> m Invitation
48createInvitation (CreateInvitation () t e (ProvenanceSheet s) = do 56createInvitation (Invitation' () t e (ProvenanceSheet s)) = undefined
49createInvitation (CreateInvitation () t e (ProvenanceUser u) = do 57createInvitation (Invitation' () t e (ProvenanceUser u)) = undefined
50 -- validate inviting user/sheet 58
51 -- record invitation code and shared secret in database 59-- Invite a user by email address.
52 -- send email containing shared secret 60-- Records the username of the inviting user and the time of the
53 61-- request.
54-- signupcodes can be used to create self-invitations. the user must 62-- * Validate inviting user/sheet.
55-- supply a signupcode and their email address. a secret code will be 63-- * Record invitation code and shared secret in database.
64-- * Send email containing shared secret.
65
66-- Signupcodes can be used to create self-invitations. The user must
67-- supply a signupcode and their email address. A shared secret will be
56-- sent to the email address. 68-- sent to the email address.
57data SignupCode' id = SignupCode' 69data SignupCode' id = SignupCode'
58 { signupCodeID :: id 70 { signupCodeID :: id
59 , signupCodeSheetID :: Sheet 71 , signupCodeSheetID :: Sheet
60 } 72 }
61type CreateSignupCode = SignupCode' () 73type CreateSignupCode = SignupCode' ()
62type SignupCode = SignupCode' SignupCodeCode 74type SignupCode = SignupCode' SignupCodeID
63createSignupCode :: CreateSignupCode -> SignupCode 75createSignupCode :: CreateSignupCode -> SignupCode
76createSignupCode = undefined
64 77
78-- ## Sheet' ##
65-- A sheet containing signupcodes. 79-- A sheet containing signupcodes.
66-- The signupcodes link up to their creating sheet. Since the real purpose is to 80--
81-- The signupcodes link back to their creating sheet.
82-- Signupcodes are converted to Invitations
83
67-- get the Username, it is kept as a Sheet rather than SheetID. If the username 84-- get the Username, it is kept as a Sheet rather than SheetID. If the username
68-- changes for the UserID then we have retained a record of the inviting 85-- changes for the UserID then we retain a record of the inviting username at
69-- username at the time. 86-- the time. The UserID itself is stored as part of the index of the Sheet so it
87-- is not stored a second time along with the UserAccount data record.
88
70data Sheet' id = Sheet' 89data Sheet' id = Sheet'
71 { sheetID :: id 90 { sheetID :: id
72 , sheetCreator :: UserAccount' () -- Stores the data! Not the database record ID! 91 , sheetCreator :: UserAccount' () -- Stores the data, but not the database
92 -- record ID, which is stored in the
93 -- sheetID.
73 , sheetCreationTime :: UTCTime 94 , sheetCreationTime :: UTCTime
74 } 95 }
75type CreateSheet = Sheet' () 96type CreateSheet = Sheet' ()
76type Sheet = Sheet' SheetID 97type Sheet = Sheet' SheetID
77type SheetID = UUID
78createSheet :: CreateSheet -> m Sheet 98createSheet :: CreateSheet -> m Sheet
99createSheet = undefined
79 100
80 101
81 102
@@ -92,7 +113,7 @@ createSheet :: CreateSheet -> m Sheet
92 113
93 114
94 115
95 116main = undefined
96 117
97-- The browser is expected to generate a secure password that will be 118-- The browser is expected to generate a secure password that will be
98-- stored within the browser. Do not re-use passwords! Password re-use 119-- stored within the browser. Do not re-use passwords! Password re-use