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.



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

def confirm_password=(value)
  @confirm_password = value
end

Class Method Details

.authenticate(login_or_email, password) ⇒ Object



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

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

Instance Method Details

#after_initializeObject



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

def after_initialize
  @confirm_password = true
end

#authenticated?(password) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#confirm_password?Boolean

Returns:

  • (Boolean)


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

def confirm_password?
  @confirm_password
end

#forget_meObject



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

def forget_me
  update_attribute(:session_token, nil)
end

#has_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#remember_meObject



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

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

#send_password_resetObject



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

def send_password_reset
  generate_token(:password_reset_token)
  update_attribute(:password_reset_sent_at, Time.zone.now)
  PasswordMailer.password_reset(self).deliver_now
end

#sha1(phrase) ⇒ Object



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

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