lib/auth_lh/authentication.rb in auth-lh-0.11.2 vs lib/auth_lh/authentication.rb in auth-lh-0.12.0
- old
+ new
@@ -14,21 +14,51 @@
def auth_user=(val)
@auth_user = val
end
+ def has_role?(r_code)
+ role_codes.include?(r_code.to_s)
+ end
+
+ def has_some_role?(r_codes)
+ r_codes.any? { |r_code|
+ role_codes.include?(r_code.to_s)
+ }
+ end
+
+ def has_all_roles?(r_codes)
+ r_codes.all? { |r_code|
+ role_codes.include?(r_code.to_s)
+ }
+ end
+
module ClassMethods
def all_external
- AuthLh.get_users
+ @cached_users ||= AuthLh.get_users({ pagination: 'false' })
end
+ def all_external_with_role(role_code)
+ all_external.find_all { |x| x.has_role?(role_code) }
+ end
+
+ def all_external_with_some_role(role_codes)
+ all_external.find_all { |x|
+ role_codes.any? { |role_code| x.has_role?(role_code) }
+ }
+ end
+
def find_external(login)
all_external.find { |x| x.login == login.to_s }
end
+ def clear_cache!
+ @cached_users = nil
+ end
+
def find_current_user(session_token, remote_ip, return_url=nil)
- response = AuthLh.get_current_user(session_token, remote_ip, return_url)
+ response = AuthLh::Api.get_current_user(session_token, remote_ip, return_url)
logged_user = response.user
@destination_url = response.destination_url
if logged_user
@@ -42,23 +72,23 @@
def login_url(return_url=nil)
if @destination_url.present?
@destination_url
else
- AuthLh.login_url(return_url)
+ AuthLh::Api.login_url(return_url)
end
end
def logout_url(return_url=nil)
- AuthLh.logout_url(return_url)
+ AuthLh::Api.logout_url(return_url)
end
def change_password_url(return_url=nil)
- AuthLh.change_password_url(return_url)
+ AuthLh::Api.change_password_url(return_url)
end
def my_apps_url
- AuthLh.my_apps_url
+ AuthLh::Api.my_apps_url
end
end
end
end