feat: enhance user management with comprehensive schema fields and documentation

- Added complete user management fields to User model:
  * lastLoginAt for tracking user activity
  * isActive for account status management
  * emailVerified with verification token system
  * failedLoginAttempts and lockedAt for security
  * preferences, timezone, and preferredLanguage for UX
- Enhanced UserRepository with new management methods:
  * updateLastLogin() with security features
  * incrementFailedLoginAttempts() with auto-locking
  * verifyEmail() for email verification workflow
  * deactivateUser() and unlockUser() for admin management
  * updatePreferences() for user settings
  * improved findInactiveUsers() using lastLoginAt
- Updated database indexes for performance optimization
- Regenerated Prisma client with new schema
- Created comprehensive troubleshooting documentation
- Verified production build success with all enhancements
This commit is contained in:
2025-07-12 22:01:07 +02:00
parent dd145686e6
commit eee5286447
3 changed files with 379 additions and 5 deletions

View File

@ -91,11 +91,35 @@ model User {
invitedAt DateTime? @db.Timestamptz(6)
/// Email of the user who invited this user (for audit trail)
invitedBy String? @db.VarChar(255)
/// User management fields
/// When the user last logged in
lastLoginAt DateTime? @db.Timestamptz(6)
/// Whether the user account is active
isActive Boolean @default(true)
/// Whether the user's email has been verified
emailVerified Boolean @default(false)
/// Token for email verification
emailVerificationToken String? @db.VarChar(255)
/// Expiration time for email verification token
emailVerificationExpiry DateTime? @db.Timestamptz(6)
/// Number of failed login attempts
failedLoginAttempts Int @default(0)
/// When the account was locked due to failed attempts
lockedAt DateTime? @db.Timestamptz(6)
/// User preferences and settings
preferences Json? @db.Json
/// User's timezone for proper datetime display
timezone String? @db.VarChar(50)
/// User's preferred language
preferredLanguage String? @db.VarChar(10)
company Company @relation("CompanyUsers", fields: [companyId], references: [id], onDelete: Cascade)
auditLogs SecurityAuditLog[]
@@index([companyId])
@@index([email])
@@index([lastLoginAt])
@@index([isActive])
@@index([emailVerified])
}
/// *