feat: added profile session route
This commit is contained in:
parent
430342ac74
commit
3fadbbba3d
3 changed files with 34 additions and 5 deletions
12
src/main.rs
12
src/main.rs
|
@ -12,8 +12,10 @@ use tokio::sync::Mutex;
|
|||
use uuid::Uuid;
|
||||
use tracing::info;
|
||||
|
||||
use crate::routes::auth::{authenticate, validate, refresh};
|
||||
use crate::routes::session::{join, has_joined};
|
||||
use crate::routes::{
|
||||
auth::{authenticate, validate, refresh},
|
||||
session::{join, has_joined, profile},
|
||||
};
|
||||
|
||||
/// Reimplementation of legacy auth server for minecraft
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
|
@ -62,13 +64,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let addr = cfg.bind_addr.parse()?;
|
||||
|
||||
let app = Router::new()
|
||||
// AUTH
|
||||
.route("/auth/authenticate", post(authenticate)) //in: username, pass; out: token
|
||||
.route("/auth/validate", post(validate)) //in: token; out: boolean valid
|
||||
.route("/auth/refresh", post(refresh)) //in: token out: refreshed token
|
||||
// .route("/signout", post(signout))
|
||||
// .route("/invalidate", post(invalidate))
|
||||
// SESSION
|
||||
.route("/session/minecraft/join", post(join))
|
||||
.route("/session/minecraft/hasJoined", get(has_joined))
|
||||
.route("/session/minecraft/profile/:user_id", get(profile))
|
||||
// CUSTOM
|
||||
.route("/register", post(register_tmp))
|
||||
.fallback(fallback_route)
|
||||
.with_state(AppState { store, db, cfg });
|
||||
|
|
|
@ -30,6 +30,14 @@ pub struct User {
|
|||
pub properties: Option<Vec<Property>>,
|
||||
}
|
||||
|
||||
/// Damn Mojang! Same as above, except for 'username' -> 'name'
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct SessionUser {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub properties: Option<Vec<Property>>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct Profile {
|
||||
pub name: String,
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use axum::{extract::{State, Query}, http::StatusCode, Json};
|
||||
use axum::{extract::{State, Query, Path}, http::StatusCode, Json};
|
||||
use chrono::{Duration, Utc};
|
||||
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
|
||||
use tracing::{info, warn};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{AppState, proto, JoinAttempt, entities};
|
||||
|
||||
|
@ -71,3 +72,19 @@ pub async fn has_joined(State(state): State<AppState>, Query(query): Query<HashM
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn profile(State(state): State<AppState>, Path(user_id): Path<Uuid>) -> Result<Json<proto::SessionUser>, StatusCode> {
|
||||
let user = entities::user::Entity::find().filter(
|
||||
entities::user::Column::Uuid.eq(user_id)
|
||||
).one(&state.db).await.unwrap();
|
||||
|
||||
if let Some(u) = user {
|
||||
Ok(Json(proto::SessionUser {
|
||||
id: u.uuid,
|
||||
name: u.name,
|
||||
properties: Some(vec![]),
|
||||
}))
|
||||
} else {
|
||||
Err(StatusCode::NOT_FOUND)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue