Module: Card::Set::Self::Signin

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod011-card-mod-account/self/signin.rb,
card/tmpsets/set/mod010-card-mod-account/self/signin.rb

Overview

The Sign In card manages logging in and out of the site.

Defined Under Namespace

Modules: HtmlFormat

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



9
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 9

def self.source_location; "/Users/ethan/dev/decko/gem/card-mod-account/set/self/signin.rb"; end

Instance Method Details

#abort_unless(value, error_key) ⇒ Object



73
74
75
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 73

def abort_unless value, error_key
  abort :failure, (error_key) unless value
end

#account_for(email) ⇒ Object



89
90
91
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 89

def  email
  Auth. email
end

#authenticate_and_signin(email, pword) ⇒ Object



62
63
64
65
66
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 62

def  email, pword
  return unless ( = Auth.authenticate email, pword)

  Auth. .left_id
end

#authenticate_or_abort(email, pword) ⇒ Object



56
57
58
59
60
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 56

def authenticate_or_abort email, pword
  abort_unless email, :email_missing
  abort_unless pword, :password_missing
  (email, pword) || (email)
end

#blank_email?Boolean

Returns:

  • (Boolean)


119
120
121
122
123
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 119

def blank_email? email
  return false if email.present?

  error_on :email, :error_blank
end

#email_from_subfieldObject



45
46
47
# File 'card/tmpsets/set/mod010-card-mod-account/self/signin.rb', line 45

def email_from_subfield
  @email_from_subfield ||= subfield(:email)&.content
end

#error_on(field, error_key) ⇒ Object



85
86
87
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 85

def error_on field, error_key
  errors.add field, (error_key)
end

#event: send_reset_password_tokenObject

triggered by clicking “Reset my Password”, this sends out the verification password and aborts (does not sign in)



39
40
41
42
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 39

event :send_reset_password_token, before: :signin, on: :update, trigger: :required do
  email = subfield(:email)&.content
  send_reset_password_email_or_fail email
end

#event: signinObject

authentication event



17
18
19
20
21
22
23
24
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 17

event :signin, :validate, on: :update do
  email = subfield :email
  email &&= email.content
  pword = subfield :password
  pword &&= pword.content

  authenticate_or_abort email, pword
end

#event: signin_successObject

abort after successful signin (do not save card)



27
28
29
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 27

event :signin_success, after: :signin do
  abort :success
end

#event: signoutObject



31
32
33
34
35
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 31

event :signout, :validate, on: :delete do
  Env.reset_session
  Auth. AnonymousID
  abort :success
end

#failed_signin(email) ⇒ Object



68
69
70
71
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 68

def  email
  errors.add :signin, ((email))
  abort :failure
end

#i18n_signin(key) ⇒ Object



52
53
54
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 52

def  key
  I18n.t key, scope: "mod.card-mod-account.set.self.signin"
end

#ok_to_readObject



44
45
46
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 44

def ok_to_read
  true
end

#recaptcha_on?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 48

def recaptcha_on?
  false
end

#reset_password_fail(account) ⇒ Object



129
130
131
132
133
134
135
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 129

def reset_password_fail 
  if 
    error_on :account, :error_not_active
  else
    error_on :email, :error_not_recognized
  end
end

#send_reset_password_email(account) ⇒ Object



125
126
127
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 125

def send_reset_password_email 
  Auth.as_bot { .send_password_reset_email }
end

#send_reset_password_email_or_failObject



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 93

def send_reset_password_email_or_fail email
  aborting do
    break errors.add :email, (:error_blank) if email.blank?

    if ( = Auth.(email))&.active?
      Auth.as_bot { .send_password_reset_email }
    elsif 
      errors.add :account, (:error_not_active)
    else
      errors.add :email, (:error_not_recognized)
    end
  end
end

#signin_error_message(account) ⇒ Object



77
78
79
80
81
82
83
# File 'card/tmpsets/set/mod011-card-mod-account/self/signin.rb', line 77

def  
  case
  when .nil?     then (:error_unknown_email)
  when !.active? then (:error_not_active)
  else                       (:error_wrong_password)
  end
end