refactored

This commit is contained in:
2025-03-18 23:27:27 +02:00
parent 64f59ea232
commit 6c1f34c682
45 changed files with 398 additions and 413 deletions

View File

@@ -0,0 +1,42 @@
package dbhandler
import (
"context"
"git.acooldomain.co/server-manager/backend/models"
"golang.org/x/crypto/bcrypt"
)
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(bytes), err
}
type InviteToken struct {
Email string
Permissions models.Permission
Token string
}
type UserSignupRequest struct {
Token InviteToken
Username string
Password string
}
type UserPassAuthanticationDbHandler interface {
// Read Only
AuthenticateUser(ctx context.Context, username string, password string) (*models.User, error)
ListUsers(ctx context.Context) ([]models.User, error)
// Write
CreateUser(ctx context.Context, username string, password string, permissions models.Permission, email string, maxOwnedServers uint) error
RemoveUser(ctx context.Context, username string) error
SetPermissions(ctx context.Context, username string, permissions models.Permission) error
SetPassword(ctx context.Context, username string, password string) error
}
type InviteTokenDbHandler interface {
SaveInviteToken(ctx context.Context, email string, permissions models.Permission) (string, error)
GetInviteToken(ctx context.Context, token string) (*InviteToken, error)
}