Overview
Health Manager provides a comprehensive user management system that allows administrators to create, manage, and delete user accounts. The system supports email-based user creation and invitation links for secure onboarding.Admin Role Assignment
The first user registered in the system is automatically assigned the admin role. This ensures that there is always at least one administrator who can manage other users.
app/Models/User.php:60-64
User Roles
Health Manager supports two user roles:- admin: Full access to all features, including user management and system configuration
- user: Standard access to personal health data and features
users table and can be checked using the isAdmin() method:
Source: app/Models/User.php:51-54
Creating Users
Administrators can create new user accounts through the admin panel. The user creation process:- Collects user information: Name and email address
- Generates credentials: Automatically creates a secure password and username
- Sends email notification: Credentials are emailed to the new user
app/Livewire/Admin/UserManagement.php:22-55
Username Generation Logic
Username Generation Logic
Usernames are automatically generated from the email address:
- Extract the local part before the
@symbol - Check if the username already exists
- If it exists, append a counter (e.g.,
john1,john2) - Continue incrementing until a unique username is found
Email Notifications
When a user is created, the system attempts to send an email with their credentials:Invitation Links
Administrators can generate invitation links that allow users to self-register: Source:app/Livewire/Admin/UserManagement.php:71-85
How Invitation Links Work
- Admin generates an invite link from the user management panel
- System creates a unique token and stores it in the
invitationstable - Link expires after 24 hours
- Users can register using the link before expiration
Invitation tokens are 40-character random strings, providing high security against guessing attacks.
Invitation Link Structure
- Token length: 40 characters (random alphanumeric)
- Default role: “user”
- Expiration: 24 hours from creation
- Single use: Token is marked as used after registration
Deleting Users
Administrators can delete user accounts with the following restrictions: Source:app/Livewire/Admin/UserManagement.php:57-62
- All associated health data is removed (cascade delete)
- All permission relationships are removed
- The user’s authentication sessions are invalidated
Access Control
Only users with the admin role can access user management features. This is enforced through theEnsureUserIsAdmin middleware:
Source: app/Http/Middleware/EnsureUserIsAdmin.php:16-22
Best Practices
- Regular audits: Periodically review user accounts and remove inactive users
- Secure communication: If email delivery fails, use secure channels to share credentials
- Monitor invitations: Check for expired invitation links and remove them
- Role assignment: Only grant admin privileges to trusted users
- Account cleanup: Remove test accounts and temporary users promptly
