Module: Sinatra::SimpleAuthentication::Models::DataMapper::Adapter::ClassMethods

Defined in:
lib/sinatra/simple_authentication/models/datamapper/adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



25
26
27
# File 'lib/sinatra/simple_authentication/models/datamapper/adapter.rb', line 25

def settings
  @settings
end

Instance Method Details

#find_user(params) ⇒ Object



47
48
49
# File 'lib/sinatra/simple_authentication/models/datamapper/adapter.rb', line 47

def find_user(params)
  self.first(params)
end

#set_validation_rulesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sinatra/simple_authentication/models/datamapper/adapter.rb', line 27

def set_validation_rules
  validates_presence_of :email, :message => self.settings.error_messages[:missing_email]
  validates_uniqueness_of :email, :message => self.settings.error_messages[:taken_email]
  validates_format_of :email, :as => :email_address, :message => self.settings.error_messages[:invalid_email]

  if Proc.new { |t| t.new_record? }
    validates_presence_of :password, :message => self.settings.error_messages[:missing_password]
    validates_length_of :password, :min => self.settings.min_password_length, :message => self.settings.error_messages[:short_password]
    validates_length_of :password, :max => self.settings.max_password_length, :message => self.settings.error_messages[:long_password]

    if self.settings.use_password_confirmation
      validates_presence_of :password_confirmation, :message => self.settings.error_messages[:missing_password_confirmation]
    end
  end

  if self.settings.use_password_confirmation
    validates_confirmation_of :password, :message => self.settings.error_messages[:password_confirmation_dont_match_password]
  end
end