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_after_rpx_connect(rpx_user) ⇒ Object
Hook that gets called after connect (each time).
-
#on_before_rpx_connect(rpx_user) ⇒ Object
Hook that gets called before connect (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:
28 29 30 31 32 |
# File 'lib/devise_rpx_connectable/model.rb', line 28 def self.included(base) #:nodoc: base.class_eval do extend ClassMethods end end |
Instance Method Details
#on_after_rpx_connect(rpx_user) ⇒ Object
Hook that gets called after connect (each time). Useful for fetching additional user info (etc.) from RPX.
Default: Do nothing.
Example:
# Overridden in RPX connectable model, e.g. "User".
#
def after_rpx_connect(rpx_user)
# See "on_before_rpx_connect" example.
end
99 100 101 102 103 |
# File 'lib/devise_rpx_connectable/model.rb', line 99 def on_after_rpx_connect(rpx_user) if self.respond_to?(:after_rpx_connect) self.send(:after_rpx_connect, rpx_user) rescue nil end end |
#on_before_rpx_connect(rpx_user) ⇒ Object
Hook that gets called before connect (each time). Useful for fetching additional user info (etc.) from RPX.
Default: Do nothing.
Examples:
# Overridden in RPX connectable model, e.g. "User".
#
def before_rpx_connect(rpx_user)
# Get email (if the provider supports it)
email = rpx_user["email"]
# etc...
end
For more info:
* http://github.com/grosser/rpx_now
80 81 82 83 84 |
# File 'lib/devise_rpx_connectable/model.rb', line 80 def on_before_rpx_connect(rpx_user) if self.respond_to?(:before_rpx_connect) self.send(:before_rpx_connect, rpx_user) rescue nil end end |
#rpx_connected? ⇒ Boolean Also known as: is_rpx_connected?
Checks if RPX connected.
54 55 56 |
# File 'lib/devise_rpx_connectable/model.rb', line 54 def rpx_connected? self.send(:"#{self.class.rpx_identifier_field}").present? end |
#store_rpx_credentials!(attributes = {}) ⇒ Object
Store RPX account/session credentials.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/devise_rpx_connectable/model.rb', line 36 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) # 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 |