Remove password reset functionality

Backend:
- Remove ForgotPassword API handler
- Remove password reset token model and database table
- Remove email service for sending reset emails
- Remove SMTP configuration

Frontend:
- Remove /auth/forgot page
- Remove forgot password link from login page
- Remove forgot route from auth-only routes check
This commit is contained in:
Christoph Haas 2026-03-23 22:35:30 +01:00
parent c459cc1efb
commit abd7e3a97f
9 changed files with 5 additions and 425 deletions

View file

@ -113,19 +113,6 @@ type ImcLoginAttempt struct {
// TableName specifies the database table name for ImcLoginAttempt.
func (ImcLoginAttempt) TableName() string { return "imc_login_attempts" }
// PasswordResetToken stores one-time tokens for password reset functionality.
type PasswordResetToken struct {
ID uint `gorm:"primaryKey" json:"id"` // Primary key
UserID uint `gorm:"not null" json:"userId"` // Foreign key to ImcUser
Token string `gorm:"size:64;not null;uniqueIndex" json:"token"` // The reset token (unique index for fast lookup)
ExpiresAt time.Time `gorm:"not null" json:"expiresAt"` // When this token expires
Used bool `gorm:"default:false" json:"used"` // Whether this token has been used
CreatedAt time.Time `json:"createdAt"` // When the token was created
}
// TableName specifies the database table name for PasswordResetToken.
func (PasswordResetToken) TableName() string { return "imc_password_reset_tokens" }
// =============================================================================
// Helper/View Models (not stored in database)
// =============================================================================
@ -258,19 +245,5 @@ func (d *DB) InitSchema() error {
return err
}
// Create imc_password_reset_tokens table for password reset functionality.
// Stores temporary tokens for resetting forgotten passwords.
resetTokensSQL := `
CREATE TABLE IF NOT EXISTS imc_password_reset_tokens (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id INT UNSIGNED NOT NULL,
token VARCHAR(64) NOT NULL UNIQUE,
expires_at DATETIME NOT NULL,
used BOOLEAN DEFAULT FALSE,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
INDEX idx_token (token),
INDEX idx_user_id (user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
`
return d.Exec(resetTokensSQL).Error
return nil
}

View file

@ -1,7 +1,5 @@
package db
import "time"
// =============================================================================
// Admin User (ImcUser) Operations
// These functions manage admin users who can log into the web interface.
@ -189,40 +187,3 @@ func (d *DB) IsUserInDomain(userID, domainID uint) (bool, error) {
err := d.Model(&ImcUserDomain{}).Where("user_id = ? AND domain_id = ?", userID, domainID).Count(&count).Error
return count > 0, err
}
// =============================================================================
// Password Reset Tokens
// These functions manage one-time tokens for password reset.
// =============================================================================
// CreatePasswordResetToken creates a new password reset token.
// userID: the ID of the user requesting password reset.
// token: the random token string.
// expiresAt: when this token becomes invalid.
func (d *DB) CreatePasswordResetToken(userID uint, token string, expiresAt time.Time) error {
resetToken := PasswordResetToken{
UserID: userID,
Token: token,
ExpiresAt: expiresAt,
}
return d.Create(&resetToken).Error
}
// GetValidPasswordResetToken looks up a valid (unused, not expired) reset token.
// token: the token string to look up.
// Returns: the token if valid, or an error if not found/expired/used.
func (d *DB) GetValidPasswordResetToken(token string) (*PasswordResetToken, error) {
var resetToken PasswordResetToken
// Check token exists, hasn't been used, and hasn't expired.
err := d.Where("token = ? AND used = false AND expires_at > ?", token, time.Now()).First(&resetToken).Error
if err != nil {
return nil, err
}
return &resetToken, nil
}
// MarkResetTokenUsed marks a token as used (prevents reuse).
// token: the token string to mark as used.
func (d *DB) MarkResetTokenUsed(token string) error {
return d.Model(&PasswordResetToken{}).Where("token = ?", token).Update("used", true).Error
}