Registration form for new users

This commit is contained in:
Simon Martens
2025-05-23 16:26:03 +02:00
parent f641a32cb5
commit c44467f229
22 changed files with 805 additions and 9 deletions

View File

@@ -0,0 +1,35 @@
package dbmodels
import (
"fmt"
"github.com/pocketbase/pocketbase/core"
)
func CreateUser(
app core.App,
email string,
password string,
name string,
role string,
) (*User, error) {
collection, err := app.FindCollectionByNameOrId(USERS_TABLE)
if err != nil {
return nil, fmt.Errorf("failed to find '%s' collection: %w", USERS_TABLE, err)
}
record := core.NewRecord(collection)
user := NewUser(record)
user.SetEmail(email)
user.SetPassword(password)
user.SetName(name)
user.SetVerified(true)
user.SetDeactivated(false)
user.SetRole(role)
if err := app.Save(record); err != nil {
return nil, fmt.Errorf("failed to save user record: %w", err)
}
return user, nil
}