module MinimalistAuthentication::User
Constants
- GUEST_USER_EMAIL
Public Instance Methods
Returns true if password matches the hashed_password, otherwise returns false.
# File lib/minimalist_authentication/user.rb, line 80 def authenticated?(password) MinimalistAuthentication.deprecator.warn(<<-MSG.squish) Calling #authenticated? is deprecated. Use #authenticate instead. MSG authenticate(password) end
Called after a user is authenticated to determine if the user object should be returned.
# File lib/minimalist_authentication/user.rb, line 58 def enabled self if enabled? end
Returns true if the user is enabled. Override this method in your user model to implement custom logic that determines if a user is eligible to log in.
# File lib/minimalist_authentication/user.rb, line 64 def enabled? active? end
Remove the has_secure_password password blank error if password is not required.
# File lib/minimalist_authentication/user.rb, line 69 def errors super.tap { |errors| errors.delete(:password, :blank) unless validate_password? } end
Check if user is a guest based on their email attribute
# File lib/minimalist_authentication/user.rb, line 88 def guest? email == GUEST_USER_EMAIL end
Returns true if the user is not active.
# File lib/minimalist_authentication/user.rb, line 74 def inactive? MinimalistAuthentication.deprecator.warn("Calling #inactive? is deprecated.") !active? end
Sets last_logged_in_at to the current time without updating the updated_at timestamp.
# File lib/minimalist_authentication/user.rb, line 93 def logged_in update_column(:last_logged_in_at, Time.current) end
Checks for password presence
# File lib/minimalist_authentication/user.rb, line 101 def password? password.present? end
Ensure password does not match username or email.
# File lib/minimalist_authentication/user.rb, line 108 def password_exclusivity %w[username email].each do |field| errors.add(:password, "can not match #{field}") if password.casecmp?(try(field)) end end
Minimum password length
# File lib/minimalist_authentication/user.rb, line 98 def password_minimum = 12 # Checks for password presence def password? password.present? end private # Ensure password does not match username or email. def password_exclusivity %w[username email].each do |field| errors.add(:password, "can not match #{field}") if password.casecmp?(try(field)) end end # Require password for active users that either do no have a password hash # stored OR are attempting to set a new password. Set **password_required** # to true to force validations even when the password field is blank. def validate_password? active? && (password_digest.blank? || password? || password_required?) end # Validate email for all users. # Applications can turn off email validation by setting the validate_email # configuration attribute to false. def validate_email? MinimalistAuthentication.configuration.validate_email end # Validate email presence for active users. # Applications can turn off email presence validation by setting # validate_email_presence configuration attribute to false. def validate_email_presence? MinimalistAuthentication.configuration.validate_email_presence && validate_email? && active? end end
Validate email for all users. Applications can turn off email validation by setting the validate_email configuration attribute to false.
# File lib/minimalist_authentication/user.rb, line 124 def validate_email? MinimalistAuthentication.configuration.validate_email end
Validate email presence for active users. Applications can turn off email presence validation by setting validate_email_presence configuration attribute to false.
# File lib/minimalist_authentication/user.rb, line 131 def validate_email_presence? MinimalistAuthentication.configuration.validate_email_presence && validate_email? && active? end
Require password for active users that either do no have a password hash stored OR are attempting to set a new password. Set password_required to true to force validations even when the password field is blank.
# File lib/minimalist_authentication/user.rb, line 117 def validate_password? active? && (password_digest.blank? || password? || password_required?) end