Merge commit '2cfb637451441e5bd51dbfb736598ee33b7e8323' into feature-clean

This commit is contained in:
2024-11-28 02:41:36 +03:00
52 changed files with 2497 additions and 2950 deletions

View File

@@ -17,9 +17,9 @@ pub mod data {
pub use crate::state::{
CacheBehaviour, CacheValueType, Credentials, Dependency, DirectoryInfo,
Hooks, JavaVersion, LinkedData, MemorySettings, ModLoader,
ModrinthCredentials, ModrinthCredentialsResult, Organization,
ProcessMetadata, ProfileFile, Project, ProjectType, SearchResult,
SearchResults, Settings, TeamMember, Theme, User, Version, WindowSize,
ModrinthCredentials, Organization, ProcessMetadata, ProfileFile,
Project, ProjectType, SearchResult, SearchResults, Settings,
TeamMember, Theme, User, Version, WindowSize,
};
}

View File

@@ -1,84 +1,18 @@
use crate::state::{ModrinthCredentials, ModrinthCredentialsResult};
use serde_json::Value;
use std::collections::HashMap;
use crate::state::ModrinthCredentials;
#[tracing::instrument]
pub fn authenticate_begin_flow(provider: &str) -> String {
crate::state::get_login_url(provider)
pub fn authenticate_begin_flow() -> &'static str {
crate::state::get_login_url()
}
#[tracing::instrument]
pub async fn authenticate_finish_flow(
response: HashMap<String, Value>,
) -> crate::Result<ModrinthCredentialsResult> {
code: &str,
) -> crate::Result<ModrinthCredentials> {
let state = crate::State::get().await?;
let creds = crate::state::finish_login_flow(
response,
&state.api_semaphore,
&state.pool,
)
.await?;
if let ModrinthCredentialsResult::Credentials(creds) = &creds {
creds.upsert(&state.pool).await?;
}
Ok(creds)
}
pub async fn login_password(
username: &str,
password: &str,
challenge: &str,
) -> crate::Result<ModrinthCredentialsResult> {
let state = crate::State::get().await?;
let creds = crate::state::login_password(
username,
password,
challenge,
&state.api_semaphore,
&state.pool,
)
.await?;
if let ModrinthCredentialsResult::Credentials(creds) = &creds {
creds.upsert(&state.pool).await?;
}
Ok(creds)
}
#[tracing::instrument]
pub async fn login_2fa(
code: &str,
flow: &str,
) -> crate::Result<ModrinthCredentials> {
let state = crate::State::get().await?;
let creds =
crate::state::login_2fa(code, flow, &state.api_semaphore, &state.pool)
.await?;
creds.upsert(&state.pool).await?;
Ok(creds)
}
#[tracing::instrument]
pub async fn create_account(
username: &str,
email: &str,
password: &str,
challenge: &str,
sign_up_newsletter: bool,
) -> crate::Result<ModrinthCredentials> {
let state = crate::State::get().await?;
let creds = crate::state::create_account(
username,
email,
password,
challenge,
sign_up_newsletter,
code,
&state.api_semaphore,
&state.pool,
)