This repository has been archived on 2025-08-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
web-app-template/db/auth.go
Tim Wundenberg cbaee07890
Some checks failed
Build Docker Image / Explore-Gitea-Actions (push) Failing after 44s
chore(auth): add service structs and test error handling
2024-09-25 21:31:57 +02:00

30 lines
710 B
Go

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
}
}