1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Allow schema options to work together with devise method in ORMs where devise and schema are in the same class (as in Datamapper and MongoMapper).

This commit is contained in:
José Valim 2009-11-15 20:35:19 -02:00
parent 1f98eed6f6
commit 6ba42affc7

View file

@ -6,13 +6,19 @@ module Devise
# Creates email, encrypted_password and password_salt. # Creates email, encrypted_password and password_salt.
# #
# == Options # == Options
# * :null when true, allow columns to be null # * :null - When true, allow columns to be null.
# * :encryptor The encryptor going to be used, necessary for setting the proper encrypter password length # * :encryptor - The encryptor going to be used, necessary for setting the proper encrypter password length.
# * :skip_email - If you want to use another authentication key, you can skip e-mail creation.
# If you are using an ORM where the devise declaration is in the same class as the schema,
# as in Datamapper or Mongomapper, the email is skipped automatically if not included in
# authentication_keys.
def authenticatable(options={}) def authenticatable(options={})
null = options[:null] || false null = options[:null] || false
encryptor = options[:encryptor] || :sha1 encryptor = options[:encryptor] || (respond_to?(:encryptor) ? self.encryptor : :sha1)
have_email = respond_to?(:authentication_keys) ? self.authentication_keys.include?(:email) : true
skip_email = options[:skip_email] || !have_email
apply_schema :email, String, :null => null, :limit => 100 apply_schema :email, String, :null => null, :limit => 100 unless skip_email
apply_schema :encrypted_password, String, :null => null, :limit => Devise::ENCRYPTORS_LENGTH[encryptor] apply_schema :encrypted_password, String, :null => null, :limit => Devise::ENCRYPTORS_LENGTH[encryptor]
apply_schema :password_salt, String, :null => null, :limit => 20 apply_schema :password_salt, String, :null => null, :limit => 20
end end