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_passwordObject



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

def confirm_password
  @confirm_password = true
end

Class Method Details

.authenticate(login_or_email, password) ⇒ Object



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

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

.unprotected_attributesObject



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

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

.unprotected_attributes=(array) ⇒ Object



37
38
39
# File 'app/models/user.rb', line 37

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

Instance Method Details

#authenticated?(password) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#confirm_password?Boolean

Returns:

  • (Boolean)


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

def confirm_password?
  @confirm_password
end

#forget_meObject



71
72
73
# File 'app/models/user.rb', line 71

def forget_me
  update_attribute(:session_token, nil)
end

#has_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#remember_meObject



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

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

#sha1(phrase) ⇒ Object



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

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