Class: User

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PagesCore::HasRoles

#role?, #role_names, #role_names=

Methods included from PagesCore::HasOtp

#recovery_codes=, #use_recovery_code!

Class Method Details

.authenticate(email, password:) ⇒ Object



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

def authenticate(email, password:)
  User.find_by_email(email).try(:authenticate, password)
end

.find_by_email(str) ⇒ Object



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

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

Instance Method Details

#authenticate!(password) ⇒ Object



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

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)


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

def can_login?
  activated?
end

#mark_active!Object



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

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

  update(last_login_at: Time.now.utc)
end

#name_and_emailObject



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

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

#online?Boolean

Returns:

  • (Boolean)


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

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

#realnameObject



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

def realname
  name
end