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),
|
||||
};
|
||||
|
||||
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<AppState>, Json(payload): J
|
|||
let doc = serde_json::from_str::<proto::RefreshResponse>(&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::<proto::SessionUser>(&response)
|
||||
info!(target:"REGISTER", "Mojang response to texture fetch [{}]: {}", url, &res);
|
||||
let doc = serde_json::from_str::<proto::SessionUser>(&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<AppState>, Json(payload): J
|
|||
|
||||
Ok(Json(proto::RegisterResponse {
|
||||
user: proto::Profile {
|
||||
name: user.username,
|
||||
id: user.id,
|
||||
name: doc.name,
|
||||
id: doc.id,
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue