feat: added route for registering unmigrated accs

Pass a valid mojang token to the bakend to have it refreshed. If it's
valid, a new account will be created with previous uuid, name (email)
and given password.

Co-authored-by: zaaarf <zaaarf@proton.me>
This commit is contained in:
dev@ftbsc 2023-01-23 00:07:19 +01:00
parent 373eae1b72
commit 98446959bc
3 changed files with 17 additions and 18 deletions

View file

@ -16,7 +16,7 @@ use tracing::{info, metadata::LevelFilter};
use crate::routes::{
auth::{authenticate, validate, refresh},
session::{join, has_joined_wrapper, profile},
session::{join, has_joined_wrapper, profile}, register::register_unmigrated,
};
/// Reimplementation of legacy auth server for minecraft
@ -83,7 +83,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.route("/session/minecraft/hasJoined", get(has_joined_wrapper))
.route("/session/minecraft/profile/:user_id", get(profile))
// CUSTOM
.route("/register", post(register_tmp))
.route("/register/unmigrated", post(register_unmigrated))
.fallback(fallback_route)
.with_state(AppState { store, db, cfg });
@ -105,15 +105,3 @@ async fn fallback_route() -> impl IntoResponse {
(StatusCode::OK, Json(error))
}
async fn register_tmp(State(state): State<AppState>, Json(payload): Json<proto::RegisterRequest>) -> StatusCode {
let user = entities::user::ActiveModel {
id: NotSet,
name: Set(payload.user),
password: Set(payload.password),
uuid: Set(Uuid::new_v4()),
};
entities::user::Entity::insert(user).exec(&state.db).await.unwrap();
StatusCode::OK
}

View file

@ -134,11 +134,21 @@ pub struct JoinResponse {
pub properties: Vec<Property>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct AccessToken {
pub accessToken: String,
pub clientToken: String,
pub selectedProfile: Profile,
pub availableProfiles: Option<Vec<Profile>>,
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct RegisterRequest {
pub user: String,
pub token: AccessToken,
pub password: String,
}
#[derive(Serialize, Deserialize)]
pub struct RegisterResponse {
pub user: Profile
}

View file

@ -1,2 +1,3 @@
pub mod auth;
pub mod session;
pub mod register;