Class: Securial::User

Inherits:
ApplicationRecord show all
Includes:
PasswordResettable
Defined in:
app/models/securial/user.rb

Overview

User

This class represents a user in the Securial authentication and authorization system.

Users can have multiple roles assigned to them, which define their permissions and access levels within the application.

The User model includes functionality for password reset, email normalization, and various validations to ensure data integrity.

## Attributes

  • ‘email_address`: The user’s email address, which is normalized

  • ‘username`: A unique username for the user, with specific format requirements

  • ‘first_name`: The user’s first name, required and limited in length

  • ‘last_name`: The user’s last name, required and limited in length

  • ‘phone`: An optional phone number, limited in length

  • ‘bio`: An optional biography, limited in length

## Validations

  • Email address must be present, unique, and formatted correctly

  • Username must be present, unique (case insensitive), and formatted correctly

  • First and last names must be present and limited in length

  • Phone and bio fields are optional but have length restrictions

## Associations

  • Has many role assignments, allowing users to have multiple roles

  • Has many roles through role assignments, enabling flexible permission management

  • Has many sessions, allowing for session management and tracking

Instance Method Summary collapse

Methods included from PasswordResettable

#clear_reset_password_token!, #generate_reset_password_token!, #password_expired?, #reset_password_token_valid?, #update_password_changed_at

Methods inherited from ApplicationRecord

#generate_uuid_v7

Instance Method Details

#is_admin?Boolean

Checks if the user has the specified role.

Parameters:

  • role_name (String)

    The name of the role to check

Returns:

  • (Boolean)

    Returns true if the user has the specified role, false otherwise.



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

def is_admin?
  roles.exists?(role_name: Securial.titleized_admin_role)
end