class DeviseAuthProxy::Manager
The Manager
class is responsible for connecting the appliation's User class with proxy user information in the request environment.
Attributes
env[R]
klass[R]
Public Class Methods
new(klass, env)
click to toggle source
# File lib/devise_auth_proxy/manager.rb, line 11 def initialize(klass, env) @klass = klass @env = env end
Public Instance Methods
create_user()
click to toggle source
# File lib/devise_auth_proxy/manager.rb, line 35 def create_user unless Devise.mappings[:admin_user].strategies.include?(:database_authenticatable) if DeviseAuthProxy.specific_database != :disable klass.with(client: DeviseAuthProxy.specific_database) do |admin| return admin.create(user_criterion) end end return klass.create(user_criterion) end random_password = SecureRandom.hex(16) attrs = user_criterion.merge({ password: random_password, password_confirmation: random_password, roles: DeviseAuthProxy.default_role }) if DeviseAuthProxy.specific_database != :disable klass.with(client: DeviseAuthProxy.specific_database) do |admin| return admin.create(attrs) end end klass.create(attrs) end
find_or_create_user()
click to toggle source
# File lib/devise_auth_proxy/manager.rb, line 16 def find_or_create_user user = find_user if !user && DeviseAuthProxy.auto_create user = create_user end update_user(user) if user && DeviseAuthProxy.auto_update user end
find_user()
click to toggle source
# File lib/devise_auth_proxy/manager.rb, line 25 def find_user if DeviseAuthProxy.specific_database != :disable klass.with(client: DeviseAuthProxy.specific_database) do |admin| return admin.where(user_criterion).first end end klass.where(user_criterion).first end
update_user(user)
click to toggle source
# File lib/devise_auth_proxy/manager.rb, line 61 def update_user(user) user.update_attributes(proxy_user_attributes) end
Protected Instance Methods
auth_key()
click to toggle source
# File lib/devise_auth_proxy/manager.rb, line 79 def auth_key DeviseAuthProxy.auth_key || Devise.authentication_keys.first end
proxy_user_attributes()
click to toggle source
# File lib/devise_auth_proxy/manager.rb, line 67 def proxy_user_attributes DeviseAuthProxy.attribute_map.inject({}) { |h, (k, v)| h[k] = env[v] if env.has_key?(v); h } end
proxy_user_id()
click to toggle source
# File lib/devise_auth_proxy/manager.rb, line 75 def proxy_user_id DeviseAuthProxy.proxy_user_id(env) end
user_criterion()
click to toggle source
# File lib/devise_auth_proxy/manager.rb, line 71 def user_criterion {auth_key => proxy_user_id} end