From 576397d5a949a99dec999433f32e8b49b3e3afab Mon Sep 17 00:00:00 2001 From: "dev@ftbsc" Date: Mon, 23 Jan 2023 02:48:08 +0100 Subject: [PATCH] fix: username != user name, uuid != user id, ... --- src/routes/register.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/routes/register.rs b/src/routes/register.rs index 2c0210b..ccc9ffa 100644 --- a/src/routes/register.rs +++ b/src/routes/register.rs @@ -16,8 +16,7 @@ pub async fn register_unmigrated(State(state): State, Json(payload): J requestUser: Some(true), }; - let c = reqwest::Client::new(); - let response = c.post("https://authserver.mojang.com/refresh") + let response = reqwest::Client::new().post("https://authserver.mojang.com/refresh") .json(&form) .send().await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, Json(proto::Error::simple(format!("mojang error : {:?}", e)))))? @@ -27,31 +26,35 @@ pub async fn register_unmigrated(State(state): State, Json(payload): J let doc = serde_json::from_str::(&response) .map_err(|_| (StatusCode::UNAUTHORIZED, Json(proto::Error::simple("invalid token"))))?; - let user = doc.user.expect("user not found in response, even though we requested it!"); + // TODO save email or some stuff from previous mojang profile? idk + let _user = doc.user.expect("user not found in response, even though we requested it!"); + let name = doc.selectedProfile.name.clone(); + let uuid = doc.selectedProfile.id; entities::user::Entity::insert( entities::user::ActiveModel { id: NotSet, - name: Set(user.username.clone()), + name: Set(name), password: Set(payload.password), - uuid: Set(user.id), + uuid: Set(uuid), } ).exec(&state.db).await .map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, Json(proto::Error::simple("db error"))))?; let u = entities::user::Entity::find().filter( - entities::user::Column::Uuid.eq(user.id) + entities::user::Column::Uuid.eq(uuid) ).one(&state.db).await .map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, Json(proto::Error::simple("db error"))))? .ok_or((StatusCode::INTERNAL_SERVER_ERROR, Json(proto::Error::simple("failed creating user"))))?; - let response = c.get(format!("https://sessionserver.mojang.com/session/minecraft/profile/{}", user.id)) //TODO: needs trimmed uuid, is it trimmed by default? - .send().await - .map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, Json(proto::Error::simple("internal server error"))))? + let url = format!("https://sessionserver.mojang.com/session/minecraft/profile/{}?unsigned=false", uuid.simple()); + let res = reqwest::Client::new().get(url.clone()) //TODO: needs trimmed uuid, is it trimmed by default? + .json(&()).send() + .await.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, Json(proto::Error::simple("internal server error"))))? .text().await.expect("invalid body on response"); - info!(target:"REGISTER", "Mojang response to texture fetch: {}", &response); - let doc = serde_json::from_str::(&response) + info!(target:"REGISTER", "Mojang response to texture fetch [{}]: {}", url, &res); + let doc = serde_json::from_str::(&res) .map_err(|_| (StatusCode::UNAUTHORIZED, Json(proto::Error::simple("invalid texture response"))))?; let mut skin = proto::Property::default_skin(); @@ -76,8 +79,8 @@ pub async fn register_unmigrated(State(state): State, Json(payload): J Ok(Json(proto::RegisterResponse { user: proto::Profile { - name: user.username, - id: user.id, + name: doc.name, + id: doc.id, } })) }