1
0
Fork 0
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:
José Valim 2010-02-17 12:35:38 +01:00
parent 8e21373946
commit 691f9324f5
9 changed files with 28 additions and 51 deletions

View file

@ -2,9 +2,9 @@ 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
included do
helper_method :warden, :signed_in?, :devise_controller?,
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
@ -14,7 +14,6 @@ module Devise
Devise::Mapping.default_url_options
end
end
end
# The main accessor for the warden proxy instance
def warden

View file

@ -27,14 +27,12 @@ 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
included do
attr_reader :password, :current_password
attr_accessor :password_confirmation
end
end
# Regenerates password salt and encrypted password each time password is set,
# and then trigger any "after_changed_password"-callbacks.

View file

@ -29,16 +29,13 @@ 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
included do
before_create :generate_confirmation_token, :if => :confirmation_required?
after_create :send_confirmation_instructions, :if => :confirmation_required?
end
end
# Confirm a user by setting it's confirmed_at to actual time. If the user
# is already confirmed, add en error to email field

View file

@ -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.

View file

@ -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

View file

@ -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.

View file

@ -30,15 +30,12 @@ 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
included do
# Remember me option available in after_authentication hook.
attr_accessor :remember_me
end
end
# Generate a new remember token and save the record without validations.
def remember_me!

View file

@ -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)

View file

@ -18,12 +18,11 @@ module Devise
# User.find(1).valid_authentication_token?('rI1t6PKQ8yP7VetgwdybB') # returns true/false
#
module TokenAuthenticatable
def self.included(base)
base.class_eval do
extend ClassMethods
extend ActiveSupport::Concern
included do
before_save :ensure_authentication_token
end
end
# Generate new authentication token (a.k.a. "single access token").
def reset_authentication_token