Class: User
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#role?, #role_names, #role_names=
Instance Attribute Details
#confirm_password ⇒ Object
Returns the value of attribute confirm_password.
6
7
8
|
# File 'app/models/user.rb', line 6
def confirm_password
@confirm_password
end
|
#password ⇒ Object
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
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 last_login_at && last_login_at > 10.minutes.ago
update(last_login_at: Time.now.utc)
end
|
#name_and_email ⇒ Object
73
74
75
|
# File 'app/models/user.rb', line 73
def name_and_email
"#{name} <#{email}>"
end
|
#online? ⇒ Boolean
77
78
79
|
# File 'app/models/user.rb', line 77
def online?
last_login_at && last_login_at > 15.minutes.ago
end
|
#realname ⇒ Object
81
82
83
|
# File 'app/models/user.rb', line 81
def realname
name
end
|