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



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

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

Instance Method Details

#after_initializeObject



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

def after_initialize
  @confirm_password = true
end

#authenticated?(password) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#confirm_password?Boolean

Returns:

  • (Boolean)


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

def confirm_password?
  @confirm_password
end

#forget_meObject



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

def forget_me
  update_attribute(:session_token, nil)
end

#has_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#remember_meObject



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

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

#sha1(phrase) ⇒ Object



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

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