Class: DeviseAuthProxy::Manager
- Inherits:
-
Object
- Object
- DeviseAuthProxy::Manager
- Defined in:
- lib/devise_auth_proxy/manager.rb
Overview
The Manager class is responsible for connecting the appliation’s User class with proxy user information in the request environment.
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #create_user ⇒ Object
- #find_or_create_user ⇒ Object
- #find_user ⇒ Object
-
#initialize(klass, env) ⇒ Manager
constructor
A new instance of Manager.
- #update_user(user) ⇒ Object
Constructor Details
#initialize(klass, env) ⇒ Manager
11 12 13 14 |
# File 'lib/devise_auth_proxy/manager.rb', line 11 def initialize(klass, env) @klass = klass @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
9 10 11 |
# File 'lib/devise_auth_proxy/manager.rb', line 9 def env @env end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
9 10 11 |
# File 'lib/devise_auth_proxy/manager.rb', line 9 def klass @klass end |
Instance Method Details
#create_user ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 ⇒ Object
16 17 18 19 20 21 22 23 |
# 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 ⇒ Object
25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
61 62 63 |
# File 'lib/devise_auth_proxy/manager.rb', line 61 def update_user(user) user.update_attributes(proxy_user_attributes) end |