fix: username != user name, uuid != user id, ...
This commit is contained in:
parent
fb03d27b41
commit
576397d5a9
1 changed files with 16 additions and 13 deletions
|
@ -16,8 +16,7 @@ pub async fn register_unmigrated(State(state): State<AppState>, Json(payload): J
|
||||||
requestUser: Some(true),
|
requestUser: Some(true),
|
||||||
};
|
};
|
||||||
|
|
||||||
let c = reqwest::Client::new();
|
let response = reqwest::Client::new().post("https://authserver.mojang.com/refresh")
|
||||||
let response = c.post("https://authserver.mojang.com/refresh")
|
|
||||||
.json(&form)
|
.json(&form)
|
||||||
.send().await
|
.send().await
|
||||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, Json(proto::Error::simple(format!("mojang error : {:?}", e)))))?
|
.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<AppState>, Json(payload): J
|
||||||
let doc = serde_json::from_str::<proto::RefreshResponse>(&response)
|
let doc = serde_json::from_str::<proto::RefreshResponse>(&response)
|
||||||
.map_err(|_| (StatusCode::UNAUTHORIZED, Json(proto::Error::simple("invalid token"))))?;
|
.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::Entity::insert(
|
||||||
entities::user::ActiveModel {
|
entities::user::ActiveModel {
|
||||||
id: NotSet,
|
id: NotSet,
|
||||||
name: Set(user.username.clone()),
|
name: Set(name),
|
||||||
password: Set(payload.password),
|
password: Set(payload.password),
|
||||||
uuid: Set(user.id),
|
uuid: Set(uuid),
|
||||||
}
|
}
|
||||||
).exec(&state.db).await
|
).exec(&state.db).await
|
||||||
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, Json(proto::Error::simple("db error"))))?;
|
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, Json(proto::Error::simple("db error"))))?;
|
||||||
|
|
||||||
let u = entities::user::Entity::find().filter(
|
let u = entities::user::Entity::find().filter(
|
||||||
entities::user::Column::Uuid.eq(user.id)
|
entities::user::Column::Uuid.eq(uuid)
|
||||||
).one(&state.db).await
|
).one(&state.db).await
|
||||||
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, Json(proto::Error::simple("db error"))))?
|
.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"))))?;
|
.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?
|
let url = format!("https://sessionserver.mojang.com/session/minecraft/profile/{}?unsigned=false", uuid.simple());
|
||||||
.send().await
|
let res = reqwest::Client::new().get(url.clone()) //TODO: needs trimmed uuid, is it trimmed by default?
|
||||||
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, Json(proto::Error::simple("internal server error"))))?
|
.json(&()).send()
|
||||||
|
.await.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, Json(proto::Error::simple("internal server error"))))?
|
||||||
.text().await.expect("invalid body on response");
|
.text().await.expect("invalid body on response");
|
||||||
|
|
||||||
info!(target:"REGISTER", "Mojang response to texture fetch: {}", &response);
|
info!(target:"REGISTER", "Mojang response to texture fetch [{}]: {}", url, &res);
|
||||||
let doc = serde_json::from_str::<proto::SessionUser>(&response)
|
let doc = serde_json::from_str::<proto::SessionUser>(&res)
|
||||||
.map_err(|_| (StatusCode::UNAUTHORIZED, Json(proto::Error::simple("invalid texture response"))))?;
|
.map_err(|_| (StatusCode::UNAUTHORIZED, Json(proto::Error::simple("invalid texture response"))))?;
|
||||||
|
|
||||||
let mut skin = proto::Property::default_skin();
|
let mut skin = proto::Property::default_skin();
|
||||||
|
@ -76,8 +79,8 @@ pub async fn register_unmigrated(State(state): State<AppState>, Json(payload): J
|
||||||
|
|
||||||
Ok(Json(proto::RegisterResponse {
|
Ok(Json(proto::RegisterResponse {
|
||||||
user: proto::Profile {
|
user: proto::Profile {
|
||||||
name: user.username,
|
name: doc.name,
|
||||||
id: user.id,
|
id: doc.id,
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue