diff --git a/app/jobs/verify_emails_job.rb b/app/jobs/verify_emails_job.rb index a0d7234c5..41965c9d9 100644 --- a/app/jobs/verify_emails_job.rb +++ b/app/jobs/verify_emails_job.rb @@ -2,10 +2,7 @@ class VerifyEmailsJob < Que::Job def run(verification_id) email_address_verification = run_condition(EmailAddressVerification.find(verification_id)) - if email_address_verification.recently_verified? - destroy - return - end + return if email_address_verification.recently_verified? ActiveRecord::Base.transaction do email_address_verification.verify diff --git a/app/models/concerns/email_verifable.rb b/app/models/concerns/email_verifable.rb index de8041c32..f7c9e59fb 100644 --- a/app/models/concerns/email_verifable.rb +++ b/app/models/concerns/email_verifable.rb @@ -3,15 +3,15 @@ module Concerns extend ActiveSupport::Concern def email_verification - EmailAddressVerification.find_or_create_by(email: email, - domain: domain(email)) + EmailAddressVerification.find_or_create_by(email: email.downcase, + domain: domain(email.downcase)) end def billing_email_verification return unless attribute_names.include?('billing_email') - EmailAddressVerification.find_or_create_by(email: billing_email, - domain: domain(email)) + EmailAddressVerification.find_or_create_by(email: billing_email.downcase, + domain: domain(email.downcase)) end def domain(email) diff --git a/config/schedule.rb b/config/schedule.rb index 089ce93f9..7ebf97d12 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -62,6 +62,10 @@ if @cron_group == 'registry' rake 'domain:discard' end + every 10.minutes do + rake 'verify_email:all_domains' + end + # Should be at least once every 4 days, since according to LHV specs: # "Unread messages older than 5 days are automatically scheduled for deletion" # https://partners.lhv.ee/en/connect/#messaging diff --git a/db/migrate/20200610090110_change_email_verification_fields_to_citext.rb b/db/migrate/20200610090110_change_email_verification_fields_to_citext.rb new file mode 100644 index 000000000..a7e2f8ee8 --- /dev/null +++ b/db/migrate/20200610090110_change_email_verification_fields_to_citext.rb @@ -0,0 +1,13 @@ +class ChangeEmailVerificationFieldsToCitext < ActiveRecord::Migration[6.0] + def up + enable_extension 'citext' + change_column :email_address_verifications, :email, :citext + change_column :email_address_verifications, :domain, :citext + end + + def down + change_column :email_address_verifications, :email, :string + change_column :email_address_verifications, :domain, :string + disable_extension 'citext' + end +end diff --git a/db/structure.sql b/db/structure.sql index c5ad902b7..9db7d07d1 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -33,10 +33,17 @@ CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public; -- --- Name: EXTENSION btree_gist; Type: COMMENT; Schema: -; Owner: - +-- Name: citext; Type: EXTENSION; Schema: -; Owner: - -- -COMMENT ON EXTENSION btree_gist IS 'support for indexing common datatypes in GiST'; +CREATE EXTENSION IF NOT EXISTS citext WITH SCHEMA public; + + +-- +-- Name: EXTENSION citext; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION citext IS 'data type for case-insensitive character strings'; -- @@ -822,10 +829,10 @@ ALTER SEQUENCE public.domains_id_seq OWNED BY public.domains.id; CREATE TABLE public.email_address_verifications ( id bigint NOT NULL, - email character varying NOT NULL, + email public.citext NOT NULL, verified_at timestamp without time zone, success boolean DEFAULT false NOT NULL, - domain character varying NOT NULL + domain public.citext NOT NULL ); @@ -4700,5 +4707,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200518104105'), ('20200529115011'), ('20200605100827'), +('20200610090110'), ('20200630081231');