diff --git a/src/frontend/rest/services/authentication.rs b/src/frontend/rest/services/authentication.rs index 46e0efd..aa358f1 100644 --- a/src/frontend/rest/services/authentication.rs +++ b/src/frontend/rest/services/authentication.rs @@ -2,7 +2,6 @@ //! //! Provides mechanisms to authenticate users using JWT. -use std::collections::HashMap; use std::sync::Arc; use futures::{Future, Stream}; @@ -13,16 +12,14 @@ use jwt::{decode, Algorithm, Validation}; use reqwest::header::USER_AGENT; -use url::form_urlencoded; +use crate::frontend::rest::services::Future as InternalFuture; +use crate::frontend::rest::services::{default_future, Request, Response, WebService}; -use frontend::rest::services::Future as InternalFuture; -use frontend::rest::services::{default_future, Request, Response, WebService}; +use crate::http::{build_async_client, build_client}; -use http::{build_async_client, build_client}; +use crate::config::JWTValidation; -use config::JWTValidation; - -use logging::LoggingErrors; +use crate::logging::LoggingErrors; #[derive(Debug, Serialize, Deserialize)] struct Auth { @@ -48,6 +45,12 @@ pub struct JWTClaims { pub is_subscribed: bool, } +#[derive(Debug, Serialize, Deserialize, Clone)] +struct AuthRequest { + username: String, + token: String +} + /// Calls the given server to obtain a JWT token and returns a Future with the response pub fn authenticate_async( url: String, @@ -163,6 +166,7 @@ pub fn validate_token( } pub fn handle(service: &WebService, _req: Request) -> InternalFuture { + info!("Handling authentication"); let framework = service .framework .read() @@ -185,14 +189,12 @@ pub fn handle(service: &WebService, _req: Request) -> InternalFuture { _req.body() .concat2() .map(move |body| { - let req = form_urlencoded::parse(body.as_ref()) - .into_owned() - .collect::>(); + let req: AuthRequest = serde_json::from_slice(&body).log_expect("Malformed request"); // Determine which credentials we should use let (username, token) = { - let req_username = req.get("username").log_expect("No username in request"); - let req_token = req.get("token").log_expect("No token in request"); + let req_username = req.username; + let req_token = req.token; // if the user didn't provide credentials, and theres nothing stored in the // database, return an early error diff --git a/src/frontend/rest/services/browser.rs b/src/frontend/rest/services/browser.rs index f0440a7..65e6732 100644 --- a/src/frontend/rest/services/browser.rs +++ b/src/frontend/rest/services/browser.rs @@ -2,20 +2,21 @@ //! //! Launches the user's web browser on request from the frontend. -use frontend::rest::services::Future as InternalFuture; -use frontend::rest::services::{Request, Response, WebService}; +use crate::frontend::rest::services::Future as InternalFuture; +use crate::frontend::rest::services::{Request, Response, WebService}; +use crate::logging::LoggingErrors; use futures::{Future, Stream}; use hyper::header::ContentType; -use logging::LoggingErrors; -use std::collections::HashMap; -use url::form_urlencoded; + +#[derive(Debug, Serialize, Deserialize, Clone)] +struct OpenRequest { + url: String, +} pub fn handle(_service: &WebService, req: Request) -> InternalFuture { Box::new(req.body().concat2().map(move |body| { - let req = form_urlencoded::parse(body.as_ref()) - .into_owned() - .collect::>(); - if webbrowser::open(req.get("url").log_expect("No URL to launch")).is_ok() { + let req: OpenRequest = serde_json::from_slice(&body).log_expect("Malformed request"); + if webbrowser::open(&req.url).is_ok() { Response::new() .with_status(hyper::Ok) .with_header(ContentType::json()) diff --git a/src/frontend/rest/services/install.rs b/src/frontend/rest/services/install.rs index ac27dd8..68cdc9d 100644 --- a/src/frontend/rest/services/install.rs +++ b/src/frontend/rest/services/install.rs @@ -39,6 +39,7 @@ pub fn handle(service: &WebService, req: Request) -> Future { } else if key == "installDesktopShortcut" { info!("Found installDesktopShortcut {:?}", value); install_desktop_shortcut = value == "true"; + continue; } if key == "mode" && value == "force" { diff --git a/src/frontend/ui/mod.rs b/src/frontend/ui/mod.rs index 852f5f4..b62cfa4 100644 --- a/src/frontend/ui/mod.rs +++ b/src/frontend/ui/mod.rs @@ -17,7 +17,7 @@ enum CallbackType { /// Starts the main web UI. Will return when UI is closed. pub fn start_ui(app_name: &str, http_address: &str, is_launcher: bool) { - let size = if is_launcher { (600, 300) } else { (1024, 500) }; + let size = if is_launcher { (600, 300) } else { (1024, 600) }; info!("Spawning web view instance"); diff --git a/src/native/mod.rs b/src/native/mod.rs index c2ec0f6..335b8b8 100644 --- a/src/native/mod.rs +++ b/src/native/mod.rs @@ -333,7 +333,7 @@ mod natives { }; path.push(format!("{}.desktop", slugify(name))); // file name let desktop_file = format!( - "[Desktop Entry]\nName={}\nExec=\"{}\" {}\nComment={}\nPath={}\n", + "[Desktop Entry]\nName={}\nExec=\"{}\" {}\nComment={}\nType=Application\nPath={}\n", name, target, args, description, working_dir ); let desktop_f = File::create(path); diff --git a/src/sources/patreon.rs b/src/sources/patreon.rs index e66a2ae..b989b5d 100644 --- a/src/sources/patreon.rs +++ b/src/sources/patreon.rs @@ -2,10 +2,10 @@ //! //! Contains the yuzu-emu core API implementation of a release source. -use http::build_client; +use crate::http::build_client; +use crate::sources::types::*; use reqwest::header::USER_AGENT; use reqwest::StatusCode; -use sources::types::*; pub struct PatreonReleases {} diff --git a/src/tasks/check_authorization.rs b/src/tasks/check_authorization.rs index 575bc76..05e6be6 100644 --- a/src/tasks/check_authorization.rs +++ b/src/tasks/check_authorization.rs @@ -1,13 +1,13 @@ //! Validates that users have correct authorization to download packages. -use frontend::rest::services::authentication; +use crate::frontend::rest::services::authentication; -use installer::InstallerFramework; +use crate::installer::InstallerFramework; -use logging::LoggingErrors; +use crate::logging::LoggingErrors; -use tasks::resolver::ResolvePackageTask; -use tasks::{Task, TaskDependency, TaskMessage, TaskOrdering, TaskParamType}; +use crate::tasks::resolver::ResolvePackageTask; +use crate::tasks::{Task, TaskDependency, TaskMessage, TaskOrdering, TaskParamType}; pub struct CheckAuthorizationTask { pub name: String, diff --git a/src/tasks/download_pkg.rs b/src/tasks/download_pkg.rs index 240b998..7d033cb 100644 --- a/src/tasks/download_pkg.rs +++ b/src/tasks/download_pkg.rs @@ -9,8 +9,6 @@ use crate::tasks::TaskMessage; use crate::tasks::TaskOrdering; use crate::tasks::TaskParamType; -use crate::tasks::resolver::ResolvePackageTask; - use crate::http::stream_file; use number_prefix::NumberPrefix::{self, Prefixed, Standalone}; diff --git a/src/tasks/install_desktop_shortcut.rs b/src/tasks/install_desktop_shortcut.rs index 58cb797..819f63b 100644 --- a/src/tasks/install_desktop_shortcut.rs +++ b/src/tasks/install_desktop_shortcut.rs @@ -1,17 +1,17 @@ //! Generates shortcuts for a specified file. -use installer::InstallerFramework; +use crate::installer::InstallerFramework; -use tasks::Task; -use tasks::TaskDependency; -use tasks::TaskMessage; -use tasks::TaskParamType; +use crate::tasks::Task; +use crate::tasks::TaskDependency; +use crate::tasks::TaskMessage; +use crate::tasks::TaskParamType; -use config::PackageDescription; +use crate::config::PackageDescription; -use logging::LoggingErrors; +use crate::logging::LoggingErrors; -use native::create_desktop_shortcut; +use crate::native::create_shortcut; pub struct InstallDesktopShortcutTask { pub name: String, @@ -81,7 +81,7 @@ impl Task for InstallDesktopShortcutTask { .to_str() .log_expect("Unable to build shortcut metadata (exe)"); - installed_files.push(create_desktop_shortcut( + installed_files.push(create_shortcut( &shortcut.name, &shortcut.description, tool_path, diff --git a/src/tasks/install_pkg.rs b/src/tasks/install_pkg.rs index d5d2863..79a7ea3 100644 --- a/src/tasks/install_pkg.rs +++ b/src/tasks/install_pkg.rs @@ -22,9 +22,9 @@ use crate::logging::LoggingErrors; use crate::archives; +use crate::tasks::install_desktop_shortcut::InstallDesktopShortcutTask; use std::fs::OpenOptions; use std::path::Path; -use tasks::install_desktop_shortcut::InstallDesktopShortcutTask; pub struct InstallPackageTask { pub name: String, @@ -70,13 +70,18 @@ impl Task for InstallPackageTask { // Ignore input from the uninstaller - no useful information passed // If a previous task Breaks, then just early exit - match input.pop().log_expect("Install Package Task should have guaranteed output!") { + match input + .pop() + .log_expect("Install Package Task should have guaranteed output!") + { TaskParamType::Break => return Ok(TaskParamType::None), _ => (), }; // Grab data from the resolver - let data = input.pop().log_expect("Install Package Task should have input from resolver!"); + let data = input + .pop() + .log_expect("Install Package Task should have input from resolver!"); let (version, file, data) = match data { TaskParamType::FileContents(version, file, data) => (version, file, data), _ => return Err("Unexpected file contents param type to install package".to_string()), @@ -201,7 +206,7 @@ impl Task for InstallPackageTask { TaskOrdering::Post, Box::new(InstallDesktopShortcutTask { name: self.name.clone(), - should_run: self.create_desktop_shortcuts + should_run: self.create_desktop_shortcuts, }), ), TaskDependency::build(TaskOrdering::Post, Box::new(SaveDatabaseTask {})), diff --git a/src/tasks/launch_installed_on_exit.rs b/src/tasks/launch_installed_on_exit.rs index 5b67cf5..f286932 100644 --- a/src/tasks/launch_installed_on_exit.rs +++ b/src/tasks/launch_installed_on_exit.rs @@ -2,16 +2,16 @@ //! If theres multiple launchable packages, then choose the first listed in config //! If there are multiple shortcuts for the first package, then launch the first. -use installer::InstallerFramework; +use crate::installer::InstallerFramework; -use tasks::Task; -use tasks::TaskDependency; -use tasks::TaskMessage; -use tasks::TaskParamType; +use crate::tasks::Task; +use crate::tasks::TaskDependency; +use crate::tasks::TaskMessage; +use crate::tasks::TaskParamType; -use config::PackageDescription; +use crate::config::PackageDescription; -use logging::LoggingErrors; +use crate::logging::LoggingErrors; pub struct LaunchOnExitTask {} diff --git a/ui/mock-server.js b/ui/mock-server.js index 927d666..7f5922b 100644 --- a/ui/mock-server.js +++ b/ui/mock-server.js @@ -100,7 +100,8 @@ app.get('/api/config', (req, res) => { }) app.post('/api/start-install', (req, res) => { - console.log(`-- Install: ${req}`) + console.log('-- Install:') + console.log(req.body) progressSimulation(res) }) diff --git a/ui/src/main.js b/ui/src/main.js index 7026e9f..d62fae9 100644 --- a/ui/src/main.js +++ b/ui/src/main.js @@ -152,10 +152,13 @@ const app = new Vue({ const that = this const app = this.$root - app.ajax('/api/check-auth', function (auth) { - app.$data.username = auth.username - app.$data.token = auth.token - that.jwt_token = auth.jwt_token + axios.post('/api/check-auth', { + username: app.$data.username, + token: app.$data.token + }).then(function (resp) { + app.$data.username = resp.data.username + app.$data.token = resp.data.token + that.jwt_token = resp.data.jwt_token that.is_authenticated = Object.keys(that.jwt_token).length !== 0 && that.jwt_token.constructor === Object if (that.is_authenticated) { // Give all permissions to vip roles @@ -166,13 +169,10 @@ const app = new Vue({ if (success) { success() } - }, function (e) { + }).catch(function () { if (error) { error() } - }, { - username: app.$data.username, - token: app.$data.token }) }, stream_ajax: streamAjax diff --git a/ui/src/views/AuthenticationView.vue b/ui/src/views/AuthenticationView.vue index 125c5e0..824f8e6 100644 --- a/ui/src/views/AuthenticationView.vue +++ b/ui/src/views/AuthenticationView.vue @@ -75,56 +75,55 @@ \ No newline at end of file + diff --git a/ui/src/views/SelectPackages.vue b/ui/src/views/SelectPackages.vue index b554faf..a16105b 100644 --- a/ui/src/views/SelectPackages.vue +++ b/ui/src/views/SelectPackages.vue @@ -26,14 +26,14 @@ -
-

Install Options

- - Create Desktop Shortcut - -
+
+

Install Options

+ + Create Desktop Shortcut + +
{{ $t('select_packages.location') }}
@@ -79,6 +79,7 @@ export default { name: 'SelectPackages', data: function () { return { + publicPath: process.env.BASE_URL, advanced: false, repair: false, installDesktopShortcut: true @@ -131,22 +132,22 @@ export default { } // maintenance + repair if (this.repair) { - this.$router.push('/install/repair') + this.$router.push('/install/repair/' + this.installDesktopShortcut.toString()) return } // maintenance + modify if (this.$root.$data.metadata.preexisting_install) { - this.$router.push('/install/regular') + this.$router.push('/install/regular/' + this.installDesktopShortcut.toString()) return } const my = this this.$http.post('/api/verify-path', `path=${this.$root.$data.install_location}`).then(function (resp) { const data = resp.data || {} if (!data.exists) { - my.$router.push('/install/regular') + my.$router.push('/install/regular/' + my.installDesktopShortcut.toString()) } else { my.show_overwrite_dialog(function () { - my.$router.push('/install/repair') + my.$router.push('/install/repair/' + my.installDesktopShortcut.toString()) }) } })