From 062d9ac02bfdd194f8758b6d1a52a12591ad5191 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 3 Aug 2024 09:03:37 +0300 Subject: [PATCH] implement identity generation --- src/Entity/Browser/Container/Page/Auth.php | 103 ++++++++++++++++++--- 1 file changed, 89 insertions(+), 14 deletions(-) diff --git a/src/Entity/Browser/Container/Page/Auth.php b/src/Entity/Browser/Container/Page/Auth.php index 991a8d7c..bd240fd3 100644 --- a/src/Entity/Browser/Container/Page/Auth.php +++ b/src/Entity/Browser/Container/Page/Auth.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Yggverse\Yoda\Entity\Browser\Container\Page; +use \Exception; use \GtkButtonsType; use \GtkDialogFlags; use \GtkMessageDialog; @@ -13,6 +14,8 @@ use \GtkResponseType; use \Yggverse\Yoda\Entity\Browser\Container\Page; +use \Yggverse\Yoda\Model\Identity\Gemini; + class Auth { // GTK @@ -26,8 +29,12 @@ class Auth public const DIALOG_FORMAT_SECONDARY_TEXT = 'Select identity'; public const DIALOG_MESSAGE_FORMAT = 'Authorization'; public const DIALOG_CONTENT_OPTION_LABEL_CREATE = 'Create new for this resource'; + public const DIALOG_CONTENT_OPTION_LABEL_RECORD = '#%d (no name)'; public const DIALOG_CONTENT_OPTION_MARGIN = 8; - public const DIALOG_CONTENT_SPACING = 8; + public const DIALOG_CONTENT_SPACING = 1; + + // Extras + private array $_options = []; public function __construct( Page $page, @@ -62,19 +69,91 @@ class Auth $this::DIALOG_CONTENT_SPACING ); - $content->add( - $this->_option( - _($this::DIALOG_CONTENT_OPTION_LABEL_CREATE) - ) + // Init new certificate option + $this->_options[0] = $this->_option( + _($this::DIALOG_CONTENT_OPTION_LABEL_CREATE) ); + $this->_options[0]->join_group( + $this->_options[0] + ); + + // Search database for auth records + foreach ($this->page->container->browser->database->auth->find() as $auth) + { + // Get related identity records + if ($identity = $this->page->container->browser->database->identity->get($auth->identity)) + { + $this->_options[$identity->id] = $this->_option( + $identity->name ? $identity->name : sprintf( + _($this::DIALOG_CONTENT_OPTION_LABEL_RECORD), + $identity->id + ) + ); + + $this->_options[$identity->id]->join_group( + $this->_options[0] + ); + } + } + + // Build options list + foreach ($this->_options as $option) + { + $content->add( + $option + ); + } + // Render $this->gtk->show_all(); - // Listen for chose + // Listen for user chose if (GtkResponseType::OK == $this->gtk->run()) { - // @TODO + // Get active option + foreach ($this->_options as $id => $option) + { + // Auth + if ($id) + { + // @TODO + } + + // Generate new identity + else + { + // Detect driver + switch (true) + { + case mb_strtolower( + parse_url( + $this->page->navbar->request->getValue(), + PHP_URL_SCHEME + ) + ) == 'gemini': + + // Init identity + $identity = new Gemini; + + // Init auth record + $this->page->container->browser->database->auth->add( + $this->page->container->browser->database->identity->add( + $identity->crt(), + $identity->key() + ), + $this->page->navbar->request->getValue() + ); + + break; + + default: + + throw new Exception; + } + } + } + $this->gtk->destroy(); return true; @@ -91,12 +170,10 @@ class Auth int $margin = self::DIALOG_CONTENT_OPTION_MARGIN ): GtkRadioButton { - $option = GtkRadioButton::new_with_label( - $label - ); + $option = new GtkRadioButton; - $option->set_margin_start( - $margin + $option->set_label( + $label ); $option->set_margin_start( @@ -111,8 +188,6 @@ class Auth $margin ); - // @TODO connect signals? - return $option; } } \ No newline at end of file