diff --git a/analyticshub/appinfo/routes.php b/analyticshub/appinfo/routes.php index 95c931c..1ed7528 100644 --- a/analyticshub/appinfo/routes.php +++ b/analyticshub/appinfo/routes.php @@ -12,10 +12,16 @@ return [ 'routes' => [ // Admin routes [ - 'name' => 'page#index', + 'name' => 'admin#index', 'url' => '/', 'verb' => 'GET', 'requirements' => [], ], + [ + 'name' => 'admin#load', + 'url' => '/load', + 'verb' => 'GET', + 'requirements' => [], + ], ], ]; diff --git a/analyticshub/lib/Controller/Admin/PageController.php b/analyticshub/lib/Controller/Admin/PageController.php new file mode 100644 index 0000000..2f1f087 --- /dev/null +++ b/analyticshub/lib/Controller/Admin/PageController.php @@ -0,0 +1,144 @@ +appName = $appName; + $this->request = $request; + $this->config = $config; + } + + /** + * Index page - render admin UI + * + * @NoAdminRequired + * @NoCSRFRequired + */ + public function index(): TemplateResponse { + // Load saved configuration + $googleClientId = $this->config->getAppValue(Application::APP_NAME, 'google_client_id', ''); + $googleClientSecret = '•••'; // Masked for display + $anthropicApiKey = '••••••••'; // Masked for display + $isConfigured = !empty($googleClientId) && !empty($this->config->getAppValue(Application::APP_NAME, 'anthropic_api_key', '')); + + return new TemplateResponse($this->appName, 'admin', [ + 'app_name' => $this->appName, + 'version' => Application::APP_VERSION, + 'is_configured' => $isConfigured, + 'google_client_id' => $googleClientId, + 'google_client_secret_masked' => $googleClientSecret, + 'anthropic_api_key_masked' => $anthropicApiKey, + ]); + } + + /** + * Save configuration + * + * @NoAdminRequired + * @NoCSRFRequired + */ + public function save(): JSONResponse { + $params = $this->request->getParams(); + + // Validate required fields + if (!isset($params['google_client_id']) || empty($params['google_client_id'])) { + return new JSONResponse([ + 'success' => false, + 'error' => 'Google Client ID is required' + ]); + } + + if (!isset($params['google_client_secret']) || empty($params['google_client_secret'])) { + return new JSONResponse([ + 'success' => false, + 'error' => 'Google Client Secret is required' + ]); + } + + if (!isset($params['anthropic_api_key']) || empty($params['anthropic_api_key'])) { + return new JSONResponse([ + 'success' => false, + 'error' => 'Anthropic API Key is required' + ]); + } + + try { + // Save configuration + $this->config->setAppValue(Application::APP_NAME, 'google_client_id', $params['google_client_id']); + $this->config->setAppValue(Application::APP_NAME, 'google_client_secret', $params['google_client_secret']); + $this->config->setAppValue(Application::APP_NAME, 'anthropic_api_key', $params['anthropic_api_key']); + + // Check if now configured + $isConfigured = !empty($params['google_client_id']) && !empty($params['anthropic_api_key']); + + return new JSONResponse([ + 'success' => true, + 'data' => [ + 'is_configured' => $isConfigured, + 'message' => 'Configuration saved successfully' + ] + ]); + + } catch (\Exception $e) { + return new JSONResponse([ + 'success' => false, + 'error' => $e->getMessage() + ]); + } + } + + /** + * Load configuration + * + * @NoAdminRequired + * @NoCSRFRequired + */ + public function load(): JSONResponse { + try { + // Load configuration + $googleClientId = $this->config->getAppValue(Application::APP_NAME, 'google_client_id', ''); + $googleClientSecret = ''; // Don't expose secret + $anthropicApiKey = ''; // Don't expose secret + + $isConfigured = !empty($googleClientId) && !empty($this->config->getAppValue(Application::APP_NAME, 'anthropic_api_key', '')); + + return new JSONResponse([ + 'success' => true, + 'data' => [ + 'google_client_id' => $googleClientId, + 'google_client_secret_masked' => '•••', // Masked + 'anthropic_api_key_masked' => '••••••••', // Masked + 'is_configured' => $isConfigured, + ] + ]); + + } catch (\Exception $e) { + return new JSONResponse([ + 'success' => false, + 'error' => $e->getMessage() + ]); + } + } +} diff --git a/analyticshub/lib/Controller/AdminController.php b/analyticshub/lib/Controller/AdminController.php new file mode 100644 index 0000000..bbc20c3 --- /dev/null +++ b/analyticshub/lib/Controller/AdminController.php @@ -0,0 +1,38 @@ +appName = $appName; + $this->request = $request; + } + + /** + * Load configuration + */ + public function load(): JSONResponse { + return new JSONResponse([ + 'success' => true, + 'data' => [ + 'message' => 'Use PageController instead of AdminController', + ], + ]); + } +} diff --git a/analyticshub/lib/Controller/PageController.php b/analyticshub/lib/Controller/PageController.php index 3b74a04..26ad327 100644 --- a/analyticshub/lib/Controller/PageController.php +++ b/analyticshub/lib/Controller/PageController.php @@ -2,9 +2,11 @@ declare(strict_types=1); -namespace OCA\AnalyticsHub\Controller; +namespace OCA\AnalyticsHub\Controller\Admin; use OCP\IRequest; +use OCP\AppFramework\Http\TemplateResponse; +use OCA\AnalyticsHub\AppInfo\Application; /** * Admin Settings Controller @@ -12,11 +14,13 @@ use OCP\IRequest; * @NoAdminRequired * @NoCSRFRequired */ -class PageController { +class PageController extends Controller { + + private $appName; public function __construct(string $appName, IRequest $request) { + parent::__construct($appName, $request); $this->appName = $appName; - $this->request = $request; } /** @@ -25,43 +29,11 @@ class PageController { * @NoAdminRequired * @NoCSRFRequired */ - public function index(): void { - echo ''; - echo ''; - echo '
'; - echo ''; - echo 'App Name: ' . htmlspecialchars($this->appName) . '
'; - echo 'Request: ' . htmlspecialchars(print_r($this->request, true)) . '
'; - echo 'Class: OCA\AnalyticsHub\Controller\PageController
'; - echo 'Method: index() invoked
'; - echo 'Namespace: OCA\AnalyticsHub\Controller
'; - echo '✅ Controller successfully loaded
'; - echo '✅ index() method executed
'; - echo '