mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Use ActiveSupport::Concern.
This commit is contained in:
parent
8e21373946
commit
691f9324f5
9 changed files with 28 additions and 51 deletions
|
@ -2,17 +2,16 @@ module Devise
|
|||
module Controllers
|
||||
# Those helpers are convenience methods added to ApplicationController.
|
||||
module Helpers
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
helper_method :warden, :signed_in?, :devise_controller?,
|
||||
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
|
||||
included do
|
||||
helper_method :warden, :signed_in?, :devise_controller?,
|
||||
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
|
||||
|
||||
# Use devise default_url_options. We have to declare it here to overwrite
|
||||
# default definitions.
|
||||
def default_url_options(options=nil)
|
||||
Devise::Mapping.default_url_options
|
||||
end
|
||||
# Use devise default_url_options. We have to declare it here to overwrite
|
||||
# default definitions.
|
||||
def default_url_options(options=nil)
|
||||
Devise::Mapping.default_url_options
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -27,13 +27,11 @@ module Devise
|
|||
# User.find(1).valid_password?('password123') # returns true/false
|
||||
#
|
||||
module Authenticatable
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
extend ClassMethods
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
attr_reader :password, :current_password
|
||||
attr_accessor :password_confirmation
|
||||
end
|
||||
included do
|
||||
attr_reader :password, :current_password
|
||||
attr_accessor :password_confirmation
|
||||
end
|
||||
|
||||
# Regenerates password salt and encrypted password each time password is set,
|
||||
|
|
|
@ -29,15 +29,12 @@ module Devise
|
|||
# User.find(1).send_confirmation_instructions # manually send instructions
|
||||
# User.find(1).resend_confirmation! # generates a new token and resent it
|
||||
module Confirmable
|
||||
extend ActiveSupport::Concern
|
||||
include Devise::Models::Activatable
|
||||
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
extend ClassMethods
|
||||
|
||||
before_create :generate_confirmation_token, :if => :confirmation_required?
|
||||
after_create :send_confirmation_instructions, :if => :confirmation_required?
|
||||
end
|
||||
included do
|
||||
before_create :generate_confirmation_token, :if => :confirmation_required?
|
||||
after_create :send_confirmation_instructions, :if => :confirmation_required?
|
||||
end
|
||||
|
||||
# Confirm a user by setting it's confirmed_at to actual time. If the user
|
||||
|
|
|
@ -6,9 +6,7 @@ module Devise
|
|||
# model class responds to authenticate and authentication_keys methods
|
||||
# (which for example are defined in authenticatable).
|
||||
module HttpAuthenticatable
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
end
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
# Authenticate an user using http.
|
||||
|
|
|
@ -18,14 +18,9 @@ module Devise
|
|||
# available when unlock_strategy is :time or :both.
|
||||
#
|
||||
module Lockable
|
||||
extend ActiveSupport::Concern
|
||||
include Devise::Models::Activatable
|
||||
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
extend ClassMethods
|
||||
end
|
||||
end
|
||||
|
||||
# Lock an user setting it's locked_at to actual time.
|
||||
def lock
|
||||
self.locked_at = Time.now
|
||||
|
|
|
@ -14,11 +14,7 @@ module Devise
|
|||
# # creates a new token and send it with instructions about how to reset the password
|
||||
# User.find(1).send_reset_password_instructions
|
||||
module Recoverable
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
extend ClassMethods
|
||||
end
|
||||
end
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
# Update password saving the record and clearing token. Returns true if
|
||||
# the passwords are valid and the record was saved, false otherwise.
|
||||
|
|
|
@ -30,14 +30,11 @@ module Devise
|
|||
# # lookup the user based on the incoming cookie information
|
||||
# User.serialize_from_cookie(cookie_string)
|
||||
module Rememberable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
extend ClassMethods
|
||||
|
||||
# Remember me option available in after_authentication hook.
|
||||
attr_accessor :remember_me
|
||||
end
|
||||
included do
|
||||
# Remember me option available in after_authentication hook.
|
||||
attr_accessor :remember_me
|
||||
end
|
||||
|
||||
# Generate a new remember token and save the record without validations.
|
||||
|
|
|
@ -11,9 +11,7 @@ module Devise
|
|||
#
|
||||
# timeout_in: the time you want to timeout the user session without activity.
|
||||
module Timeoutable
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
end
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
# Checks whether the user session has expired based on configured time.
|
||||
def timedout?(last_access)
|
||||
|
|
|
@ -18,11 +18,10 @@ module Devise
|
|||
# User.find(1).valid_authentication_token?('rI1t6PKQ8yP7VetgwdybB') # returns true/false
|
||||
#
|
||||
module TokenAuthenticatable
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
extend ClassMethods
|
||||
before_save :ensure_authentication_token
|
||||
end
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_save :ensure_authentication_token
|
||||
end
|
||||
|
||||
# Generate new authentication token (a.k.a. "single access token").
|
||||
|
|
Loading…
Add table
Reference in a new issue