mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 17:59:28 +08:00
generate first user username from email
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"beszel/migrations"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/pocketbase/pocketbase"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
@@ -97,6 +98,9 @@ func (um *UserManager) CreateFirstUser(e *core.RequestEvent) error {
|
||||
user.SetPassword(data.Password)
|
||||
user.Set("role", "admin")
|
||||
user.Set("verified", true)
|
||||
if username := strings.Split(data.Email, "@")[0]; len(username) > 2 {
|
||||
user.Set("username", username)
|
||||
}
|
||||
if err := um.app.Save(user); err != nil {
|
||||
return e.JSON(http.StatusInternalServerError, map[string]string{"err": err.Error()})
|
||||
}
|
||||
|
Reference in New Issue
Block a user