Module: Devise::Models::RpxConnectable
- Defined in:
- lib/devise_rpx_connectable/model.rb
Overview
RPX 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.
rpx_identifier_field
- Defines the name of the RPX identifier database attribute/column.
rpx_auto_create_account
- Speifies if account should automatically be created upon connect
if not already exists.
Examples:
User.authenticate_with_rpx(:identifier => '[email protected]') # returns authenticated user or nil
User.find(1).rpx_connected? # returns true/false
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#on_before_rpx_auto_create(rpx_user) ⇒ Object
Hook that gets called before the auto creation of the user.
-
#on_before_rpx_success(rpx_user) ⇒ Object
Hook that gets called before a successful connection (each time).
-
#rpx_connected? ⇒ Boolean
(also: #is_rpx_connected?)
Checks if RPX connected.
-
#store_rpx_credentials!(attributes = {}) ⇒ Object
Store RPX account/session credentials.
Class Method Details
.included(base) ⇒ Object
:nodoc:
27 28 29 30 31 |
# File 'lib/devise_rpx_connectable/model.rb', line 27 def self.included(base) #:nodoc: base.class_eval do extend ClassMethods end end |
Instance Method Details
#on_before_rpx_auto_create(rpx_user) ⇒ Object
Hook that gets called before the auto creation of the user. Therefore, this hook is only called when rpx_auto_create_account config option is enabled. Useful for fetching additional user info (etc.) from RPX.
Default: Do nothing.
Example:
# Overridden in RPX connectable model, e.g. "User".
#
def before_rpx_auto_create(rpx_user)
# Get email (if the provider supports it)
email = rpx_user["email"]
# etc...
end
For more info:
* http://github.com/grosser/rpx_now
112 113 114 |
# File 'lib/devise_rpx_connectable/model.rb', line 112 def on_before_rpx_auto_create(rpx_user) self.send(:before_rpx_auto_create, rpx_user) if self.respond_to?(:before_rpx_auto_create) end |
#on_before_rpx_success(rpx_user) ⇒ Object
Hook that gets called before a successful connection (each time). Useful for fetching additional user info (etc.) from RPX.
Default: Do nothing.
Example:
# Overridden in RPX connectable model, e.g. "User".
#
def before_rpx_success(rpx_user)
# Get email (if the provider supports it)
email = rpx_user["email"]
# etc...
end
For more info:
* http://github.com/grosser/rpx_now
86 87 88 |
# File 'lib/devise_rpx_connectable/model.rb', line 86 def on_before_rpx_success(rpx_user) self.send(:before_rpx_success, rpx_user) if self.respond_to?(:before_rpx_success) end |
#rpx_connected? ⇒ Boolean Also known as: is_rpx_connected?
Checks if RPX connected.
60 61 62 |
# File 'lib/devise_rpx_connectable/model.rb', line 60 def rpx_connected? self.send(:"#{self.class.rpx_identifier_field}").present? end |
#store_rpx_credentials!(attributes = {}) ⇒ Object
Store RPX account/session credentials.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/devise_rpx_connectable/model.rb', line 35 def store_rpx_credentials!(attributes = {}) self.send(:"#{self.class.rpx_identifier_field}=", attributes[:identifier]) # 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) # Populate optional request fields if attributes[:request_keys] attributes[:request_keys].each do |k, v| self.send(:"#{k}=", v) end end # 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 |