Sha256: 11e27fb6d77f1e0b70abc141fac4edd3ed34a56748c7719e159154231901bc86
Contents?: true
Size: 1.72 KB
Versions: 6
Compression:
Stored size: 1.72 KB
Contents
class <%= options[:admin_model].underscore.camelize %> include Mongoid::Document attr_accessor :password, :password_confirmation # Fields field :name, :type => String field :surname, :type => String field :email, :type => String field :crypted_password, :type => String field :role, :type => String # Validations validates_presence_of :email, :role validates_presence_of :password, :if => :password_required validates_presence_of :password_confirmation, :if => :password_required validates_length_of :password, :within => 4..40, :if => :password_required validates_confirmation_of :password, :if => :password_required validates_length_of :email, :within => 3..100 validates_uniqueness_of :email, :case_sensitive => false validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i validates_format_of :role, :with => /[A-Za-z]/ # Callbacks before_save :encrypt_password, :if => :password_required ## # This method is for authentication purpose # def self.authenticate(email, password) account = first(:conditions => { :email => email }) if email.present? account && account.has_password?(password) ? account : nil end ## # This method is used by AuthenticationHelper # def self.find_by_id(id) find(id) rescue nil end def has_password?(password) ::BCrypt::Password.new(crypted_password) == password end private def encrypt_password self.crypted_password = ::BCrypt::Password.create(self.password) end def password_required crypted_password.blank? || self.password.present? end end
Version data entries
6 entries across 6 versions & 1 rubygems