Class: User

Inherits:
ApplicationRecord
  • Object
show all
Includes:
PagesCore::HasRoles
Defined in:
app/models/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PagesCore::HasRoles

#role?, #role_names, #role_names=

Instance Attribute Details

#confirm_passwordObject

Returns the value of attribute confirm_password.



6
7
8
# File 'app/models/user.rb', line 6

def confirm_password
  @confirm_password
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'app/models/user.rb', line 6

def password
  @password
end

Class Method Details

.authenticate(email, password:) ⇒ Object



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

def authenticate(email, password:)
  user = User.find_by_email(email)
  user if user.try { |u| u.authenticate!(password) }
end

.find_by_email(str) ⇒ Object



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

def find_by_email(str)
  find_by("LOWER(email) = ?", str.to_s.downcase)
end

Instance Method Details

#authenticate!(password) ⇒ Object



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

def authenticate!(password)
  return false unless can_login? && valid_password?(password)

  rehash_password!(password) if password_needs_rehash?
  true
end

#can_login?Boolean

Returns:

  • (Boolean)


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

def can_login?
  activated?
end

#mark_active!Object



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

def mark_active!
  return if  &&  > 10.minutes.ago

  update(last_login_at: Time.now.utc)
end

#name_and_emailObject



73
74
75
# File 'app/models/user.rb', line 73

def name_and_email
  "#{name} <#{email}>"
end

#online?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'app/models/user.rb', line 77

def online?
   &&  > 15.minutes.ago
end

#realnameObject



81
82
83
# File 'app/models/user.rb', line 81

def realname
  name
end