Module: Devise::Models::KoalaConnectable
- Defined in:
- lib/devise_koala_connectable/model.rb
Overview
Koala Connectable Module, responsible for validating authenticity of a user and storing credentials while signing in.
Configuration:
You can overwrite configuration values by setting in globally in Devise (Devise.setup
), using devise method, or overwriting the respective instance method.
koala_identifier_field
- Defines the name of the Koala identifier database attribute/column.
koala_auto_create_account
- Speifies if account should automatically be created upon connect
if not already exists.
Examples:
User.authenticate_with_koala(:identifier => '[email protected]') # returns authenticated user or nil
User.find(1).koala_connected? # returns true/false
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#koala_connected? ⇒ Boolean
(also: #is_koala_connected?)
Checks if Koala connected.
-
#on_before_koala_auto_create(koala_user) ⇒ Object
Hook that gets called before the auto creation of the user.
-
#on_before_koala_success(koala_user) ⇒ Object
Hook that gets called before a successful connection (each time).
-
#store_koala_credentials!(attributes = {}) ⇒ Object
Store Koala account/session credentials.
Class Method Details
.included(base) ⇒ Object
:nodoc:
27 28 29 30 31 |
# File 'lib/devise_koala_connectable/model.rb', line 27 def self.included(base) #:nodoc: base.class_eval do extend ClassMethods end end |
Instance Method Details
#koala_connected? ⇒ Boolean Also known as: is_koala_connected?
Checks if Koala connected.
53 54 55 |
# File 'lib/devise_koala_connectable/model.rb', line 53 def koala_connected? self.send(:"#{self.class.koala_identifier_field}").present? end |
#on_before_koala_auto_create(koala_user) ⇒ Object
Hook that gets called before the auto creation of the user. Therefore, this hook is only called when koala_auto_create_account config option is enabled. Useful for fetching additional user info (etc.) from Facebook.
Default: Do nothing.
Example:
# Overridden in Koala connectable model, e.g. "User".
#
def before_koala_auto_create(koala_user)
# Get email (if the provider supports it)
email = koala_user["email"]
# etc...
end
97 98 99 |
# File 'lib/devise_koala_connectable/model.rb', line 97 def on_before_koala_auto_create(koala_user) self.send(:before_koala_auto_create, koala_user) if self.respond_to?(:before_koala_auto_create) end |
#on_before_koala_success(koala_user) ⇒ Object
Hook that gets called before a successful connection (each time). Useful for fetching additional user info (etc.) from Facebook.
Default: Do nothing.
Example:
# Overridden in Koala connectable model, e.g. "User".
#
def before_koala_success(koala_user)
# Get email (if the provider supports it)
email = koala_user["email"]
# etc...
end
75 76 77 |
# File 'lib/devise_koala_connectable/model.rb', line 75 def on_before_koala_success(koala_user) self.send(:before_koala_success, koala_user) if self.respond_to?(:before_koala_success) end |
#store_koala_credentials!(attributes = {}) ⇒ Object
Store Koala account/session credentials.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/devise_koala_connectable/model.rb', line 35 def store_koala_credentials!(attributes = {}) self.send(:"#{self.class.koala_identifier_field}=", attributes["id"]) # Confirm without e-mail - if confirmable module is loaded. self.skip_confirmation! if self.respond_to?(:skip_confirmation!) # Only populate +email+ field if it's available (e.g. if +authenticable+ module is used). self.email = attributes["email"] || '' if self.respond_to?(:email) # Lazy hack: These database fields are required if +authenticable+/+confirmable+ # module(s) is used. Could be avoided with :null => true for authenticatable # migration, but keeping this to avoid unnecessary problems. self.password_salt = '' if self.respond_to?(:password_salt) self.encrypted_password = '' if self.respond_to?(:encrypted_password) end |