mirror of
				https://github.com/nitnelave/lldap.git
				synced 2023-04-12 14:25:13 +00:00 
			
		
		
		
	app: replace ConsoleService with gloo_console
This commit is contained in:
		
							parent
							
								
									f44e8b7659
								
							
						
					
					
						commit
						8d44717588
					
				
							
								
								
									
										27
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										27
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@ -1534,6 +1534,19 @@ dependencies = [
 | 
				
			|||||||
 "gloo-timers",
 | 
					 "gloo-timers",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "gloo-console"
 | 
				
			||||||
 | 
					version = "0.2.3"
 | 
				
			||||||
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
 | 
					checksum = "82b7ce3c05debe147233596904981848862b068862e9ec3e34be446077190d3f"
 | 
				
			||||||
 | 
					dependencies = [
 | 
				
			||||||
 | 
					 "gloo-utils",
 | 
				
			||||||
 | 
					 "js-sys",
 | 
				
			||||||
 | 
					 "serde",
 | 
				
			||||||
 | 
					 "wasm-bindgen",
 | 
				
			||||||
 | 
					 "web-sys",
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "gloo-console-timer"
 | 
					name = "gloo-console-timer"
 | 
				
			||||||
version = "0.1.0"
 | 
					version = "0.1.0"
 | 
				
			||||||
@ -1575,6 +1588,19 @@ dependencies = [
 | 
				
			|||||||
 "wasm-bindgen",
 | 
					 "wasm-bindgen",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "gloo-utils"
 | 
				
			||||||
 | 
					version = "0.1.6"
 | 
				
			||||||
 | 
					source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
				
			||||||
 | 
					checksum = "a8e8fc851e9c7b9852508bc6e3f690f452f474417e8545ec9857b7f7377036b5"
 | 
				
			||||||
 | 
					dependencies = [
 | 
				
			||||||
 | 
					 "js-sys",
 | 
				
			||||||
 | 
					 "serde",
 | 
				
			||||||
 | 
					 "serde_json",
 | 
				
			||||||
 | 
					 "wasm-bindgen",
 | 
				
			||||||
 | 
					 "web-sys",
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "graphql-introspection-query"
 | 
					name = "graphql-introspection-query"
 | 
				
			||||||
version = "0.2.0"
 | 
					version = "0.2.0"
 | 
				
			||||||
@ -2361,6 +2387,7 @@ dependencies = [
 | 
				
			|||||||
 "anyhow",
 | 
					 "anyhow",
 | 
				
			||||||
 "base64 0.13.1",
 | 
					 "base64 0.13.1",
 | 
				
			||||||
 "chrono",
 | 
					 "chrono",
 | 
				
			||||||
 | 
					 "gloo-console",
 | 
				
			||||||
 "graphql_client 0.10.0",
 | 
					 "graphql_client 0.10.0",
 | 
				
			||||||
 "http",
 | 
					 "http",
 | 
				
			||||||
 "image",
 | 
					 "image",
 | 
				
			||||||
 | 
				
			|||||||
@ -8,6 +8,7 @@ include = ["src/**/*", "queries/**/*", "Cargo.toml", "../schema.graphql"]
 | 
				
			|||||||
[dependencies]
 | 
					[dependencies]
 | 
				
			||||||
anyhow = "1"
 | 
					anyhow = "1"
 | 
				
			||||||
base64 = "0.13"
 | 
					base64 = "0.13"
 | 
				
			||||||
 | 
					gloo-console = "0.2.3"
 | 
				
			||||||
graphql_client = "0.10"
 | 
					graphql_client = "0.10"
 | 
				
			||||||
http = "0.2"
 | 
					http = "0.2"
 | 
				
			||||||
jwt = "0.13"
 | 
					jwt = "0.13"
 | 
				
			||||||
 | 
				
			|||||||
@ -16,10 +16,8 @@ use crate::{
 | 
				
			|||||||
    infra::{api::HostService, cookies::get_cookie},
 | 
					    infra::{api::HostService, cookies::get_cookie},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use yew::{
 | 
					use gloo_console::error;
 | 
				
			||||||
    prelude::*,
 | 
					use yew::{prelude::*, services::fetch::FetchTask};
 | 
				
			||||||
    services::{fetch::FetchTask, ConsoleService},
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
use yew_router::{
 | 
					use yew_router::{
 | 
				
			||||||
    agent::{RouteAgentDispatcher, RouteRequest},
 | 
					    agent::{RouteAgentDispatcher, RouteRequest},
 | 
				
			||||||
    route::Route,
 | 
					    route::Route,
 | 
				
			||||||
@ -51,14 +49,14 @@ impl Component for App {
 | 
				
			|||||||
            link,
 | 
					            link,
 | 
				
			||||||
            user_info: get_cookie("user_id")
 | 
					            user_info: get_cookie("user_id")
 | 
				
			||||||
                .unwrap_or_else(|e| {
 | 
					                .unwrap_or_else(|e| {
 | 
				
			||||||
                    ConsoleService::error(&e.to_string());
 | 
					                    error!(&e.to_string());
 | 
				
			||||||
                    None
 | 
					                    None
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
                .and_then(|u| {
 | 
					                .and_then(|u| {
 | 
				
			||||||
                    get_cookie("is_admin")
 | 
					                    get_cookie("is_admin")
 | 
				
			||||||
                        .map(|so| so.map(|s| (u, s == "true")))
 | 
					                        .map(|so| so.map(|s| (u, s == "true")))
 | 
				
			||||||
                        .unwrap_or_else(|e| {
 | 
					                        .unwrap_or_else(|e| {
 | 
				
			||||||
                            ConsoleService::error(&e.to_string());
 | 
					                            error!(&e.to_string());
 | 
				
			||||||
                            None
 | 
					                            None
 | 
				
			||||||
                        })
 | 
					                        })
 | 
				
			||||||
                }),
 | 
					                }),
 | 
				
			||||||
@ -105,7 +103,7 @@ impl Component for App {
 | 
				
			|||||||
            Msg::PasswordResetProbeFinished(Err(err)) => {
 | 
					            Msg::PasswordResetProbeFinished(Err(err)) => {
 | 
				
			||||||
                self.task = None;
 | 
					                self.task = None;
 | 
				
			||||||
                self.password_reset_enabled = Some(false);
 | 
					                self.password_reset_enabled = Some(false);
 | 
				
			||||||
                ConsoleService::error(&format!(
 | 
					                error!(&format!(
 | 
				
			||||||
                    "Could not probe for password reset support: {err:#}"
 | 
					                    "Could not probe for password reset support: {err:#}"
 | 
				
			||||||
                ));
 | 
					                ));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
@ -6,9 +6,10 @@ use crate::{
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use anyhow::{anyhow, bail, Context, Result};
 | 
					use anyhow::{anyhow, bail, Context, Result};
 | 
				
			||||||
 | 
					use gloo_console::error;
 | 
				
			||||||
use lldap_auth::*;
 | 
					use lldap_auth::*;
 | 
				
			||||||
use validator_derive::Validate;
 | 
					use validator_derive::Validate;
 | 
				
			||||||
use yew::{prelude::*, services::ConsoleService};
 | 
					use yew::prelude::*;
 | 
				
			||||||
use yew_form::Form;
 | 
					use yew_form::Form;
 | 
				
			||||||
use yew_form_derive::Model;
 | 
					use yew_form_derive::Model;
 | 
				
			||||||
use yew_router::{
 | 
					use yew_router::{
 | 
				
			||||||
@ -114,10 +115,7 @@ impl CommonComponent<ChangePasswordForm> for ChangePasswordForm {
 | 
				
			|||||||
                            |e| {
 | 
					                            |e| {
 | 
				
			||||||
                                // Common error, we want to print a full error to the console but only a
 | 
					                                // Common error, we want to print a full error to the console but only a
 | 
				
			||||||
                                // simple one to the user.
 | 
					                                // simple one to the user.
 | 
				
			||||||
                                ConsoleService::error(&format!(
 | 
					                                error!(&format!("Invalid username or password: {}", e));
 | 
				
			||||||
                                    "Invalid username or password: {}",
 | 
					 | 
				
			||||||
                                    e
 | 
					 | 
				
			||||||
                                ));
 | 
					 | 
				
			||||||
                                anyhow!("Invalid username or password")
 | 
					                                anyhow!("Invalid username or password")
 | 
				
			||||||
                            },
 | 
					                            },
 | 
				
			||||||
                        )?;
 | 
					                        )?;
 | 
				
			||||||
 | 
				
			|||||||
@ -3,10 +3,10 @@ use crate::{
 | 
				
			|||||||
    infra::common_component::{CommonComponent, CommonComponentParts},
 | 
					    infra::common_component::{CommonComponent, CommonComponentParts},
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use anyhow::{bail, Result};
 | 
					use anyhow::{bail, Result};
 | 
				
			||||||
 | 
					use gloo_console::log;
 | 
				
			||||||
use graphql_client::GraphQLQuery;
 | 
					use graphql_client::GraphQLQuery;
 | 
				
			||||||
use validator_derive::Validate;
 | 
					use validator_derive::Validate;
 | 
				
			||||||
use yew::prelude::*;
 | 
					use yew::prelude::*;
 | 
				
			||||||
use yew::services::ConsoleService;
 | 
					 | 
				
			||||||
use yew_form_derive::Model;
 | 
					use yew_form_derive::Model;
 | 
				
			||||||
use yew_router::{
 | 
					use yew_router::{
 | 
				
			||||||
    agent::{RouteAgentDispatcher, RouteRequest},
 | 
					    agent::{RouteAgentDispatcher, RouteRequest},
 | 
				
			||||||
@ -60,7 +60,7 @@ impl CommonComponent<CreateGroupForm> for CreateGroupForm {
 | 
				
			|||||||
                Ok(true)
 | 
					                Ok(true)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            Msg::CreateGroupResponse(response) => {
 | 
					            Msg::CreateGroupResponse(response) => {
 | 
				
			||||||
                ConsoleService::log(&format!(
 | 
					                log!(&format!(
 | 
				
			||||||
                    "Created group '{}'",
 | 
					                    "Created group '{}'",
 | 
				
			||||||
                    &response?.create_group.display_name
 | 
					                    &response?.create_group.display_name
 | 
				
			||||||
                ));
 | 
					                ));
 | 
				
			||||||
 | 
				
			|||||||
@ -6,11 +6,11 @@ use crate::{
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use anyhow::{bail, Context, Result};
 | 
					use anyhow::{bail, Context, Result};
 | 
				
			||||||
 | 
					use gloo_console::log;
 | 
				
			||||||
use graphql_client::GraphQLQuery;
 | 
					use graphql_client::GraphQLQuery;
 | 
				
			||||||
use lldap_auth::{opaque, registration};
 | 
					use lldap_auth::{opaque, registration};
 | 
				
			||||||
use validator_derive::Validate;
 | 
					use validator_derive::Validate;
 | 
				
			||||||
use yew::prelude::*;
 | 
					use yew::prelude::*;
 | 
				
			||||||
use yew::services::ConsoleService;
 | 
					 | 
				
			||||||
use yew_form_derive::Model;
 | 
					use yew_form_derive::Model;
 | 
				
			||||||
use yew_router::{
 | 
					use yew_router::{
 | 
				
			||||||
    agent::{RouteAgentDispatcher, RouteRequest},
 | 
					    agent::{RouteAgentDispatcher, RouteRequest},
 | 
				
			||||||
@ -102,7 +102,7 @@ impl CommonComponent<CreateUserForm> for CreateUserForm {
 | 
				
			|||||||
            Msg::CreateUserResponse(r) => {
 | 
					            Msg::CreateUserResponse(r) => {
 | 
				
			||||||
                match r {
 | 
					                match r {
 | 
				
			||||||
                    Err(e) => return Err(e),
 | 
					                    Err(e) => return Err(e),
 | 
				
			||||||
                    Ok(r) => ConsoleService::log(&format!(
 | 
					                    Ok(r) => log!(&format!(
 | 
				
			||||||
                        "Created user '{}' at '{}'",
 | 
					                        "Created user '{}' at '{}'",
 | 
				
			||||||
                        &r.create_user.id, &r.create_user.creation_date
 | 
					                        &r.create_user.id, &r.create_user.creation_date
 | 
				
			||||||
                    )),
 | 
					                    )),
 | 
				
			||||||
 | 
				
			|||||||
@ -6,9 +6,10 @@ use crate::{
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use anyhow::{anyhow, bail, Context, Result};
 | 
					use anyhow::{anyhow, bail, Context, Result};
 | 
				
			||||||
 | 
					use gloo_console::{debug, error};
 | 
				
			||||||
use lldap_auth::*;
 | 
					use lldap_auth::*;
 | 
				
			||||||
use validator_derive::Validate;
 | 
					use validator_derive::Validate;
 | 
				
			||||||
use yew::{prelude::*, services::ConsoleService};
 | 
					use yew::prelude::*;
 | 
				
			||||||
use yew_form::Form;
 | 
					use yew_form::Form;
 | 
				
			||||||
use yew_form_derive::Model;
 | 
					use yew_form_derive::Model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -77,7 +78,7 @@ impl CommonComponent<LoginForm> for LoginForm {
 | 
				
			|||||||
                        Err(e) => {
 | 
					                        Err(e) => {
 | 
				
			||||||
                            // Common error, we want to print a full error to the console but only a
 | 
					                            // Common error, we want to print a full error to the console but only a
 | 
				
			||||||
                            // simple one to the user.
 | 
					                            // simple one to the user.
 | 
				
			||||||
                            ConsoleService::error(&format!("Invalid username or password: {}", e));
 | 
					                            error!(&format!("Invalid username or password: {}", e));
 | 
				
			||||||
                            self.common.error = Some(anyhow!("Invalid username or password"));
 | 
					                            self.common.error = Some(anyhow!("Invalid username or password"));
 | 
				
			||||||
                            self.common.cancel_task();
 | 
					                            self.common.cancel_task();
 | 
				
			||||||
                            return Ok(true);
 | 
					                            return Ok(true);
 | 
				
			||||||
@ -132,7 +133,7 @@ impl Component for LoginForm {
 | 
				
			|||||||
            app.common
 | 
					            app.common
 | 
				
			||||||
                .call_backend(HostService::refresh, (), Msg::AuthenticationRefreshResponse)
 | 
					                .call_backend(HostService::refresh, (), Msg::AuthenticationRefreshResponse)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            ConsoleService::debug(&format!("Could not refresh auth: {}", e));
 | 
					            debug!(&format!("Could not refresh auth: {}", e));
 | 
				
			||||||
            app.refreshing = false;
 | 
					            app.refreshing = false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        app
 | 
					        app
 | 
				
			||||||
 | 
				
			|||||||
@ -8,7 +8,7 @@ use anyhow::{bail, Error, Result};
 | 
				
			|||||||
use graphql_client::GraphQLQuery;
 | 
					use graphql_client::GraphQLQuery;
 | 
				
			||||||
use validator_derive::Validate;
 | 
					use validator_derive::Validate;
 | 
				
			||||||
use wasm_bindgen::JsCast;
 | 
					use wasm_bindgen::JsCast;
 | 
				
			||||||
use yew::{prelude::*, services::ConsoleService};
 | 
					use yew::prelude::*;
 | 
				
			||||||
use yew_form_derive::Model;
 | 
					use yew_form_derive::Model;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(PartialEq, Eq, Clone, Default)]
 | 
					#[derive(PartialEq, Eq, Clone, Default)]
 | 
				
			||||||
@ -96,11 +96,8 @@ impl CommonComponent<UserDetailsForm> for UserDetailsForm {
 | 
				
			|||||||
                    .expect("Form field avatarInput should be present")
 | 
					                    .expect("Form field avatarInput should be present")
 | 
				
			||||||
                    .dyn_into::<web_sys::HtmlInputElement>()
 | 
					                    .dyn_into::<web_sys::HtmlInputElement>()
 | 
				
			||||||
                    .expect("Should be an HtmlInputElement");
 | 
					                    .expect("Should be an HtmlInputElement");
 | 
				
			||||||
                ConsoleService::log("Form update");
 | 
					 | 
				
			||||||
                if let Some(files) = input.files() {
 | 
					                if let Some(files) = input.files() {
 | 
				
			||||||
                    ConsoleService::log("Got file list");
 | 
					 | 
				
			||||||
                    if files.length() > 0 {
 | 
					                    if files.length() > 0 {
 | 
				
			||||||
                        ConsoleService::log("Got a file");
 | 
					 | 
				
			||||||
                        let new_avatar = JsFile {
 | 
					                        let new_avatar = JsFile {
 | 
				
			||||||
                            file: files.item(0),
 | 
					                            file: files.item(0),
 | 
				
			||||||
                            contents: None,
 | 
					                            contents: None,
 | 
				
			||||||
@ -339,11 +336,9 @@ impl Component for UserDetailsForm {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
impl UserDetailsForm {
 | 
					impl UserDetailsForm {
 | 
				
			||||||
    fn submit_user_update_form(&mut self) -> Result<bool> {
 | 
					    fn submit_user_update_form(&mut self) -> Result<bool> {
 | 
				
			||||||
        ConsoleService::log("Submit");
 | 
					 | 
				
			||||||
        if !self.form.validate() {
 | 
					        if !self.form.validate() {
 | 
				
			||||||
            bail!("Invalid inputs");
 | 
					            bail!("Invalid inputs");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        ConsoleService::log("Valid inputs");
 | 
					 | 
				
			||||||
        if let JsFile {
 | 
					        if let JsFile {
 | 
				
			||||||
            file: Some(_),
 | 
					            file: Some(_),
 | 
				
			||||||
            contents: None,
 | 
					            contents: None,
 | 
				
			||||||
@ -351,7 +346,6 @@ impl UserDetailsForm {
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            bail!("Image file hasn't finished loading, try again");
 | 
					            bail!("Image file hasn't finished loading, try again");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        ConsoleService::log("File is correctly loaded");
 | 
					 | 
				
			||||||
        let base_user = &self.common.user;
 | 
					        let base_user = &self.common.user;
 | 
				
			||||||
        let mut user_input = update_user::UpdateUserInput {
 | 
					        let mut user_input = update_user::UpdateUserInput {
 | 
				
			||||||
            id: self.common.user.id.clone(),
 | 
					            id: self.common.user.id.clone(),
 | 
				
			||||||
@ -379,11 +373,9 @@ impl UserDetailsForm {
 | 
				
			|||||||
        user_input.avatar = maybe_to_base64(&self.avatar)?;
 | 
					        user_input.avatar = maybe_to_base64(&self.avatar)?;
 | 
				
			||||||
        // Nothing changed.
 | 
					        // Nothing changed.
 | 
				
			||||||
        if user_input == default_user_input {
 | 
					        if user_input == default_user_input {
 | 
				
			||||||
            ConsoleService::log("No changes");
 | 
					 | 
				
			||||||
            return Ok(false);
 | 
					            return Ok(false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        let req = update_user::Variables { user: user_input };
 | 
					        let req = update_user::Variables { user: user_input };
 | 
				
			||||||
        ConsoleService::log("Querying");
 | 
					 | 
				
			||||||
        self.common.call_graphql::<UpdateUser, _>(
 | 
					        self.common.call_graphql::<UpdateUser, _>(
 | 
				
			||||||
            req,
 | 
					            req,
 | 
				
			||||||
            Msg::UserUpdated,
 | 
					            Msg::UserUpdated,
 | 
				
			||||||
 | 
				
			|||||||
@ -23,13 +23,13 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
use crate::infra::api::HostService;
 | 
					use crate::infra::api::HostService;
 | 
				
			||||||
use anyhow::{Error, Result};
 | 
					use anyhow::{Error, Result};
 | 
				
			||||||
 | 
					use gloo_console::{error, log};
 | 
				
			||||||
use graphql_client::GraphQLQuery;
 | 
					use graphql_client::GraphQLQuery;
 | 
				
			||||||
use yew::{
 | 
					use yew::{
 | 
				
			||||||
    prelude::*,
 | 
					    prelude::*,
 | 
				
			||||||
    services::{
 | 
					    services::{
 | 
				
			||||||
        fetch::FetchTask,
 | 
					        fetch::FetchTask,
 | 
				
			||||||
        reader::{FileData, ReaderService, ReaderTask},
 | 
					        reader::{FileData, ReaderService, ReaderTask},
 | 
				
			||||||
        ConsoleService,
 | 
					 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use yewtil::NeqAssign;
 | 
					use yewtil::NeqAssign;
 | 
				
			||||||
@ -100,7 +100,7 @@ impl<C: CommonComponent<C>> CommonComponentParts<C> {
 | 
				
			|||||||
        com.mut_common().error = None;
 | 
					        com.mut_common().error = None;
 | 
				
			||||||
        match com.handle_msg(msg) {
 | 
					        match com.handle_msg(msg) {
 | 
				
			||||||
            Err(e) => {
 | 
					            Err(e) => {
 | 
				
			||||||
                ConsoleService::error(&e.to_string());
 | 
					                error!(&e.to_string());
 | 
				
			||||||
                com.mut_common().error = Some(e);
 | 
					                com.mut_common().error = Some(e);
 | 
				
			||||||
                com.mut_common().cancel_task();
 | 
					                com.mut_common().cancel_task();
 | 
				
			||||||
                true
 | 
					                true
 | 
				
			||||||
@ -178,7 +178,7 @@ impl<C: CommonComponent<C>> CommonComponentParts<C> {
 | 
				
			|||||||
            error_message,
 | 
					            error_message,
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        .map_err::<(), _>(|e| {
 | 
					        .map_err::<(), _>(|e| {
 | 
				
			||||||
            ConsoleService::log(&e.to_string());
 | 
					            log!(&e.to_string());
 | 
				
			||||||
            self.error = Some(e);
 | 
					            self.error = Some(e);
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
        .ok()
 | 
					        .ok()
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user