Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into fix/683
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically authored Aug 21, 2023
2 parents 4250264 + c85f12f commit 73ff91f
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 732 deletions.
13 changes: 13 additions & 0 deletions sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5432,6 +5432,19 @@
},
"query": "\n SELECT name FROM report_types\n "
},
"e37ecb6dc1509d390bb6f68ba25899d19f693554d8969bbf8f8ee14a78adf0f9": {
"describe": {
"columns": [],
"nullable": [],
"parameters": {
"Left": [
"Bool",
"Int8"
]
}
},
"query": "\n UPDATE threads\n SET show_in_mod_inbox = $1\n WHERE id = $2\n "
},
"e3cc1fd070b97c4cc36bdb2f33080d4e0d7f3c3d81312d9d28a8c3c8213ad54b": {
"describe": {
"columns": [],
Expand Down
63 changes: 1 addition & 62 deletions src/auth/flows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ pub fn config(cfg: &mut ServiceConfig) {
.service(resend_verify_email)
.service(set_email)
.service(verify_email)
.service(subscribe_newsletter)
.service(login_from_minecraft)
.configure(super::minecraft::config),
.service(subscribe_newsletter),
);
}

Expand Down Expand Up @@ -1177,65 +1175,6 @@ pub async fn auth_callback(
Ok(res?)
}

#[derive(Deserialize)]
pub struct MinecraftLogin {
pub flow: String,
}

#[post("login/minecraft")]
pub async fn login_from_minecraft(
req: HttpRequest,
client: Data<PgPool>,
file_host: Data<Arc<dyn FileHost + Send + Sync>>,
redis: Data<deadpool_redis::Pool>,
login: web::Json<MinecraftLogin>,
) -> Result<HttpResponse, AuthenticationError> {
let flow = Flow::get(&login.flow, &redis).await?;

// Extract cookie header from request
if let Some(Flow::MicrosoftLogin {
access_token: token,
}) = flow
{
Flow::remove(&login.flow, &redis).await?;
let provider = AuthProvider::Microsoft;
let oauth_user = provider.get_user(&token).await?;
let user_id_opt = provider.get_user_id(&oauth_user.id, &**client).await?;

let mut transaction = client.begin().await?;

let user_id = if let Some(user_id) = user_id_opt {
let user = crate::database::models::User::get_id(user_id, &**client, &redis)
.await?
.ok_or_else(|| AuthenticationError::InvalidCredentials)?;

if user.totp_secret.is_some() {
let flow = Flow::Login2FA { user_id: user.id }
.insert(Duration::minutes(30), &redis)
.await?;

return Ok(HttpResponse::Ok().json(serde_json::json!({
"error": "2fa_required",
"flow": flow
})));
}

user_id
} else {
oauth_user
.create_account(provider, &mut transaction, &client, &file_host, &redis)
.await?
};

let session = issue_session(req, user_id, &mut transaction, &redis).await?;
Ok(HttpResponse::Ok().json(serde_json::json!({
"code": session.session
})))
} else {
Err(AuthenticationError::InvalidCredentials)
}
}

#[derive(Deserialize)]
pub struct DeleteAuthProvider {
pub provider: AuthProvider,
Expand Down
160 changes: 0 additions & 160 deletions src/auth/minecraft/auth.rs

This file was deleted.

35 changes: 0 additions & 35 deletions src/auth/minecraft/login.rs

This file was deleted.

60 changes: 0 additions & 60 deletions src/auth/minecraft/mod.rs

This file was deleted.

Loading

0 comments on commit 73ff91f

Please sign in to comment.