chore(auth): add service structs and test error handling
Some checks failed
Build Docker Image / Explore-Gitea-Actions (push) Failing after 44s
Some checks failed
Build Docker Image / Explore-Gitea-Actions (push) Failing after 44s
This commit is contained in:
29
db/auth.go
Normal file
29
db/auth.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user