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:
parent
373eae1b72
commit
98446959bc
3 changed files with 17 additions and 18 deletions
16
src/main.rs
16
src/main.rs
|
@ -16,7 +16,7 @@ use tracing::{info, metadata::LevelFilter};
|
||||||
|
|
||||||
use crate::routes::{
|
use crate::routes::{
|
||||||
auth::{authenticate, validate, refresh},
|
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
|
/// 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/hasJoined", get(has_joined_wrapper))
|
||||||
.route("/session/minecraft/profile/:user_id", get(profile))
|
.route("/session/minecraft/profile/:user_id", get(profile))
|
||||||
// CUSTOM
|
// CUSTOM
|
||||||
.route("/register", post(register_tmp))
|
.route("/register/unmigrated", post(register_unmigrated))
|
||||||
.fallback(fallback_route)
|
.fallback(fallback_route)
|
||||||
.with_state(AppState { store, db, cfg });
|
.with_state(AppState { store, db, cfg });
|
||||||
|
|
||||||
|
@ -105,15 +105,3 @@ async fn fallback_route() -> impl IntoResponse {
|
||||||
|
|
||||||
(StatusCode::OK, Json(error))
|
(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
|
|
||||||
}
|
|
||||||
|
|
18
src/proto.rs
18
src/proto.rs
|
@ -134,11 +134,21 @@ pub struct JoinResponse {
|
||||||
pub properties: Vec<Property>,
|
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, Debug)]
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
pub struct RegisterRequest {
|
pub struct RegisterRequest {
|
||||||
pub user: String,
|
pub token: AccessToken,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct RegisterResponse {
|
||||||
|
pub user: Profile
|
||||||
|
}
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
pub mod session;
|
pub mod session;
|
||||||
|
pub mod register;
|
||||||
|
|
Loading…
Reference in a new issue