feat: paket: logout
This commit is contained in:
parent
4d0f8f57ce
commit
cf986694eb
6 changed files with 95 additions and 26 deletions
|
@ -1,9 +1,8 @@
|
|||
use adw::prelude::*;
|
||||
use gtk::gdk;
|
||||
use libpaket::{stammdaten::CustomerDataFull, LibraryError, LibraryResult};
|
||||
use relm4::{Component, ComponentParts};
|
||||
|
||||
use crate::LoginSharedState;
|
||||
use crate::{send_log_out, LoginSharedState};
|
||||
|
||||
#[tracker::track]
|
||||
pub struct AccountView {
|
||||
|
@ -31,6 +30,7 @@ pub enum CopyTargets {
|
|||
#[derive(Debug)]
|
||||
pub enum AccountInput {
|
||||
Copy(CopyTargets),
|
||||
LogOut,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -66,20 +66,49 @@ impl Component for AccountView {
|
|||
#[root]
|
||||
adw::Bin {
|
||||
#[wrap(Some)]
|
||||
set_child = >k::ListBox {
|
||||
set_child = >k::ScrolledWindow {
|
||||
set_propagate_natural_width: true,
|
||||
|
||||
#[wrap(Some)]
|
||||
set_child = &adw::Clamp {
|
||||
#[wrap(Some)]
|
||||
set_child = >k::Box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
set_margin_start: 12,
|
||||
set_margin_end: 12,
|
||||
|
||||
set_margin_top: 24,
|
||||
set_margin_bottom: 24,
|
||||
|
||||
// General infos
|
||||
append = &adw::PreferencesGroup {
|
||||
#[track(model.changed_customer_data_full() && model.get_customer_data_full().is_some())]
|
||||
set_title?: get_str_from_customer_data!(model, display_name).as_ref(),
|
||||
|
||||
#[wrap(Some)]
|
||||
set_header_suffix = >k::Box {
|
||||
add_css_class: relm4::css::LINKED,
|
||||
|
||||
append = >k::Button {
|
||||
add_css_class: relm4::css::DESTRUCTIVE_ACTION,
|
||||
set_label: "Log out",
|
||||
|
||||
connect_clicked => AccountInput::LogOut,
|
||||
},
|
||||
},
|
||||
|
||||
// Postnumber
|
||||
add = &adw::ActionRow {
|
||||
add_css_class: relm4::css::NUMERIC,
|
||||
set_subtitle: "Postnummer",
|
||||
|
||||
#[track(model.changed_customer_data_full() && model.get_customer_data_full().is_some())]
|
||||
set_title?: get_str_from_customer_data!(model, post_number).as_ref(),
|
||||
|
||||
set_subtitle: "Postnummer",
|
||||
|
||||
add_suffix = >k::Button {
|
||||
set_vexpand: false,
|
||||
set_valign: gtk::Align::Center,
|
||||
|
||||
#[wrap(Some)]
|
||||
set_child = &adw::ButtonContent {
|
||||
set_icon_name: relm4_icons::icon_names::COPY,
|
||||
|
@ -91,6 +120,8 @@ impl Component for AccountView {
|
|||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,6 +183,9 @@ impl Component for AccountView {
|
|||
clipboard.set_text(value.as_str());
|
||||
}
|
||||
}
|
||||
AccountInput::LogOut => {
|
||||
send_log_out();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use libpaket::LibraryError;
|
||||
use relm4::{adw, gtk, gtk::gdk, gtk::gio, gtk::glib};
|
||||
use relm4::{adw, gtk, gtk::gdk, gtk::gio};
|
||||
|
||||
use adw::prelude::*;
|
||||
use relm4::prelude::*;
|
||||
|
|
|
@ -117,6 +117,7 @@ pub struct AdvicesView {
|
|||
#[derive(Debug)]
|
||||
pub enum AdvicesViewInput {
|
||||
Fetch,
|
||||
Reset,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -197,7 +198,13 @@ impl AsyncComponent for AdvicesView {
|
|||
sender: AsyncComponentSender<Self>,
|
||||
root: &Self::Root,
|
||||
) {
|
||||
self.reset();
|
||||
|
||||
match message {
|
||||
AdvicesViewInput::Reset => {
|
||||
self.set_state(AdvicesViewState::Loading);
|
||||
self.factory.guard().clear();
|
||||
},
|
||||
AdvicesViewInput::Fetch => {
|
||||
self.set_state(AdvicesViewState::Loading);
|
||||
|
||||
|
|
|
@ -196,12 +196,35 @@ impl AsyncComponent for Login {
|
|||
|
||||
match message {
|
||||
LoginInput::LogOut => {
|
||||
self.refresh_token = None;
|
||||
sender.output(LoginOutput::RequiresLogin).unwrap();
|
||||
sender.input(LoginInput::NeedsLogin);
|
||||
{
|
||||
let token = get_id_token(&self.shared_id_token).await;
|
||||
if let Some(token) = token {
|
||||
sender.command(|_, shutdown| {
|
||||
shutdown
|
||||
.register(async move {
|
||||
let client = OpenIdClient::new();
|
||||
let _ = client.logout(&token).await;
|
||||
})
|
||||
.drop_on_shutdown()
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
let token = self.shared_id_token.lock().await;
|
||||
*token.write() = None;
|
||||
}
|
||||
if let Some(refresh_token) = self.refresh_token.clone() {
|
||||
sender.command(|out, shutdown| {
|
||||
shutdown
|
||||
.register(async move {
|
||||
let client = OpenIdClient::new();
|
||||
let _ = client.revoke(&refresh_token).await;
|
||||
})
|
||||
.drop_on_shutdown()
|
||||
});
|
||||
}
|
||||
self.refresh_token = None;
|
||||
let keyring = KEYRING.get().unwrap();
|
||||
let _ = keyring
|
||||
.delete(&HashMap::from([("app", crate::constants::APP_ID)]))
|
||||
|
@ -356,7 +379,7 @@ macro_rules! received {
|
|||
async fn $func_name$args -> LoginCommand {
|
||||
let client = OpenIdClient::new();
|
||||
let mut err = LibraryError::NetworkFetch;
|
||||
for _ in 0..6 {
|
||||
while err == LibraryError::NetworkFetch {
|
||||
let result: Result<TokenResponse, LibraryError> = client
|
||||
.$calling$calling_args
|
||||
.await;
|
||||
|
|
|
@ -222,7 +222,8 @@ impl Component for Ready {
|
|||
if self.logged_in {
|
||||
sender.output(ReadyOutput::Ready).unwrap();
|
||||
} else {
|
||||
todo!();
|
||||
self.advices_component.emit(AdvicesViewInput::Reset);
|
||||
self.tracking_component.emit(TrackingInput::Reset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ pub struct TrackingView {
|
|||
pub enum TrackingInput {
|
||||
Search(Option<String>),
|
||||
Notification(String),
|
||||
Reset,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -108,6 +109,9 @@ impl Component for TrackingView {
|
|||
|
||||
fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>, root: &Self::Root) {
|
||||
match message {
|
||||
TrackingInput::Reset => {
|
||||
self.factory.clear();
|
||||
}
|
||||
TrackingInput::Search(value) => {
|
||||
// Some input validation
|
||||
if let Some(value) = &value {
|
||||
|
|
Loading…
Reference in a new issue