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.



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

def confirm_password=(value)
  @confirm_password = value
end

Class Method Details

.authenticate(login_or_email, password) ⇒ Object



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

def self.authenticate(, password)
  user = find(:first, :conditions => ["login = ? OR email = ?", , ])
  user if user && user.authenticated?(password)
end

.unprotected_attributesObject



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

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

.unprotected_attributes=(array) ⇒ Object



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

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

Instance Method Details

#after_initializeObject



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

def after_initialize
  @confirm_password = true
end

#authenticated?(password) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#confirm_password?Boolean

Returns:

  • (Boolean)


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

def confirm_password?
  @confirm_password
end

#forget_meObject



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

def forget_me
  update_attribute(:session_token, nil)
end

#has_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#remember_meObject



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

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

#sha1(phrase) ⇒ Object



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

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