Module: Opro
- Defined in:
- lib/opro/controllers/application_controller_helper.rb,
lib/opro.rb,
lib/opro/engine.rb,
lib/generators/opro/install_generator.rb
Overview
this concern gets put into ApplicationController
Defined Under Namespace
Modules: Controllers, Generators, Oauth
Classes: Engine
Class Method Summary
collapse
Class Method Details
.auth_strategy(auth_strategy = nil) ⇒ Object
Used by set_login_logout_methods to pre-define login, logout, and authenticate methods
60
61
62
63
64
65
66
|
# File 'lib/opro.rb', line 60
def self.auth_strategy(auth_strategy = nil)
if auth_strategy.present?
@auth_strategy = auth_strategy
else
@auth_strategy
end
end
|
.auth_strategy=(auth_strategy) ⇒ Object
68
69
70
|
# File 'lib/opro.rb', line 68
def self.auth_strategy=(auth_strategy)
@auth_strategy = auth_strategy
end
|
.authenticate_user_method(&block) ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/opro.rb', line 105
def self.authenticate_user_method(&block)
if block.present?
@authenticate_user_method = block
else
@authenticate_user_method or raise 'authenticate_user_method not set, please specify Opro auth_strategy'
end
end
|
.convert_to_lambda(&block) ⇒ Object
Grossssss, don’t use, needed to support ‘return` from the blocks provided to `find_user_for_auth`
125
126
127
128
129
|
# File 'lib/opro.rb', line 125
def self.convert_to_lambda &block
obj = Object.new
obj.define_singleton_method(:_, &block)
return obj.method(:_).to_proc
end
|
.find_user_for_all_auths!(controller, params) ⇒ Object
calls all of the different auths made available,
114
115
116
117
118
119
120
121
|
# File 'lib/opro.rb', line 114
def self.find_user_for_all_auths!(controller, params)
@user = false
find_user_for_auth.each do |auth_block|
break if @user.present?
@user = auth_block.call(controller, params)
end
@user
end
|
.find_user_for_auth(&block) ⇒ Object
holds an Array of authentication blocks is called by find_user_for_all_auths! in token controller can be used for finding users using multiple methods (password, facebook, twitter, etc.)
133
134
135
136
137
138
139
140
|
# File 'lib/opro.rb', line 133
def self.find_user_for_auth(&block)
if block.present?
@find_for_authentication ||= []
@find_for_authentication << convert_to_lambda(&block)
else
@find_for_authentication or raise 'find_for_authentication not set, please specify Opro auth_strategy'
end
end
|
.include_helpers(scope) ⇒ Object
Include helpers in the given scope to AC and AV.
10
11
12
13
14
|
# File 'lib/opro.rb', line 10
def self.include_helpers(scope)
ActiveSupport.on_load(:action_controller) do
include scope::ApplicationControllerHelper if defined?(scope::ApplicationControllerHelper)
end
end
|
.login(*args) ⇒ Object
Used by application controller to log user in
48
49
50
51
|
# File 'lib/opro.rb', line 48
def self.login(*args)
raise 'login method not set, please specify Opro auth_strategy' if login_method.blank?
login_method.call(*args)
end
|
.login_method(&block) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/opro.rb', line 73
def self.login_method(&block)
if block.present?
@login_method = block
else
@login_method or raise 'login method not set, please specify Opro auth_strategy'
end
end
|
.logout(*args) ⇒ Object
Used by application controller to log user out
54
55
56
57
|
# File 'lib/opro.rb', line 54
def self.logout(*args)
raise 'login method not set, please specify Opro auth_strategy' if login_method.blank?
logout_method.call(*args)
end
|
.logout_method(&block) ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/opro.rb', line 97
def self.logout_method(&block)
if block.present?
@logout_method = block
else
@logout_method or raise 'login method not set, please specify Opro auth_strategy'
end
end
|
.password_exchange_enabled=(password_exchange_enabled) ⇒ Object
142
143
144
|
# File 'lib/opro.rb', line 142
def self.password_exchange_enabled=(password_exchange_enabled)
@password_exchange_enabled = password_exchange_enabled
end
|
.password_exchange_enabled? ⇒ Boolean
146
147
148
|
# File 'lib/opro.rb', line 146
def self.password_exchange_enabled?
@password_exchange_enabled
end
|
.request_permissions ⇒ Object
85
86
87
|
# File 'lib/opro.rb', line 85
def self.request_permissions
@request_permissions || []
end
|
.request_permissions=(permissions) ⇒ Object
81
82
83
|
# File 'lib/opro.rb', line 81
def self.request_permissions=(permissions)
@request_permissions = permissions
end
|
.require_refresh_within ⇒ Object
93
94
95
|
# File 'lib/opro.rb', line 93
def self.require_refresh_within
@require_refresh_within
end
|
.require_refresh_within=(require_refresh_within) ⇒ Object
89
90
91
|
# File 'lib/opro.rb', line 89
def self.require_refresh_within=(require_refresh_within)
@require_refresh_within = require_refresh_within
end
|
.set_login_logout_methods ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/opro.rb', line 22
def self.set_login_logout_methods
case auth_strategy
when :devise
login_method { |controller, current_user| controller.sign_in(current_user, :bypass => true) }
logout_method { |controller, current_user| controller.sign_out(current_user) }
authenticate_user_method { |controller| controller.authenticate_user! }
find_user_for_auth do |controller, params|
return false if params[:password].blank?
find_params = params.each_with_object({}) {|(key,value), hash| hash[key] = value if Devise.authentication_keys.include?(key.to_sym) }
if find_params.blank? && params[:username].present?
find_params = { Devise.authentication_keys.first => params[:username] }
end
user = User.where(find_params).first if find_params.present?
return false unless user.present?
return false unless user.valid_password?(params[:password])
user
end
else
end
end
|
.setup {|_self| ... } ⇒ Object
17
18
19
20
|
# File 'lib/opro.rb', line 17
def self.setup
yield self
set_login_logout_methods
end
|