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