diff --git a/migration/src/m20220101_000001_create_table.rs b/migration/src/m20220101_000001_create_table.rs index b4971fa..df696e6 100644 --- a/migration/src/m20220101_000001_create_table.rs +++ b/migration/src/m20220101_000001_create_table.rs @@ -20,6 +20,7 @@ impl MigrationTrait for Migration { ) .col(ColumnDef::new(User::Uuid).uuid().not_null()) .col(ColumnDef::new(User::Name).string().not_null()) + .col(ColumnDef::new(User::Email).string().not_null()) .col(ColumnDef::new(User::Password).string().not_null()) .to_owned(), ) @@ -76,6 +77,7 @@ enum User { Id, Name, Uuid, + Email, Password, } diff --git a/src/entities/user.rs b/src/entities/user.rs index 9ad76f7..d141917 100644 --- a/src/entities/user.rs +++ b/src/entities/user.rs @@ -9,6 +9,7 @@ pub struct Model { pub id: i32, pub uuid: Uuid, pub name: String, + pub email: String, pub password: String, } diff --git a/src/routes/auth.rs b/src/routes/auth.rs index e3929dc..38a397b 100644 --- a/src/routes/auth.rs +++ b/src/routes/auth.rs @@ -61,7 +61,7 @@ pub async fn refresh(State(state): State, Json(payload): Json, Json(payload): Json) -> proto::Response { info!(target: "AUTH", "[AUTHENTICATE] called with {:?}", payload); let user = entities::user::Entity::find().filter( - entities::user::Column::Name.eq(payload.username) + entities::user::Column::Email.eq(payload.username) ).one(&state.db).await .map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, proto::Error::simple("db error").json()))?; diff --git a/src/routes/register.rs b/src/routes/register.rs index ccc9ffa..e1096f8 100644 --- a/src/routes/register.rs +++ b/src/routes/register.rs @@ -26,8 +26,7 @@ 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"))))?; - // 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 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; @@ -35,6 +34,7 @@ pub async fn register_unmigrated(State(state): State, Json(payload): J entities::user::ActiveModel { id: NotSet, name: Set(name), + email: Set(user.username), password: Set(payload.password), uuid: Set(uuid), }