first commit

This commit is contained in:
Adrian Zürcher
2025-10-12 14:56:18 +02:00
parent a9f2e11fe6
commit a908db4f38
92 changed files with 13273 additions and 0 deletions

49
backend/user/manager.go Normal file
View File

@@ -0,0 +1,49 @@
package user
import (
"backend/dbRequest"
"backend/utils"
"database/sql"
"fmt"
"os"
)
type UserManager struct {
dbType string
dbFile string
}
func NewUserManager(dir string) (*UserManager, error) {
if dir == "" {
dir = "."
}
var typ string = "sqlite"
var file string = fmt.Sprintf("%s/user.db", dir)
if _, err := os.Stat(file); err != nil {
db, err := sql.Open(typ, file)
if err != nil {
return nil, err
}
defer db.Close()
_, err = db.Exec(dbRequest.DBCreate)
if err != nil {
return nil, err
}
hash, err := utils.HashPassword("tecamino@2025")
if err != nil {
return nil, err
}
_, err = db.Exec(dbRequest.DBNewUser, "admin", "admin", hash, "{}")
if err != nil {
return nil, err
}
}
return &UserManager{
dbType: typ,
dbFile: file,
}, nil
}