Class: Maquina::User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Maquina::User
- Includes:
- Blockeable, Multifactor, RetainPasswords
- Defined in:
- app/models/maquina/user.rb
Overview
A class representing the User model in the Maquina module.
Attributes
email
-
The user’s email address (required, unique, automatically normalized).
password
-
Encrypted password that must meet complexity requirements.
password_expires_at
-
Timestamp indicating when the password expires.
Associations
memberships
-
Has many memberships linking users to organizations.
active_sessions
-
Has many active sessions that are destroyed when the user is deleted.
Included Modules
RetainPasswords
-
Handles password retention functionality.
Blockeable
-
Provides blocking/unblocking capabilities.
Multifactor
-
Implements multi-factor authentication features.
Validations
email
-
Must be present, unique, and in valid email format.
password
-
Must contain at least:
-
8 characters
-
1 uppercase letter
-
1 lowercase letter
-
1 number
-
1 special character (@$!%*?&#-=+)
Normalizations
email
-
Automatically stripped of whitespace and converted to lowercase.
Security
Uses has_secure_password for password encryption and authentication.
Constant Summary collapse
- PASSWORD_COMPLEXITY_REGEX =
/\A(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&#-=+])[A-Za-z\d@$!%*?&#-=+]{8,}\z/
Instance Method Summary collapse
-
#default_membership ⇒ Object
Returns the user’s default active membership.
-
#expired_password? ⇒ Boolean
Checks if the user’s password has expired.
Methods inherited from ApplicationRecord
Instance Method Details
#default_membership ⇒ Object
Returns the user’s default active membership
A default membership is the first unblocked membership associated with an active organization. Returns nil if user is management or no valid membership exists.
Returns:
-
Maquina::Membership: the default membership
-
nil: if user is management or no valid membership exists
75 76 77 78 79 |
# File 'app/models/maquina/user.rb', line 75 def default_membership return nil if management? memberships.detect { |membership| membership.blocked_at.blank? && membership.organization.present? && membership.organization.active? } end |
#expired_password? ⇒ Boolean
Checks if the user’s password has expired
Returns true if password_expires_at is set and in the past, false otherwise
61 62 63 64 65 |
# File 'app/models/maquina/user.rb', line 61 def expired_password? return false if password_expires_at.blank? password_expires_at < Time.zone.now end |