Fix getUserWebDAVClient to use actual username and COALESCE for NULL handling
This commit is contained in:
BIN
go_cloud/api
BIN
go_cloud/api
Binary file not shown.
@@ -32,22 +32,22 @@ import (
|
||||
// getUserWebDAVClient gets or creates a user's Nextcloud account and returns a WebDAV client for them
|
||||
func getUserWebDAVClient(ctx context.Context, db *database.DB, userID uuid.UUID, nextcloudBaseURL, adminUser, adminPass string) (*storage.WebDAVClient, error) {
|
||||
var user struct {
|
||||
Username string
|
||||
NextcloudUsername string
|
||||
NextcloudPassword string
|
||||
Email string
|
||||
}
|
||||
|
||||
err := db.QueryRowContext(ctx,
|
||||
"SELECT nextcloud_username, nextcloud_password, email FROM users WHERE id = $1",
|
||||
userID).Scan(&user.NextcloudUsername, &user.NextcloudPassword, &user.Email)
|
||||
"SELECT username, COALESCE(nextcloud_username, ''), COALESCE(nextcloud_password, '') FROM users WHERE id = $1",
|
||||
userID).Scan(&user.Username, &user.NextcloudUsername, &user.NextcloudPassword)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get user: %w", err)
|
||||
}
|
||||
|
||||
// If user doesn't have Nextcloud credentials, create them
|
||||
if user.NextcloudUsername == "" || user.NextcloudPassword == "" {
|
||||
// Use email prefix as username
|
||||
ncUsername := strings.Split(user.Email, "@")[0]
|
||||
// Use the actual username from the users table
|
||||
ncUsername := user.Username
|
||||
ncPassword, err := storage.GenerateSecurePassword(32)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to generate password: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user