Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#confirm_password=(value) ⇒ Object (writeonly)

Sets the attribute confirm_password

Parameters:

  • value

    the value to set the attribute confirm_password to.



29
30
31
# File 'app/models/user.rb', line 29

def confirm_password=(value)
  @confirm_password = value
end

Class Method Details

.authenticate(login, password) ⇒ Object



48
49
50
51
# File 'app/models/user.rb', line 48

def self.authenticate(, password)
  user = ()
  user if user && user.authenticated?(password)
end

.protected_attributesObject



31
32
33
# File 'app/models/user.rb', line 31

def protected_attributes
  @protected_attributes ||= [:name, :email, :login, :password, :password_confirmation]
end

.protected_attributes=(array) ⇒ Object



35
36
37
# File 'app/models/user.rb', line 35

def protected_attributes=(array)
  @protected_attributes = array.map{|att| att.to_sym }
end

Instance Method Details

#after_initializeObject



57
58
59
# File 'app/models/user.rb', line 57

def after_initialize
  @confirm_password = true
end

#authenticated?(password) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/user.rb', line 53

def authenticated?(password)
  self.password == sha1(password)
end

#confirm_password?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/models/user.rb', line 61

def confirm_password?
  @confirm_password
end

#forget_meObject



69
70
71
# File 'app/models/user.rb', line 69

def forget_me
  update_attribute(:session_token, nil)
end

#has_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/user.rb', line 40

def has_role?(role)
  respond_to?("#{role}?") && send("#{role}?")
end

#remember_meObject



65
66
67
# File 'app/models/user.rb', line 65

def remember_me
  update_attribute(:session_token, sha1(Time.now + Radiant::Config['session_timeout'].to_i)) unless self.session_token?
end

#sha1(phrase) ⇒ Object



44
45
46
# File 'app/models/user.rb', line 44

def sha1(phrase)
  Digest::SHA1.hexdigest("--#{salt}--#{phrase}--")
end