mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
use uri for request
This commit is contained in:
parent
24adba9065
commit
9a7984f345
6 changed files with 37 additions and 49 deletions
|
|
@ -12,9 +12,9 @@ use std::rc::Rc;
|
|||
pub fn default(
|
||||
action: (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||
profile: &Rc<Profile>,
|
||||
auth_uri: &Uri,
|
||||
request: &Uri,
|
||||
) -> Default {
|
||||
Default::build(action, profile, auth_uri)
|
||||
Default::build(action, profile, request)
|
||||
}
|
||||
|
||||
/// Create new identity widget for unknown request
|
||||
|
|
|
|||
|
|
@ -2,10 +2,7 @@ mod widget;
|
|||
use widget::{form::list::item::value::Value, Widget};
|
||||
|
||||
use super::{BrowserAction, Profile, WindowAction};
|
||||
use gtk::{
|
||||
glib::{Regex, RegexCompileFlags, RegexMatchFlags, Uri},
|
||||
prelude::IsA,
|
||||
};
|
||||
use gtk::{glib::Uri, prelude::IsA};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Default {
|
||||
|
|
@ -20,31 +17,13 @@ impl Default {
|
|||
pub fn build(
|
||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||
profile: &Rc<Profile>,
|
||||
auth_uri: &Uri,
|
||||
request: &Uri,
|
||||
) -> Self {
|
||||
// Init scope
|
||||
let auth_url = auth_uri.to_string();
|
||||
|
||||
let scope = match Regex::split_simple(
|
||||
r"^\w+://(.*)",
|
||||
&auth_url,
|
||||
RegexCompileFlags::DEFAULT,
|
||||
RegexMatchFlags::DEFAULT,
|
||||
)
|
||||
.get(1)
|
||||
{
|
||||
Some(postfix) => postfix.to_string(),
|
||||
None => auth_url, // @TODO warn?
|
||||
}
|
||||
.trim()
|
||||
.trim_end_matches("/")
|
||||
.to_lowercase();
|
||||
|
||||
// Init widget
|
||||
let widget = Rc::new(Widget::build(
|
||||
(browser_action, window_action),
|
||||
profile,
|
||||
&scope,
|
||||
request,
|
||||
));
|
||||
|
||||
// Init events
|
||||
|
|
@ -55,6 +34,7 @@ impl Default {
|
|||
|
||||
widget.on_apply({
|
||||
let profile = profile.clone();
|
||||
let request = request.clone();
|
||||
let widget = widget.clone();
|
||||
let window_action = window_action.clone();
|
||||
move |response| {
|
||||
|
|
@ -68,13 +48,13 @@ impl Default {
|
|||
.make(None, &widget.form.name.value().unwrap())
|
||||
{
|
||||
Ok(profile_identity_id) => profile_identity_id,
|
||||
Err(e) => todo!("{}", e.to_string()),
|
||||
Err(e) => todo!("{e}"),
|
||||
},
|
||||
),
|
||||
Value::ImportPem => Some(
|
||||
match profile.identity.add(&widget.form.file.pem.take().unwrap()) {
|
||||
Ok(profile_identity_id) => profile_identity_id,
|
||||
Err(e) => todo!("{}", e.to_string()),
|
||||
Err(e) => todo!("{e}"),
|
||||
},
|
||||
),
|
||||
};
|
||||
|
|
@ -83,14 +63,18 @@ impl Default {
|
|||
match option {
|
||||
// Activate identity for `scope`
|
||||
Some(profile_identity_id) => {
|
||||
if let Err(e) = profile.identity.auth.apply(profile_identity_id, &scope) {
|
||||
todo!("{}", e.to_string())
|
||||
if let Err(e) = profile
|
||||
.identity
|
||||
.auth
|
||||
.apply(profile_identity_id, &request.to_string())
|
||||
{
|
||||
todo!("{e}")
|
||||
};
|
||||
}
|
||||
// Remove all identity auths for `scope`
|
||||
None => {
|
||||
if let Err(e) = profile.identity.auth.remove_scope(&scope) {
|
||||
todo!("{}", e.to_string())
|
||||
if let Err(e) = profile.identity.auth.remove_scope(&request.to_string()) {
|
||||
todo!("{e}")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use adw::{
|
|||
prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual},
|
||||
AlertDialog, ResponseAppearance,
|
||||
};
|
||||
use gtk::prelude::IsA;
|
||||
use gtk::{glib::Uri, prelude::IsA};
|
||||
use std::rc::Rc;
|
||||
|
||||
// Defaults
|
||||
|
|
@ -39,7 +39,7 @@ impl Widget {
|
|||
pub fn build(
|
||||
(browser_action, window_action): (&Rc<BrowserAction>, &Rc<WindowAction>),
|
||||
profile: &Rc<Profile>,
|
||||
scope: &str,
|
||||
request: &Uri,
|
||||
) -> Self {
|
||||
// Init actions
|
||||
let widget_action = Rc::new(WidgetAction::new());
|
||||
|
|
@ -48,7 +48,7 @@ impl Widget {
|
|||
let form = Rc::new(Form::build(
|
||||
(browser_action, window_action, &widget_action),
|
||||
profile,
|
||||
scope,
|
||||
request,
|
||||
));
|
||||
|
||||
// Init main widget
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use crate::{
|
|||
app::browser::{action::Action as BrowserAction, window::action::Action as WindowAction},
|
||||
Profile,
|
||||
};
|
||||
use gtk::{prelude::BoxExt, Box, Orientation};
|
||||
use gtk::{glib::Uri, prelude::BoxExt, Box, Orientation};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Form {
|
||||
|
|
@ -29,7 +29,7 @@ pub struct Form {
|
|||
pub name: Rc<Name>,
|
||||
pub save: Rc<Save>,
|
||||
pub g_box: Box,
|
||||
scope: String,
|
||||
request: Uri,
|
||||
profile: Rc<Profile>,
|
||||
}
|
||||
|
||||
|
|
@ -44,10 +44,10 @@ impl Form {
|
|||
&Rc<WidgetAction>,
|
||||
),
|
||||
profile: &Rc<Profile>,
|
||||
scope: &str,
|
||||
request: &Uri,
|
||||
) -> Self {
|
||||
// Init components
|
||||
let list = Rc::new(List::build(widget_action, profile, scope));
|
||||
let list = Rc::new(List::build(widget_action, profile, request));
|
||||
let file = Rc::new(File::build(widget_action));
|
||||
let name = Rc::new(Name::build(widget_action));
|
||||
let save = Rc::new(Save::build(profile, &list));
|
||||
|
|
@ -56,7 +56,7 @@ impl Form {
|
|||
(browser_action, widget_action),
|
||||
profile,
|
||||
&list,
|
||||
scope,
|
||||
request,
|
||||
));
|
||||
|
||||
// Init main container
|
||||
|
|
@ -79,7 +79,7 @@ impl Form {
|
|||
name,
|
||||
save,
|
||||
g_box,
|
||||
scope: scope.to_string(),
|
||||
request: request.clone(),
|
||||
profile: profile.clone(),
|
||||
}
|
||||
}
|
||||
|
|
@ -112,7 +112,7 @@ impl Form {
|
|||
.identity
|
||||
.auth
|
||||
.memory
|
||||
.match_scope(&self.scope)
|
||||
.match_scope(&self.request.to_string())
|
||||
.is_some_and(|auth| auth.profile_identity_id == profile_identity_id),
|
||||
);
|
||||
self.save.update(true);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use adw::{
|
|||
AlertDialog, ResponseAppearance,
|
||||
};
|
||||
use gtk::{
|
||||
glib::Uri,
|
||||
prelude::{ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
|
|
@ -36,7 +37,7 @@ impl Exit {
|
|||
(browser_action, widget_action): (&Rc<BrowserAction>, &Rc<WidgetAction>),
|
||||
profile: &Rc<Profile>,
|
||||
list: &Rc<List>,
|
||||
scope: &str,
|
||||
request: &Uri,
|
||||
) -> Self {
|
||||
// Init main widget
|
||||
let button = Button::builder()
|
||||
|
|
@ -48,11 +49,11 @@ impl Exit {
|
|||
|
||||
// Init events
|
||||
button.connect_clicked({
|
||||
let scope = scope.to_string();
|
||||
let browser_action = browser_action.clone();
|
||||
let button = button.clone();
|
||||
let list = list.clone();
|
||||
let profile = profile.clone();
|
||||
let request = request.clone();
|
||||
let widget_action = widget_action.clone();
|
||||
move |_| {
|
||||
// Get selected identity from holder
|
||||
|
|
@ -83,16 +84,17 @@ impl Exit {
|
|||
|
||||
// Connect confirmation event
|
||||
alert_dialog.connect_response(Some(RESPONSE_CONFIRM.0), {
|
||||
let scope = scope.clone();
|
||||
let browser_action = browser_action.clone();
|
||||
let button = button.clone();
|
||||
let list = list.clone();
|
||||
let profile = profile.clone();
|
||||
let browser_action = browser_action.clone();
|
||||
let request = request.clone();
|
||||
let widget_action = widget_action.clone();
|
||||
move |_, _| {
|
||||
match profile.identity.auth.remove_ref(profile_identity_id) {
|
||||
Ok(_) => {
|
||||
match list.selected().update(&profile, &scope.to_string()) {
|
||||
match list.selected().update(&profile, &request.to_string())
|
||||
{
|
||||
Ok(_) => {
|
||||
button.set_css_classes(&["success"]);
|
||||
button
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use gtk::{
|
|||
prelude::{Cast, CastNone},
|
||||
ListStore,
|
||||
},
|
||||
glib::Uri,
|
||||
prelude::{BoxExt, ListItemExt, ObjectExt, WidgetExt},
|
||||
Align, Box, DropDown, Image, Label, ListItem, Orientation, SignalListItemFactory,
|
||||
};
|
||||
|
|
@ -24,7 +25,7 @@ impl List {
|
|||
// Constructors
|
||||
|
||||
/// Create new `Self`
|
||||
pub fn build(widget_action: &Rc<WidgetAction>, profile: &Rc<Profile>, scope: &str) -> Self {
|
||||
pub fn build(widget_action: &Rc<WidgetAction>, profile: &Rc<Profile>, request: &Uri) -> Self {
|
||||
// Init dropdown items
|
||||
let guest_session = Item::new_guest_session();
|
||||
let generate_pem = Item::new_generate_pem();
|
||||
|
|
@ -41,7 +42,8 @@ impl List {
|
|||
Ok(identities) => {
|
||||
let mut is_guest_session = true;
|
||||
for identity in identities {
|
||||
match Item::new_profile_identity_id(profile, identity.id, scope) {
|
||||
match Item::new_profile_identity_id(profile, identity.id, &request.to_string())
|
||||
{
|
||||
Ok(item) => {
|
||||
if item.is_active() {
|
||||
is_guest_session = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue