@@ -72,8 +72,8 @@ class BParam < ApplicationRecord
7272 stolen
7373 street
7474 ] . freeze
75- # How long a register flow registration resumes by token - and so how long its emailed
76- # confirmation link works, since a link outliving the registration it resumes is a dead end
75+ # How long a register flow registration resumes by token, and so how long its
76+ # emailed confirmation link works
7777 TOKEN_EXPIRATION = 90 . days
7878 mount_uploader :image , ImageUploaderBackgrounded
7979 process_in_background :image , CarrierWaveProcessJob # Defer version generation so large uploads don't hit the 30s Rack::Timeout
@@ -100,7 +100,6 @@ class BParam < ApplicationRecord
100100 scope :without_bike_values , -> { bike_params_empty . or ( where ( origin : "register_flow" ) . where ( "(params -> 'bike' -> 'manufacturer_id') IS NULL" ) ) }
101101 # Tokenized lookups resume registrations for up to a month
102102 scope :recent_with_token , -> ( toke ) { where ( id_token : toke ) . where ( "created_at >= ?" , Time . current - 1 . month ) }
103- # The register flow's own (longer) window - see TOKEN_EXPIRATION
104103 scope :unexpired_with_token , -> ( toke ) { where ( id_token : toke ) . where ( "created_at >= ?" , Time . current - TOKEN_EXPIRATION ) }
105104 scope :unprocessed_image , -> { where ( image_processed : false ) . where . not ( image : nil ) }
106105 scope :with_cycle_type , -> { bike_params . where ( "(params -> 'bike' -> 'cycle_type') IS NOT NULL" ) }
@@ -448,8 +447,7 @@ def email_unconfirmed?
448447 owner_email . present? && !email_confirmed?
449448 end
450449
451- # Spends the confirmation token, so a forwarded email can't sign anyone in later.
452- # creator_id: assigned in the same write, the registration having proven who it's for
450+ # Spends the confirmation token, so a forwarded email can't sign anyone in later
453451 def confirm_email! ( creator_id : nil )
454452 return true if email_confirmed?
455453
@@ -458,15 +456,13 @@ def confirm_email!(creator_id: nil)
458456 . except ( "email_confirmation_token" , "email_confirmation_email" ) )
459457 end
460458
461- # The emailed link's credential. Distinct from id_token, which is in the registrant's
462- # own URL before any email goes out - only a secret that lived solely in the email
463- # proves the address received it. Nil once owner_email is edited to a different
464- # address, since all the token proves is that the one it was mailed to received it
459+ # Distinct from id_token, which is in the registrant's own URL before any email goes
460+ # out - only a secret that lived solely in the email proves the address received it,
461+ # and only for the address it was mailed to
465462 def email_confirmation_token
466463 params [ "email_confirmation_token" ] if email_confirmation_email == EmailNormalizer . normalize ( owner_email )
467464 end
468465
469- # The address the token in hand was mailed to
470466 def email_confirmation_email
471467 params [ "email_confirmation_email" ]
472468 end
@@ -476,8 +472,8 @@ def email_confirmation_token_expired?
476472 SecurityTokenizer . token_time ( email_confirmation_token ) < Time . current - TOKEN_EXPIRATION
477473 end
478474
479- # Resending reuses an unexpired token, so the link already in their inbox keeps working.
480- # The stamp is what rate limits resends, so it's rewritten either way
475+ # Reuses an unexpired token, so the link already in their inbox keeps working - but
476+ # re-stamps either way, since the stamp is what rate limits resends
481477 def generate_email_confirmation_token!
482478 token = email_confirmation_token_expired? ? SecurityTokenizer . new_token : email_confirmation_token
483479 update ( params : params . merge ( "email_confirmation_token" => token ,
@@ -486,8 +482,8 @@ def generate_email_confirmation_token!
486482 token
487483 end
488484
489- # When a link last went out - written by whatever asked for the send, rather than by
490- # the job that delivers it, so it rate limits even when delivery drops the email
485+ # Written by whatever asked for the send rather than by the job that delivers it,
486+ # so it rate limits even when delivery drops the email
491487 def email_confirmation_sent_at
492488 Binxtils ::TimeParser . parse ( params [ "email_confirmation_sent_at" ] )
493489 end
@@ -682,7 +678,6 @@ def mnfg_name
682678 Manufacturer . calculated_mnfg_name ( manufacturer , bike [ "manufacturer_other" ] )
683679 end
684680
685- # What the registration's emails call the bike - everything entered that names it
686681 def color_and_brand
687682 [ primary_frame_color . presence , mnfg_name ] . compact . join ( " " )
688683 end
0 commit comments