diff --git a/crates/ezidam/src/error/conversion.rs b/crates/ezidam/src/error/conversion.rs index b56fc24..887d6e4 100644 --- a/crates/ezidam/src/error/conversion.rs +++ b/crates/ezidam/src/error/conversion.rs @@ -1,5 +1,7 @@ use super::Error; +// External crates + impl From for Error { fn from(e: rocket::tokio::task::JoinError) -> Self { Error::internal_server_error(e) @@ -12,6 +14,14 @@ impl From for Error { } } +impl From for Error { + fn from(e: url::ParseError) -> Self { + Error::internal_server_error(e) + } +} + +// Local crates + impl From for Error { fn from(e: hash::Error) -> Self { Error::internal_server_error(e) @@ -41,3 +51,9 @@ impl From for Error { Error::internal_server_error(e) } } + +impl From for Error { + fn from(e: apps::Error) -> Self { + Error::internal_server_error(e) + } +} diff --git a/crates/ezidam/src/routes/setup.rs b/crates/ezidam/src/routes/setup.rs index ef06303..c8431b9 100644 --- a/crates/ezidam/src/routes/setup.rs +++ b/crates/ezidam/src/routes/setup.rs @@ -1,6 +1,9 @@ use super::prelude::*; +use apps::App; +use hash::{Secret, SecretString}; use rocket::{get, post}; use settings::Settings; +use std::str::FromStr; use url::Url; use users::User; @@ -47,6 +50,17 @@ async fn create_first_account( } }; + // Generate secret for ezidam app + let ezidam_secret = task::spawn_blocking(SecretString::default).await?; + // Hash secret for ezidam app + let ezidam_secret_hash = task::spawn_blocking(move || Secret::new(ezidam_secret)).await??; + + // Create redirect uri for ezidam + let ezidam_redirect_uri = url.join("/oauth/redirect")?; + + // Create app id for ezidam + let ezidam_app_id = AppID::from_str("ezidam").map_err(Error::internal_server_error)?; + // Generate UserID let user_id = task::spawn_blocking(UserID::default).await?; @@ -56,6 +70,17 @@ async fn create_first_account( let mut transaction = db.begin().await?; + // Insert ezidam app in database + App::insert( + &mut transaction, + &ezidam_app_id, + "Ezidam", + &ezidam_redirect_uri, + &ezidam_secret_hash, + true, + ) + .await?; + // Insert user in database User::insert( &mut transaction,