fix!: added email field, check pwd against email
This commit is contained in:
parent
576397d5a9
commit
e89a9b4495
4 changed files with 6 additions and 3 deletions
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ pub struct Model {
|
|||
pub id: i32,
|
||||
pub uuid: Uuid,
|
||||
pub name: String,
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
|
|
|
@ -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> {
|
||||
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()))?;
|
||||
|
||||
|
|
|
@ -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)
|
||||
.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<AppState>, Json(payload): J
|
|||
entities::user::ActiveModel {
|
||||
id: NotSet,
|
||||
name: Set(name),
|
||||
email: Set(user.username),
|
||||
password: Set(payload.password),
|
||||
uuid: Set(uuid),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue