Migrate GORM to generics API, simplify user-domain relationship, refactor models

This commit is contained in:
Christoph Haas 2026-03-28 17:21:00 +01:00
parent 19ce2224b8
commit 560b40503a
9 changed files with 192 additions and 117 deletions

View file

@ -176,7 +176,7 @@ func isLockedOut(ip, identifier string, database *db.DB) bool {
}
database.Model(&db.ImcLoginAttempt{}).
Where("email = ? AND attempted_at > ? AND successful = false", identifier, cutoff).
Where("username = ? AND attempted_at > ? AND successful = false", identifier, cutoff).
Count(&count)
return count >= MaxLoginAttempts
@ -184,7 +184,7 @@ func isLockedOut(ip, identifier string, database *db.DB) bool {
func recordFailedAttempt(identifier, ip string, database *db.DB) {
database.Create(&db.ImcLoginAttempt{
Email: identifier,
Username: identifier,
IPAddress: ip,
Successful: false,
})
@ -192,7 +192,7 @@ func recordFailedAttempt(identifier, ip string, database *db.DB) {
func clearFailedAttempts(identifier, ip string, database *db.DB) {
database.Model(&db.ImcLoginAttempt{}).
Where("email = ? OR ip_address = ?", identifier, ip).
Where("username = ? OR ip_address = ?", identifier, ip).
Update("successful", true)
}

View file

@ -22,13 +22,6 @@ type CreateDomainRequest struct {
Name string `json:"name" binding:"required"`
}
type DomainPermissions struct {
DomainID uint `json:"domainId"`
DomainName string `json:"domainName"`
UserID uint `json:"userId"`
CanManage bool `json:"canManage"`
}
func (h *DomainHandler) List(c *gin.Context) {
authCtx := GetAuthContext(c)
if authCtx == nil {
@ -188,6 +181,13 @@ func (h *DomainHandler) Delete(c *gin.Context) {
NoContent(c)
}
type DomainPermissions struct {
DomainID uint `json:"domainId"`
DomainName string `json:"domainName"`
UserID uint `json:"userId"`
CanManage bool `json:"canManage"`
}
func (h *DomainHandler) GetPermissions(c *gin.Context) {
authCtx := GetAuthContext(c)
if authCtx == nil {

View file

@ -270,22 +270,6 @@ func (h *UserHandler) Delete(c *gin.Context) {
NoContent(c)
}
func (h *UserHandler) ListAll(c *gin.Context) {
authCtx := GetAuthContext(c)
if authCtx == nil || !authCtx.IsAdmin() {
Error(c, http.StatusForbidden, "admin access required")
return
}
users, err := h.db.GetAllMailUsers()
if err != nil {
Error(c, http.StatusInternalServerError, "database error")
return
}
Success(c, users)
}
var emailLocalPartRegex = regexp.MustCompile("^[a-zA-Z0-9!#$%&'*+\\-=?^_~-]+$")
func validateEmailLocalPart(email string) error {