fix!: added email field, check pwd against email

This commit is contained in:
dev@ftbsc 2023-01-23 02:59:47 +01:00
parent 576397d5a9
commit e89a9b4495
4 changed files with 6 additions and 3 deletions

View file

@ -20,6 +20,7 @@ impl MigrationTrait for Migration {
) )
.col(ColumnDef::new(User::Uuid).uuid().not_null()) .col(ColumnDef::new(User::Uuid).uuid().not_null())
.col(ColumnDef::new(User::Name).string().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()) .col(ColumnDef::new(User::Password).string().not_null())
.to_owned(), .to_owned(),
) )
@ -76,6 +77,7 @@ enum User {
Id, Id,
Name, Name,
Uuid, Uuid,
Email,
Password, Password,
} }

View file

@ -9,6 +9,7 @@ pub struct Model {
pub id: i32, pub id: i32,
pub uuid: Uuid, pub uuid: Uuid,
pub name: String, pub name: String,
pub email: String,
pub password: String, pub password: String,
} }

View file

@ -61,7 +61,7 @@ pub async fn refresh(State(state): State<AppState>, Json(payload): Json<proto::R
pub async fn authenticate(State(state): State<AppState>, Json(payload): Json<proto::AuthenticateRequest>) -> proto::Response<proto::AuthenticateResponse> { pub async fn authenticate(State(state): State<AppState>, Json(payload): Json<proto::AuthenticateRequest>) -> proto::Response<proto::AuthenticateResponse> {
info!(target: "AUTH", "[AUTHENTICATE] called with {:?}", payload); info!(target: "AUTH", "[AUTHENTICATE] called with {:?}", payload);
let user = entities::user::Entity::find().filter( 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 ).one(&state.db).await
.map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, proto::Error::simple("db error").json()))?; .map_err(|_| (StatusCode::INTERNAL_SERVER_ERROR, proto::Error::simple("db error").json()))?;

View file

@ -26,8 +26,7 @@ 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"))))?;
// 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 name = doc.selectedProfile.name.clone();
let uuid = doc.selectedProfile.id; let uuid = doc.selectedProfile.id;
@ -35,6 +34,7 @@ pub async fn register_unmigrated(State(state): State<AppState>, Json(payload): J
entities::user::ActiveModel { entities::user::ActiveModel {
id: NotSet, id: NotSet,
name: Set(name), name: Set(name),
email: Set(user.username),
password: Set(payload.password), password: Set(payload.password),
uuid: Set(uuid), uuid: Set(uuid),
} }