Module: LsOmniauth::OmniauthHelper
- Defined in:
- app/helpers/ls_omniauth/omniauth_helper.rb
Class Method Summary collapse
- .authorized_group_users(group) ⇒ Object
- .authorized_users ⇒ Object
- .email_for_current_user ⇒ Object
- .email_in_group(email, group) ⇒ Object
- .render_access_denied ⇒ Object
- .running_in_dev_mode? ⇒ Boolean
Instance Method Summary collapse
- #current_user_in_group(group) ⇒ Object
- #require_authentication ⇒ Object
- #require_authorization(options = {}) ⇒ Object
- #when_not_in_dev_mode(&block) ⇒ Object
Class Method Details
.authorized_group_users(group) ⇒ Object
57 58 59 |
# File 'app/helpers/ls_omniauth/omniauth_helper.rb', line 57 def (group) [group] || [] end |
.authorized_users ⇒ Object
53 54 55 |
# File 'app/helpers/ls_omniauth/omniauth_helper.rb', line 53 def @authorized_users ||= (LS_OMNIAUTH.config[:authorized_users] || {}) end |
.email_for_current_user ⇒ Object
61 62 63 |
# File 'app/helpers/ls_omniauth/omniauth_helper.rb', line 61 def email_for_current_user LsOmniauth::AuthSessions.new(session).auth.get end |
.email_in_group(email, group) ⇒ Object
65 66 67 |
# File 'app/helpers/ls_omniauth/omniauth_helper.rb', line 65 def email_in_group(email, group) (group).map(&:upcase).include?(email.to_s.upcase) end |
.render_access_denied ⇒ Object
69 70 71 |
# File 'app/helpers/ls_omniauth/omniauth_helper.rb', line 69 def render_access_denied render :text => "<div class='notification error'>You are not authorized to view this resource. Sorry!</div>", :status => 401 end |
.running_in_dev_mode? ⇒ Boolean
49 50 51 |
# File 'app/helpers/ls_omniauth/omniauth_helper.rb', line 49 def running_in_dev_mode? LS_OMNIAUTH.config.running_in_dev_mode? end |
Instance Method Details
#current_user_in_group(group) ⇒ Object
37 38 39 |
# File 'app/helpers/ls_omniauth/omniauth_helper.rb', line 37 def current_user_in_group(group) email_in_group(email_for_current_user, group) end |
#require_authentication ⇒ Object
2 3 4 5 6 7 8 9 10 11 |
# File 'app/helpers/ls_omniauth/omniauth_helper.rb', line 2 def require_authentication when_not_in_dev_mode { sessions = LsOmniauth::AuthSessions.new(session) if sessions.auth.get.blank? sessions.origin.set("#{request.protocol}#{request.host_with_port}#{request.fullpath}") redirect_to ls_omniauth.sign_in_url and return false end true } end |
#require_authorization(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/ls_omniauth/omniauth_helper.rb', line 13 def ( = {}) when_not_in_dev_mode { return unless require_authentication sessions = LsOmniauth::AuthSessions.new(session) email = sessions.auth.get .symbolize_keys! if [:domains].respond_to? :include? email_domain = email.match(/[\w]+\.com/)[0] unless [:domains].map(&:upcase).include? email_domain.upcase render_access_denied and return end end if .has_key? :group if !email_in_group(email, [:group]) render_access_denied and return end end } end |
#when_not_in_dev_mode(&block) ⇒ Object
41 42 43 44 45 |
# File 'app/helpers/ls_omniauth/omniauth_helper.rb', line 41 def when_not_in_dev_mode(&block) if !running_in_dev_mode? yield end end |