Module: Card::Set::Right::Account::Events
- Extended by:
- Card::Set
- Defined in:
- platypus/tmp/set/gem-defaults/mod014-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
Class Method Summary collapse
Instance Method Summary collapse
-
#activatable ⇒ Object
EVENT HELPERS.
-
#event: activate_account ⇒ Object
NOTE: this only works in the context of an action.
-
#event: password_redirect ⇒ Object
-
#event: reset_password ⇒ Object
reset password emails contain a link to update the +*account card and trigger this event.
-
#event: set_default_salt ⇒ Object
-
#event: set_default_status ⇒ Object
-
#event: verify_and_activate ⇒ Object
-
#password_redirect? ⇒ Boolean
-
#requiring_token ⇒ Object
-
#reset_password_failure(error_message) ⇒ Object
-
#reset_password_success ⇒ Object
-
#verify_and_activate_failure(error_message) ⇒ Object
-
#verify_and_activate_success ⇒ Object
-
#verifying_token(success, failure) ⇒ Object
Methods included from Card::Set
Methods included from I18nScope
Methods included from Card::Set::Registrar
#extended, #finalize_load, #process_base_modules, #register_set
Methods included from Helpers
#format_module, #format_modules, #method_missing, #modules, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscored_name
Methods included from AdvancedApi
#assign_type, #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 Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
Class Method Details
.source_location ⇒ Object
8 |
# File 'platypus/tmp/set/gem-defaults/mod014-account/right/account/events.rb', line 8 def self.source_location; "/Users/ethan/dev/decko/gem/mod/account/set/right/account/events.rb"; end |
Instance Method Details
#activatable ⇒ Object
EVENT HELPERS
47 48 49 50 51 52 |
# File 'platypus/tmp/set/gem-defaults/mod014-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_account ⇒ Object
NOTE: this only works in the context of an action. if run independently, it will not activate an account
56 57 58 59 |
# File 'platypus/tmp/set/gem-defaults/mod014-account/right/account/events.rb', line 56 event :activate_account do field :status, content: "active" trigger_event! :send_welcome_email end |
#event: password_redirect ⇒ Object
33 34 35 |
# File 'platypus/tmp/set/gem-defaults/mod014-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_password ⇒ Object
reset password emails contain a link to update the +*account card and trigger this event
22 23 24 |
# File 'platypus/tmp/set/gem-defaults/mod014-account/right/account/events.rb', line 22 event :reset_password, :prepare_to_validate, on: :update, trigger: :required do :reset_password_success, :reset_password_failure end |
#event: set_default_salt ⇒ Object
10 11 12 |
# File 'platypus/tmp/set/gem-defaults/mod014-account/right/account/events.rb', line 10 event :set_default_salt, :prepare_to_validate, on: :create do field(:salt).generate end |
#event: set_default_status ⇒ Object
14 15 16 |
# File 'platypus/tmp/set/gem-defaults/mod014-account/right/account/events.rb', line 14 event :set_default_status, :prepare_to_validate, on: :create do field :status, content: (accounted&.try(:default_account_status) || "active") end |
#event: verify_and_activate ⇒ Object
26 27 28 29 30 31 |
# File 'platypus/tmp/set/gem-defaults/mod014-account/right/account/events.rb', line 26 event :verify_and_activate, :prepare_to_validate, on: :update, trigger: :required do activatable do :verify_and_activate_success, :verify_and_activate_failure subcard(accounted)&.try :activate_accounted end end |
#password_redirect? ⇒ Boolean
80 81 82 |
# File 'platypus/tmp/set/gem-defaults/mod014-account/right/account/events.rb', line 80 def password_redirect? Auth.current_id == accounted_id && password.blank? end |
#requiring_token ⇒ Object
72 73 74 75 76 77 78 |
# File 'platypus/tmp/set/gem-defaults/mod014-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 'platypus/tmp/set/gem-defaults/mod014-account/right/account/events.rb', line 103 def reset_password_failure Auth.as_bot { send_password_reset_email } errors.add :content, t(:account_sorry_email_reset, error_msg: ) end |
#reset_password_success ⇒ Object
97 98 99 100 101 |
# File 'platypus/tmp/set/gem-defaults/mod014-account/right/account/events.rb', line 97 def reset_password_success Auth.signin accounted_id success << { id: name, view: :edit } abort :success end |
#verify_and_activate_failure(error_message) ⇒ Object
91 92 93 94 95 |
# File 'platypus/tmp/set/gem-defaults/mod014-account/right/account/events.rb', line 91 def verify_and_activate_failure send_verification_email errors.add :content, "Sorry, #{}. Please check your email for a new activation link." end |
#verify_and_activate_success ⇒ Object
84 85 86 87 88 89 |
# File 'platypus/tmp/set/gem-defaults/mod014-account/right/account/events.rb', line 84 def verify_and_activate_success Auth.signin accounted_id Auth.as_bot # use admin permissions for rest of action activate_account success << "" end |
#verifying_token(success, failure) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'platypus/tmp/set/gem-defaults/mod014-account/right/account/events.rb', line 61 def success, failure requiring_token do |token| result = Auth::Token.decode token if result.is_a?(String) || (result[:user_id] != accounted_id) send failure, result else send success end end end |