Class: WithAccounts::PasswordsCreating::CheckPasswordSetInvitation

Inherits:
LetsDoThis::Act
  • Object
show all
Includes:
ErrorsHelpers
Defined in:
app/scenarios/with_accounts/passwords_creating/check_password_set_invitation.rb

Instance Method Summary collapse

Methods included from ErrorsHelpers

#error_key, #format_errors

Instance Method Details

#instructions(stage) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/scenarios/with_accounts/passwords_creating/check_password_set_invitation.rb', line 5

def instructions(stage)
  password_set_invitation = stage.params[:invitation]
   = Account.ready_to_set_password(:_)
                   .joins(:user)
                   .where('users.disabled': false)
                   .find_by_password_set_invitation(password_set_invitation)

  unless 
    errors.add(error_key, 'err')
    return NOTHING_NEW
  end

  encrypted = Base64.urlsafe_decode64(password_set_invitation)
  decipher = .cipher_decipher(:decrypt, :password_set_at)
  plain = decipher.update(encrypted) + decipher.final
  deadline = Time.at(plain.to_i)

  if Time.now > deadline
    errors.add(error_key, 'err')
    return NOTHING_NEW
  end

  { account:  }
end