mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement identity generation
This commit is contained in:
parent
5e0ef1616e
commit
062d9ac02b
1 changed files with 89 additions and 14 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue