mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 01:05:32 +00:00
Registration form for new users
This commit is contained in:
35
dbmodels/user_functions.go
Normal file
35
dbmodels/user_functions.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user