Add comprehensive debug logging for password flow and org creation diagnostics
This commit is contained in:
@@ -97,8 +97,10 @@ class OrganizationBloc extends Bloc<OrganizationEvent, OrganizationState> {
|
||||
CreateOrganization event,
|
||||
Emitter<OrganizationState> emit,
|
||||
) async {
|
||||
print('[DEBUG-ORG-CREATION] CreateOrganization event received with name: "${event.name}"');
|
||||
final name = event.name.trim();
|
||||
if (name.isEmpty) {
|
||||
print('[DEBUG-ORG-CREATION] Name is empty after trim');
|
||||
// Try to preserve current state if possible
|
||||
if (state is OrganizationLoaded) {
|
||||
emit(
|
||||
@@ -144,8 +146,10 @@ class OrganizationBloc extends Bloc<OrganizationEvent, OrganizationState> {
|
||||
),
|
||||
);
|
||||
|
||||
print('[DEBUG-ORG-CREATION] About to call orgApi.createOrganization with name: "$name"');
|
||||
try {
|
||||
final newOrg = await orgApi.createOrganization(name);
|
||||
print('[DEBUG-ORG-CREATION] API returned successfully: ${newOrg.id} - ${newOrg.name}');
|
||||
final updatedOrgs = [...existingOrgs, newOrg];
|
||||
emit(OrganizationLoaded(organizations: updatedOrgs, selectedOrg: newOrg));
|
||||
// Reset blocs and load permissions for new org
|
||||
@@ -154,6 +158,7 @@ class OrganizationBloc extends Bloc<OrganizationEvent, OrganizationState> {
|
||||
uploadBloc.add(ResetUploads());
|
||||
permissionBloc.add(LoadPermissions(newOrg.id));
|
||||
} catch (e) {
|
||||
print('[DEBUG-ORG-CREATION] Error caught: $e');
|
||||
emit(
|
||||
OrganizationLoaded(
|
||||
organizations: existingOrgs,
|
||||
|
||||
@@ -72,10 +72,13 @@ class ApiClient {
|
||||
dynamic data,
|
||||
required T Function(dynamic data) fromJson,
|
||||
}) async {
|
||||
print('[DEBUG-API-CLIENT] POST request starting - path: $path, data: $data');
|
||||
try {
|
||||
final response = await _dio.post(path, data: data);
|
||||
print('[DEBUG-API-CLIENT] POST response received - status: ${response.statusCode}, data: ${response.data}');
|
||||
return fromJson(response.data);
|
||||
} on DioException catch (e) {
|
||||
print('[DEBUG-API-CLIENT] POST request failed - type: ${e.type}, message: ${e.message}, status: ${e.response?.statusCode}');
|
||||
throw _handleError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import '../blocs/organization/organization_state.dart';
|
||||
import 'api_client.dart';
|
||||
import 'dart:developer' as developer;
|
||||
|
||||
class OrgApi {
|
||||
final ApiClient _apiClient;
|
||||
@@ -14,10 +15,20 @@ class OrgApi {
|
||||
}
|
||||
|
||||
Future<Organization> createOrganization(String name) async {
|
||||
return await _apiClient.post(
|
||||
print('[DEBUG-ORG-CREATION] OrgApi.createOrganization called with name: "$name"');
|
||||
developer.log('POST /orgs with payload: {"name": "$name"}', name: 'OrgApi');
|
||||
|
||||
try {
|
||||
final result = await _apiClient.post(
|
||||
'/orgs',
|
||||
data: {'name': name},
|
||||
fromJson: (data) => Organization.fromJson(data),
|
||||
);
|
||||
print('[DEBUG-ORG-CREATION] OrgApi.createOrganization returned: ${result.id}');
|
||||
return result;
|
||||
} catch (e) {
|
||||
print('[DEBUG-ORG-CREATION] OrgApi.createOrganization error: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,12 +53,16 @@ func getUserWebDAVClient(ctx context.Context, db *database.DB, userID uuid.UUID,
|
||||
return nil, fmt.Errorf("failed to generate password: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("[DEBUG-PASSWORD-FLOW] Generated password for user %s: %s\n", ncUsername, ncPassword)
|
||||
|
||||
// Create Nextcloud user account
|
||||
err = storage.CreateNextcloudUser(nextcloudBaseURL, adminUser, adminPass, ncUsername, ncPassword)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create Nextcloud user: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("[DEBUG-PASSWORD-FLOW] About to store in DB - username: %s, password: %s\n", ncUsername, ncPassword)
|
||||
|
||||
// Update database with Nextcloud credentials
|
||||
_, err = db.ExecContext(ctx,
|
||||
"UPDATE users SET nextcloud_username = $1, nextcloud_password = $2 WHERE id = $3",
|
||||
@@ -67,11 +71,16 @@ func getUserWebDAVClient(ctx context.Context, db *database.DB, userID uuid.UUID,
|
||||
return nil, fmt.Errorf("failed to update user credentials: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("[DEBUG-PASSWORD-FLOW] Stored in DB successfully\n")
|
||||
|
||||
user.NextcloudUsername = ncUsername
|
||||
user.NextcloudPassword = ncPassword
|
||||
fmt.Printf("[AUTO-PROVISION] Created Nextcloud account for user %s: %s\n", userID, ncUsername)
|
||||
}
|
||||
|
||||
fmt.Printf("[DEBUG-PASSWORD-FLOW] Retrieved from DB - username: %s, password: %s\n", user.NextcloudUsername, user.NextcloudPassword)
|
||||
fmt.Printf("[DEBUG-PASSWORD-FLOW] Creating WebDAV client with URL: %s, user: %s, pass: %s\n", nextcloudBaseURL, user.NextcloudUsername, user.NextcloudPassword)
|
||||
|
||||
// Create user-specific WebDAV client
|
||||
return storage.NewUserWebDAVClient(nextcloudBaseURL, user.NextcloudUsername, user.NextcloudPassword), nil
|
||||
}
|
||||
|
||||
@@ -17,12 +17,16 @@ func CreateNextcloudUser(nextcloudBaseURL, adminUser, adminPass, username, passw
|
||||
baseURL := strings.Split(nextcloudBaseURL, "/remote.php")[0]
|
||||
urlStr := fmt.Sprintf("%s/ocs/v1.php/cloud/users", baseURL)
|
||||
|
||||
fmt.Printf("[DEBUG-PASSWORD-FLOW] CreateNextcloudUser called with password: %s\n", password)
|
||||
|
||||
// OCS API expects form-encoded data with proper URL encoding
|
||||
formData := url.Values{
|
||||
"userid": {username},
|
||||
"password": {password},
|
||||
}.Encode()
|
||||
|
||||
fmt.Printf("[DEBUG-PASSWORD-FLOW] Form data being sent to OCS API: %s\n", formData)
|
||||
|
||||
req, err := http.NewRequest("POST", urlStr, bytes.NewBufferString(formData))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create request: %w", err)
|
||||
@@ -67,6 +71,7 @@ func NewUserWebDAVClient(nextcloudBaseURL, username, password string) *WebDAVCli
|
||||
fullURL := fmt.Sprintf("%s/remote.php/dav/files/%s", baseURL, username)
|
||||
|
||||
fmt.Printf("[WEBDAV-USER] Input URL: %s, Base: %s, Full: %s, User: %s\n", nextcloudBaseURL, baseURL, fullURL, username)
|
||||
fmt.Printf("[DEBUG-PASSWORD-FLOW] NewUserWebDAVClient called with password: %s\n", password)
|
||||
|
||||
return &WebDAVClient{
|
||||
baseURL: fullURL,
|
||||
|
||||
Reference in New Issue
Block a user