Class: SequelUser

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/models/sequel_user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object (protected)



50
51
52
# File 'lib/models/sequel_user.rb', line 50

def method_missing(m, *args)
  return false
end

Instance Attribute Details

#password_confirmation=(value) ⇒ Object (writeonly)

Sets the attribute password_confirmation

Parameters:

  • value

    the value to set the attribute password_confirmation to.



18
19
20
# File 'lib/models/sequel_user.rb', line 18

def password_confirmation=(value)
  @password_confirmation = value
end

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/models/sequel_user.rb', line 40

def admin?
  self.permission_level == -1 || self.id == 1
end

#password=(pass) ⇒ Object

TODO validate format of email



34
35
36
37
38
# File 'lib/models/sequel_user.rb', line 34

def password=(pass)
  @password = pass
  self.salt = User.random_string(10) if !self.salt
  self.hashed_password = User.encrypt(@password, self.salt)
end

#site_admin?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/models/sequel_user.rb', line 44

def site_admin?
  self.id == 1
end

#validateObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/models/sequel_user.rb', line 22

def validate
  super
  email_regexp = /(\A(\s*)\Z)|(\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z)/i
  validates_format email_regexp, :email
  validates_presence :email
  validates_unique :email
  validates_presence :password if new?
  errors.add :passwords, ' don\'t match' unless @password == @password_confirmation
  #validate equality?
end