Module: Card::Set::Right::Account::Events

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

Overview

Set: All “+Account+Events” cards (Events)

ON CREATE

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



8
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 8

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

Instance Method Details

#activatableObject

EVENT HELPERS



47
48
49
50
51
52
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 47

def activatable
  abort :failure, "no field manipulation mid-activation" if subcards.present?
  # above is necessary because activation uses super user (Decko Bot),
  # so allowing subcards would be unsafe
  yield
end

#event: activate_accountObject

NOTE: this only works in the context of an action. if run independently, it will not activate an account



56
57
58
59
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 56

event :activate_account do
  add_subfield :status, content: "active"
  trigger_event! :send_welcome_email
end

#event: password_redirectObject



33
34
35
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 33

event :password_redirect, :finalize, on: :update, when: :password_redirect? do
  success << { id: name, view: "edit" }
end

#event: reset_passwordObject

reset password emails contain a link to update the +*account card and trigger this event



22
23
24
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 22

event :reset_password, :prepare_to_validate, on: :update, trigger: :required do
  verifying_token :reset_password_success, :reset_password_failure
end

#event: set_default_saltObject



10
11
12
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 10

event :set_default_salt, :prepare_to_validate, on: :create do
  add_subfield(:salt).generate
end

#event: set_default_statusObject



14
15
16
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 14

event :set_default_status, :prepare_to_validate, on: :create do
  add_subfield :status, content: (accounted&.try(:default_account_status) || "active")
end

#event: verify_and_activateObject



26
27
28
29
30
31
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 26

event :verify_and_activate, :prepare_to_validate, on: :update, trigger: :required do
  activatable do
    verifying_token :verify_and_activate_success, :verify_and_activate_failure
    add_subcard(accounted)&.try :activate_accounted
  end
end

#password_redirect?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 80

def password_redirect?
  Auth.current_id == accounted_id && password.blank?
end

#requiring_tokenObject



72
73
74
75
76
77
78
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 72

def requiring_token
  if !(token = Env.params[:token])
    errors.add :token, "is required"
  else
    yield token
  end
end

#reset_password_failure(error_message) ⇒ Object



103
104
105
106
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 103

def reset_password_failure error_message
  Auth.as_bot { send_password_reset_email }
  errors.add :content, tr(:sorry_email_reset, error_msg: error_message)
end

#reset_password_successObject



97
98
99
100
101
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 97

def reset_password_success
  Auth. accounted_id
  success << { id: name, view: :edit }
  abort :success
end

#verify_and_activate_failure(error_message) ⇒ Object



91
92
93
94
95
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 91

def verify_and_activate_failure error_message
  send_verification_email
  errors.add :content,
             "Sorry, #{error_message}. Please check your email for a new activation link."
end

#verify_and_activate_successObject



84
85
86
87
88
89
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 84

def verify_and_activate_success
  Auth. accounted_id
  Auth.as_bot # use admin permissions for rest of action
  
  success << ""
end

#verifying_token(success, failure) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'card/tmpsets/set/mod011-card-mod-account/right/account/events.rb', line 61

def verifying_token success, failure
  requiring_token do |token|
    result = Auth::Token.decode token
    if result.is_a?(String)
      send failure, result
    else
      send success
    end
  end
end