From 5592d715d1881606ca38bc85cba14f4af995b6a8 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Wed, 24 Aug 2022 06:40:11 -0400 Subject: [PATCH] WIP on security --- src/JobsJobsJobs/Domain/Types.fs | 22 +++++++++++++++ src/JobsJobsJobs/Server/Data.fs | 46 +++++++++++++++++++------------- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/JobsJobsJobs/Domain/Types.fs b/src/JobsJobsJobs/Domain/Types.fs index 3bf4dc3..063df14 100644 --- a/src/JobsJobsJobs/Domain/Types.fs +++ b/src/JobsJobsJobs/Domain/Types.fs @@ -97,6 +97,28 @@ type Listing = } +/// Security settings for a user +type SecurityInfo = + { /// The ID of the citizen to whom these settings apply + Id : CitizenId + + /// The number of failed log on attempts (reset to 0 on successful log on) + FailedLogOnAttempts : int16 + + /// Whether the account is locked + AccountLocked : bool + + /// The token the user must provide to take their desired action + Token : string option + + /// The action to which the token applies + TokenUsage : string option + + /// When the token expires + TokenExpires : Instant option + } + + /// A skill the job seeker possesses type Skill = { /// The ID of the skill diff --git a/src/JobsJobsJobs/Server/Data.fs b/src/JobsJobsJobs/Server/Data.fs index 742bef0..3c74b31 100644 --- a/src/JobsJobsJobs/Server/Data.fs +++ b/src/JobsJobsJobs/Server/Data.fs @@ -163,6 +163,24 @@ module Startup = is_legacy BOOLEAN NOT NULL, display_name TEXT, other_contacts TEXT)" + if needsTable "listing" then + "CREATE TABLE jjj.listing ( + id UUID NOT NULL PRIMARY KEY, + citizen_id UUID NOT NULL, + created_on TIMESTAMPTZ NOT NULL, + title TEXT NOT NULL, + continent_id UUID NOT NULL, + region TEXT NOT NULL, + is_remote BOOLEAN NOT NULL, + is_expired BOOLEAN NOT NULL, + updated_on TIMESTAMPTZ NOT NULL, + listing_text TEXT NOT NULL, + needed_by DATE, + was_filled_here BOOLEAN, + FOREIGN KEY fk_listing_citizen (citizen_id) REFERENCES jjj.citizen (id) ON DELETE CASCADE, + FOREIGN KEY fk_listing_continent (continent_id) REFERENCES jjj.continent (id))" + "CREATE INDEX idx_listing_citizen ON jjj.listing (citizen_id)" + "CREATE INDEX idx_listing_continent ON jjj.listing (continent_id)" if needsTable "profile" then "CREATE TABLE jjj.profile ( citizen_id UUID NOT NULL PRIMARY KEY, @@ -188,24 +206,16 @@ module Startup = FOREIGN KEY fk_profile_skill_profile (citizen_id) REFERENCES jjj.profile (citizen_id) ON DELETE CASCADE)" "CREATE INDEX idx_profile_skill_profile ON jjj.profile_skill (citizen_id)" - if needsTable "listing" then - "CREATE TABLE jjj.listing ( - id UUID NOT NULL PRIMARY KEY, - citizen_id UUID NOT NULL, - created_on TIMESTAMPTZ NOT NULL, - title TEXT NOT NULL, - continent_id UUID NOT NULL, - region TEXT NOT NULL, - is_remote BOOLEAN NOT NULL, - is_expired BOOLEAN NOT NULL, - updated_on TIMESTAMPTZ NOT NULL, - listing_text TEXT NOT NULL, - needed_by DATE, - was_filled_here BOOLEAN, - FOREIGN KEY fk_listing_citizen (citizen_id) REFERENCES jjj.citizen (id) ON DELETE CASCADE, - FOREIGN KEY fk_listing_continent (continent_id) REFERENCES jjj.continent (id))" - "CREATE INDEX idx_listing_citizen ON jjj.listing (citizen_id)" - "CREATE INDEX idx_listing_continent ON jjj.listing (continent_id)" + if needsTable "security_info" then + "CREATE TABLE jjj.security_info ( + id UUID NOT NULL PRIMARY KEY, + failed_attempts SMALLINT NOT NULL, + is_locked BOOLEAN NOT NULL, + token TEXT, + token_usage TEXT, + token_expires TIMESTAMPTZ, + FOREIGN KEY fk_security_info_citizen (id) REFERENCES jjj.citizen (id) ON DELETE CASCADE)" + "CREATE INDEX idx_security_info_expires ON jjj.security_info (token_expires)" if needsTable "success" then "CREATE TABLE jjj.success ( id UUID NOT NULL PRIMARY KEY,