ezidam: setup: create "ezidam" app in database
This commit is contained in:
parent
71b083895d
commit
95173b1a09
2 changed files with 41 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
use super::Error;
|
use super::Error;
|
||||||
|
|
||||||
|
// External crates
|
||||||
|
|
||||||
impl From<rocket::tokio::task::JoinError> for Error {
|
impl From<rocket::tokio::task::JoinError> for Error {
|
||||||
fn from(e: rocket::tokio::task::JoinError) -> Self {
|
fn from(e: rocket::tokio::task::JoinError) -> Self {
|
||||||
Error::internal_server_error(e)
|
Error::internal_server_error(e)
|
||||||
|
|
@ -12,6 +14,14 @@ impl From<rocket_db_pools::sqlx::Error> for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<url::ParseError> for Error {
|
||||||
|
fn from(e: url::ParseError) -> Self {
|
||||||
|
Error::internal_server_error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Local crates
|
||||||
|
|
||||||
impl From<hash::Error> for Error {
|
impl From<hash::Error> for Error {
|
||||||
fn from(e: hash::Error) -> Self {
|
fn from(e: hash::Error) -> Self {
|
||||||
Error::internal_server_error(e)
|
Error::internal_server_error(e)
|
||||||
|
|
@ -41,3 +51,9 @@ impl From<jwt::Error> for Error {
|
||||||
Error::internal_server_error(e)
|
Error::internal_server_error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<apps::Error> for Error {
|
||||||
|
fn from(e: apps::Error) -> Self {
|
||||||
|
Error::internal_server_error(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
use super::prelude::*;
|
use super::prelude::*;
|
||||||
|
use apps::App;
|
||||||
|
use hash::{Secret, SecretString};
|
||||||
use rocket::{get, post};
|
use rocket::{get, post};
|
||||||
use settings::Settings;
|
use settings::Settings;
|
||||||
|
use std::str::FromStr;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use users::User;
|
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
|
// Generate UserID
|
||||||
let user_id = task::spawn_blocking(UserID::default).await?;
|
let user_id = task::spawn_blocking(UserID::default).await?;
|
||||||
|
|
||||||
|
|
@ -56,6 +70,17 @@ async fn create_first_account(
|
||||||
|
|
||||||
let mut transaction = db.begin().await?;
|
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
|
// Insert user in database
|
||||||
User::insert(
|
User::insert(
|
||||||
&mut transaction,
|
&mut transaction,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue