Module: Gringotts::GringottsHelper
- Defined in:
- app/helpers/gringotts/gringotts_helper.rb
Instance Method Summary collapse
-
#gringotts_next_url ⇒ Object
used to redirect back after verifying.
-
#gringotts_owner ⇒ Object
Overridable by application controller Definse whoever is the owner of the Gringotts vault defaults to current_user for simplicity.
-
#gringotts_protego! ⇒ Object
The before_filter that checks to ensure an authenticated user has been verified Keeps users from accessing pages inbetween authentication and verification.
- #gringotts_protego? ⇒ Boolean
-
#gringotts_redirect_to(url) ⇒ Object
helper method for seamlessly redirecting within app ensures we put users back in the same place when we’re done with them.
Instance Method Details
#gringotts_next_url ⇒ Object
used to redirect back after verifying
12 13 14 |
# File 'app/helpers/gringotts/gringotts_helper.rb', line 12 def gringotts_next_url return flash[:gringotts_next_url] end |
#gringotts_owner ⇒ Object
Overridable by application controller Definse whoever is the owner of the Gringotts vault defaults to current_user for simplicity
7 8 9 |
# File 'app/helpers/gringotts/gringotts_helper.rb', line 7 def gringotts_owner return current_user end |
#gringotts_protego! ⇒ Object
The before_filter that checks to ensure an authenticated user has been verified Keeps users from accessing pages inbetween authentication and verification
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/gringotts/gringotts_helper.rb', line 42 def gringotts_protego! # check to see if we should be protecting in the first place # maybe not, depending on config/gringotts.yml and user status if gringotts_protego? # find or create a vault for this owner @gringotts = Gringotts::Vault.for_owner(gringotts_owner) # what we do now is based on what the user has done before in the past... if @gringotts.show_prompt? # 1) owner is a first-timer, and not know about this 2FA -- show prompt gringotts_redirect_to gringotts_engine.prompt_path elsif @gringotts.confirmed? # 2) owner has opted-in -- require verification if @gringotts.verified?(session) # already verified -- do not do anything else # make them verify gringotts_redirect_to gringotts_engine.verification_path end else # 3) owner has declined 2FA -- not do anything end else # if owner not currently defined, assume is an anonymous situation # therefore, no need to bother them end end |
#gringotts_protego? ⇒ Boolean
29 30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/gringotts/gringotts_helper.rb', line 29 def gringotts_protego? # config/gringotts.yml can disable Gringotts entirely return Gringotts::Config.enabled && # fine-grain control over ignoring certain paths, like a .gitignore !(Gringotts::Config.ignore_paths && Gringotts::Config.ignore_paths.include?(request.original_fullpath)) && # if the object designated as the "owner" of this Gringotts vault is defined # then we need to make sure that they are verified on every single page load # otherwise, the user could simply navigate away from the verify page gringotts_owner.present? end |
#gringotts_redirect_to(url) ⇒ Object
helper method for seamlessly redirecting within app ensures we put users back in the same place when we’re done with them
18 19 20 21 22 23 24 25 26 27 |
# File 'app/helpers/gringotts/gringotts_helper.rb', line 18 def gringotts_redirect_to(url) # save url for redirecting back after we verify flash[:gringotts_next_url] = request.original_url # keep other flash items (e.g., success messages) flash.keep # last but not least ... redirect redirect_to url end |