mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement logout feature
This commit is contained in:
parent
6b91591aa5
commit
f6812c9dc2
2 changed files with 122 additions and 67 deletions
|
|
@ -30,7 +30,7 @@ class Auth
|
|||
// Defaults
|
||||
public const DEFAULT_RESPONSE = GtkResponseType::CANCEL;
|
||||
public const FORMAT_SECONDARY_TEXT = 'Select identity';
|
||||
public const MESSAGE_FORMAT = 'Authorization';
|
||||
public const MESSAGE_FORMAT = 'Auth';
|
||||
|
||||
public const MARGIN = 8;
|
||||
public const SPACING = 1;
|
||||
|
|
@ -71,6 +71,13 @@ class Auth
|
|||
$this::SPACING
|
||||
);
|
||||
|
||||
// Add separator
|
||||
$content->add(
|
||||
new GtkSeparator(
|
||||
GtkOrientation::VERTICAL
|
||||
)
|
||||
);
|
||||
|
||||
// Init new certificate option
|
||||
$this->_options[
|
||||
Auth\Option\Identity::ID_CRT_NEW
|
||||
|
|
@ -96,7 +103,7 @@ class Auth
|
|||
Auth\Option\Identity::ID_CRT_NEW
|
||||
]->useName();
|
||||
|
||||
// Search database for auth records
|
||||
// Build records from database
|
||||
foreach ($this->page->container->browser->database->auth->like(
|
||||
sprintf(
|
||||
'%s%%',
|
||||
|
|
@ -107,28 +114,48 @@ class Auth
|
|||
// Get related identity records
|
||||
if ($identity = $this->page->container->browser->database->identity->get($auth->identity))
|
||||
{
|
||||
$this->_options[$identity->id] = new Auth\Option\Identity(
|
||||
$this->_options[
|
||||
$identity->id
|
||||
] = new Auth\Option\Identity(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->_options[$identity->id]->setGroup(
|
||||
$this->_options[
|
||||
$identity->id
|
||||
]->setGroup(
|
||||
$this->_options[
|
||||
Auth\Option\Identity::ID_CRT_NEW
|
||||
]
|
||||
);
|
||||
|
||||
$this->_options[$identity->id]->setLabel(
|
||||
$this->_options[
|
||||
$identity->id
|
||||
]->setLabel(
|
||||
$identity->id,
|
||||
$identity->name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Append separator
|
||||
$content->add(
|
||||
new GtkSeparator(
|
||||
GtkOrientation::VERTICAL
|
||||
)
|
||||
// Append logout option
|
||||
$this->_options[
|
||||
Auth\Option\Identity::ID_LOG_OUT
|
||||
] = new Auth\Option\Identity(
|
||||
$this
|
||||
);
|
||||
|
||||
$this->_options[
|
||||
Auth\Option\Identity::ID_LOG_OUT
|
||||
]->setGroup(
|
||||
$this->_options[
|
||||
Auth\Option\Identity::ID_CRT_NEW
|
||||
]
|
||||
);
|
||||
|
||||
$this->_options[
|
||||
Auth\Option\Identity::ID_LOG_OUT
|
||||
]->setLabel(
|
||||
Auth\Option\Identity::ID_LOG_OUT
|
||||
);
|
||||
|
||||
// Build options list
|
||||
|
|
@ -173,7 +200,7 @@ class Auth
|
|||
}
|
||||
}
|
||||
|
||||
// Append empty line separator
|
||||
// Add final separator
|
||||
$content->add(
|
||||
new GtkLabel
|
||||
);
|
||||
|
|
@ -189,32 +216,31 @@ class Auth
|
|||
{
|
||||
if ($option->gtk->get_active())
|
||||
{
|
||||
// Logout previous identities for this request
|
||||
// Route ID
|
||||
switch ($id)
|
||||
{
|
||||
case Auth\Option\Identity::ID_LOG_OUT:
|
||||
|
||||
// Logout previous session
|
||||
$this->page->container->browser->database->auth->logout(
|
||||
$this->page->navbar->request->getValue()
|
||||
);
|
||||
|
||||
// Activate existing identity
|
||||
if ($id)
|
||||
{
|
||||
// Add new auth record
|
||||
$this->page->container->browser->database->auth->add(
|
||||
$id,
|
||||
break;
|
||||
|
||||
case Auth\Option\Identity::ID_CRT_NEW:
|
||||
|
||||
// Logout previous session
|
||||
$this->page->container->browser->database->auth->logout(
|
||||
$this->page->navbar->request->getValue()
|
||||
);
|
||||
}
|
||||
|
||||
// Generate new identity
|
||||
else
|
||||
{
|
||||
// Detect driver
|
||||
// Detect identity driver
|
||||
switch (true)
|
||||
{
|
||||
case mb_strtolower(
|
||||
parse_url(
|
||||
case parse_url(
|
||||
$this->page->navbar->request->getValue(),
|
||||
PHP_URL_SCHEME
|
||||
)
|
||||
) == 'gemini':
|
||||
|
||||
// Init identity model
|
||||
|
|
@ -236,9 +262,25 @@ class Auth
|
|||
|
||||
throw new Exception;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
// Logout previous session
|
||||
$this->page->container->browser->database->auth->logout(
|
||||
$this->page->navbar->request->getValue()
|
||||
);
|
||||
|
||||
// Add new auth record
|
||||
$this->page->container->browser->database->auth->add(
|
||||
$id,
|
||||
$this->page->navbar->request->getValue()
|
||||
);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->destroy();
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ class Identity
|
|||
public const LABEL_DEFAULT = '#%d (%s)';
|
||||
public const LABEL_NO_NAME = '#%d (no name)';
|
||||
public const LABEL_CRT_NEW = 'Create new for this resource';
|
||||
public const LABEL_LOG_OUT = 'Log out..';
|
||||
|
||||
public const ID_LOG_OUT =-1;
|
||||
public const ID_CRT_NEW = 0; // free < 0 > reserved by DB
|
||||
|
||||
public function __construct(
|
||||
|
|
@ -76,8 +78,26 @@ class Identity
|
|||
?string $label = null
|
||||
): void
|
||||
{
|
||||
if ($id)
|
||||
switch ($id)
|
||||
{
|
||||
case $this::ID_LOG_OUT:
|
||||
|
||||
$this->gtk->set_label(
|
||||
$this::LABEL_LOG_OUT
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
case $this::ID_CRT_NEW:
|
||||
|
||||
$this->gtk->set_label(
|
||||
$this::LABEL_CRT_NEW
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
default: // DB
|
||||
|
||||
$this->gtk->set_label(
|
||||
$label ? sprintf(
|
||||
$this::LABEL_DEFAULT,
|
||||
|
|
@ -89,13 +109,6 @@ class Identity
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$this->gtk->set_label(
|
||||
$this::LABEL_CRT_NEW
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function useName(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue