Some checks failed
Build Docker Image / Explore-Gitea-Actions (push) Failing after 44s
30 lines
710 B
Go
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
|
|
}
|
|
}
|