Module: Wallaby::SecureHelper
- Defined in:
- lib/helpers/wallaby/secure_helper.rb
Overview
Secure helper
Instance Method Summary collapse
-
#logout_method(user = current_user) ⇒ String, Symbol
Logout method for given user.
-
#logout_path(user = current_user, app = main_app) ⇒ String
Logout path for given user.
-
#user_portrait(user = current_user) ⇒ String
Image portrait for given user.
Instance Method Details
#logout_method(user = current_user) ⇒ String, Symbol
Logout method for given user
41 42 43 44 45 46 47 48 |
# File 'lib/helpers/wallaby/secure_helper.rb', line 41 def logout_method(user = current_user) http_method = Wallaby.configuration.security.logout_method http_method || if defined? ::Devise scope = ::Devise::Mapping.find_scope! user mapping = ::Devise.mappings[scope] mapping.sign_out_via end end |
#logout_path(user = current_user, app = main_app) ⇒ String
Logout path for given user
27 28 29 30 31 32 33 34 35 |
# File 'lib/helpers/wallaby/secure_helper.rb', line 27 def logout_path(user = current_user, app = main_app) path = Wallaby.configuration.security.logout_path path ||= if defined? ::Devise scope = ::Devise::Mapping.find_scope! user "destroy_#{scope}_session_path" end app.public_send path if path && app.respond_to?(path) end |
#user_portrait(user = current_user) ⇒ String
Image portrait for given user.
-
if email is present, a gravatar image tag will be returned
-
otherwise, an user icon will be returned
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/helpers/wallaby/secure_helper.rb', line 9 def user_portrait(user = current_user) email_method = Wallaby.configuration.security.email_method || :email email = user.respond_to?(email_method) && user.public_send(email_method) if email.present? https = "http#{request.ssl? ? 's' : EMPTY_STRING}" email_md5 = ::Digest::MD5.hexdigest email.downcase image_source = "#{https}://www.gravatar.com/avatar/#{email_md5}" image_tag image_source, class: 'hidden-xs user-portrait' else content_tag :i, nil, class: 'fa fa-user user-portrait' end end |