diff options
author | Andrew Cady <d@cryptonomic.net> | 2022-12-02 15:06:01 -0500 |
---|---|---|
committer | Andrew Cady <d@cryptonomic.net> | 2022-12-02 22:14:35 -0500 |
commit | 2d7ced50d94cf5cc83f9565f45a95fd869acea1b (patch) | |
tree | 7eb00f16c2328886eda6b0b981a95bc5829c50d5 | |
parent | d7684e1b4c448f968d9e06d74c4e380a1ebc984f (diff) |
notes in haskell now actually compile
-rw-r--r-- | types.hs | 79 |
1 files changed, 50 insertions, 29 deletions
@@ -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. | 2 | type Text = String |
3 | -- Records the username of the inviting user and the time of the | 3 | type UUID = Text |
4 | -- request. | 4 | type UserID = Int |
5 | data CreateInvitation = CreateInvitation Username Email UTCTime | 5 | type UTCTime = () |
6 | createInvitation (CreateInvitation u e t) = do | 6 | type EmailAddress = () |
7 | x... | ||
8 | type Username = Text | ||
9 | data 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 | ||
17 | newtype UserAccountID = UserAccountID UserID | 14 | type UserAccountID = UserID |
18 | newtype SheetID = SheetID (UserID, Integer) | 15 | newtype SheetID = SheetID (UserAccountID, Integer) |
19 | newtype SignupCodeID = SignupCodeID Text -- short code for typing | 16 | newtype SignupCodeID = SignupCodeID Text -- short code for typing |
20 | newtype InvitationID = InvitationID UUID | 17 | newtype InvitationID = InvitationID UUID |
21 | newtype PasswordResetID = PasswordResetID UUID | 18 | newtype PasswordResetID = PasswordResetID UUID |
22 | 19 | ||
20 | data PasswordReset' id = PasswordReset' | ||
21 | { passwordResetID :: id | ||
22 | , passwordResetSharedSecret :: Text | ||
23 | , passwordResetUserAccount :: UserAccount | ||
24 | , passwordResetCreationTime :: UTCTime | ||
25 | } | ||
26 | type CreatePasswordReset = PasswordReset' () | ||
27 | type PasswordReset = PasswordReset' UserID | ||
28 | |||
23 | data UserAccount' id = UserAccount' | 29 | data 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 | ||
38 | data Provenance = ProvenanceSheet Sheet | ProvenanceUser User | 44 | data Provenance = ProvenanceSheet SheetID | ProvenanceUser UserAccountID |
39 | data Invitation' id = Invitation' | 45 | data 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 | ||
45 | type CreateInvitation = Invitation' () | 52 | type CreateInvitation = Invitation' () |
46 | type Invitation = Invitation' UUID | 53 | type Invitation = Invitation' UUID |
54 | |||
47 | createInvitation :: CreateInvitation -> m Invitation | 55 | createInvitation :: CreateInvitation -> m Invitation |
48 | createInvitation (CreateInvitation () t e (ProvenanceSheet s) = do | 56 | createInvitation (Invitation' () t e (ProvenanceSheet s)) = undefined |
49 | createInvitation (CreateInvitation () t e (ProvenanceUser u) = do | 57 | createInvitation (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. |
57 | data SignupCode' id = SignupCode' | 69 | data SignupCode' id = SignupCode' |
58 | { signupCodeID :: id | 70 | { signupCodeID :: id |
59 | , signupCodeSheetID :: Sheet | 71 | , signupCodeSheetID :: Sheet |
60 | } | 72 | } |
61 | type CreateSignupCode = SignupCode' () | 73 | type CreateSignupCode = SignupCode' () |
62 | type SignupCode = SignupCode' SignupCodeCode | 74 | type SignupCode = SignupCode' SignupCodeID |
63 | createSignupCode :: CreateSignupCode -> SignupCode | 75 | createSignupCode :: CreateSignupCode -> SignupCode |
76 | createSignupCode = 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 | |||
70 | data Sheet' id = Sheet' | 89 | data 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 | } |
75 | type CreateSheet = Sheet' () | 96 | type CreateSheet = Sheet' () |
76 | type Sheet = Sheet' SheetID | 97 | type Sheet = Sheet' SheetID |
77 | type SheetID = UUID | ||
78 | createSheet :: CreateSheet -> m Sheet | 98 | createSheet :: CreateSheet -> m Sheet |
99 | createSheet = undefined | ||
79 | 100 | ||
80 | 101 | ||
81 | 102 | ||
@@ -92,7 +113,7 @@ createSheet :: CreateSheet -> m Sheet | |||
92 | 113 | ||
93 | 114 | ||
94 | 115 | ||
95 | 116 | main = 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 |