Class: Opro::AuthProvider::Devise
- Inherits:
-
Object
- Object
- Opro::AuthProvider::Devise
- Defined in:
- lib/opro/auth_provider/devise.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
Instance Method Summary collapse
- #authenticate_user_method ⇒ Object
- #find_user_for_auth(params) ⇒ Object
-
#initialize(controller) ⇒ Devise
constructor
A new instance of Devise.
- #login_method(current_user) ⇒ Object
- #logout_method(current_user) ⇒ Object
Constructor Details
#initialize(controller) ⇒ Devise
Returns a new instance of Devise.
6 7 8 |
# File 'lib/opro/auth_provider/devise.rb', line 6 def initialize(controller) @controller = controller end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
4 5 6 |
# File 'lib/opro/auth_provider/devise.rb', line 4 def controller @controller end |
Instance Method Details
#authenticate_user_method ⇒ Object
18 19 20 |
# File 'lib/opro/auth_provider/devise.rb', line 18 def authenticate_user_method controller.authenticate_user! end |
#find_user_for_auth(params) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/opro/auth_provider/devise.rb', line 22 def find_user_for_auth(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) } # Try to get fancy, some clients have :username hardcoded, if we have nothing in our find hash # we can make an educated guess here 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 |
#login_method(current_user) ⇒ Object
10 11 12 |
# File 'lib/opro/auth_provider/devise.rb', line 10 def login_method(current_user) controller.sign_in(current_user, :bypass => true) end |
#logout_method(current_user) ⇒ Object
14 15 16 |
# File 'lib/opro/auth_provider/devise.rb', line 14 def logout_method(current_user) controller.sign_out(current_user) end |