chore(auth): add service structs and test error handling
Some checks failed
Build Docker Image / Explore-Gitea-Actions (push) Failing after 44s

This commit is contained in:
2024-09-25 21:31:57 +02:00
parent e53a0e5cf7
commit cbaee07890
2 changed files with 84 additions and 52 deletions

29
db/auth.go Normal file
View File

@@ -0,0 +1,29 @@
package db
import (
"database/sql"
"errors"
"strings"
"github.com/google/uuid"
)
type AuthDb interface {
InsertUser(userIs uuid.UUID, email string, password string) error
}
type AuthDbSqlite struct {
db *sql.DB
}
func (a *AuthDbSqlite) InsertUser(userId uuid.UUID, email string, passwordHash []byte, salt []byte) error {
_, err := a.db.Exec("INSERT INTO user (user_uuid, email, email_verified, is_admin, password, salt, created_at) VALUES (?, ?, FALSE, FALSE, ?, ?, datetime())", userId, email, passwordHash, salt)
if err != nil {
if strings.Contains(err.Error(), "email") {
return errors.New("Bad Request")
}
utils.LogError("Could not insert user", err)
return ErrInternalServer
}
}