Skip to content

Instantly share code, notes, and snippets.

@keo
Created November 27, 2010 00:04
Show Gist options
  • Save keo/717371 to your computer and use it in GitHub Desktop.
Save keo/717371 to your computer and use it in GitHub Desktop.
def self.included(base)
@user_models << base.name
base.extend(ClassMethods)
base.class_eval do
fields do
crypted_password :string, :limit => 40
salt :string, :limit => 40
remember_token :string
remember_token_expires_at :datetime
end
validates_confirmation_of :password, :if => :new_password_required?
password_validations
validate :validate_current_password_when_changing_password
# Virtual attributes for setting and changing the password
# note that :password_confirmation= is also defined by
# validates_confirmation_of, so this line must follow any
# validates_confirmation_of statements.
# https://hobo.lighthouseapp.com/projects/8324-hobo/tickets/530
attr_accessor :current_password, :password, :password_confirmation, :type => :password
before_save :encrypt_password
after_save :stash_current_password
never_show *AUTHENTICATION_FIELDS
attr_protected *AUTHENTICATION_FIELDS
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment