diff --git a/core/src/crypto.rs b/core/src/crypto.rs index 2b823dbe..8614a874 100644 --- a/core/src/crypto.rs +++ b/core/src/crypto.rs @@ -344,7 +344,7 @@ mod tests { #[tokio::test] async fn test_verify_password() { - const HASH: &str = "$argon2id$v=19$m=4096,t=3,p=1$c2VjcmV0bHl0ZXN0aW5nZXZlcnl0aGluZw$xEzH8wD/ZjzgZTDTl3YtzMFCfcVa5M5m9y6NfSyB1n4"; + const HASH: &str = "$argon2i$v=19$m=6000,t=3,p=10$WE9xCQmmWdBK82R4SEjoqA$TZSc6PuLd4aWK2x2WAb+Lm9sLySqjK3KLbNyqyQmzPQ"; const PASSWORD: &str = "test"; let result = super::verify_password(PASSWORD.to_string(), HASH.to_string()) diff --git a/core/src/database/mutation/candidate.rs b/core/src/database/mutation/candidate.rs index 14b94ce5..4c86b088 100644 --- a/core/src/database/mutation/candidate.rs +++ b/core/src/database/mutation/candidate.rs @@ -1,4 +1,4 @@ -use crate::{Mutation, services::candidate_service::{AddUserDetailsForm, EncryptedAddUserData}}; +use crate::{Mutation}; use ::entity::candidate::{self, Model}; use sea_orm::{*}; @@ -8,13 +8,13 @@ impl Mutation { db: &DbConn, application_id: i32, hashed_password: String, - encrypted_personal_id_number: String, + hashed_personal_id_number: String, pubkey: String, encrypted_priv_key: String ) -> Result { candidate::ActiveModel { application: Set(application_id), - personal_identification_number: Set(encrypted_personal_id_number), + personal_identification_number_hash: Set(hashed_personal_id_number), code: Set(hashed_password), public_key: Set(pubkey), private_key: Set(encrypted_priv_key), @@ -26,22 +26,31 @@ impl Mutation { .await } - pub async fn add_user_details( + pub async fn add_candidate_details( db: &DbConn, user: Model, - details: EncryptedAddUserData, + name: String, + surname: String, + birthplace: String, + birthdate: String, + address: String, + telephone: String, + citizenship: String, + email: String, + sex: String, + study: String, ) -> Result { let mut user: candidate::ActiveModel = user.into(); - user.name = Set(Some(details.name)); - user.surname = Set(Some(details.surname)); - user.birthplace = Set(Some(details.birthplace)); - user.birthdate = Set(Some(details.birthdate)); - user.address = Set(Some(details.address)); - user.telephone = Set(Some(details.telephone)); - user.citizenship = Set(Some(details.citizenship)); - user.email = Set(Some(details.email)); - user.sex = Set(Some(details.sex)); - user.study = Set(Some(details.study)); + user.name = Set(Some(name)); + user.surname = Set(Some(surname)); + user.birthplace = Set(Some(birthplace)); + user.birthdate = Set(None); + user.address = Set(Some(address)); + user.telephone = Set(Some(telephone)); + user.citizenship = Set(Some(citizenship)); + user.email = Set(Some(email)); + user.sex = Set(Some(sex)); + user.study = Set(Some(study)); user.updated_at = Set(chrono::offset::Local::now().naive_local()); diff --git a/core/src/database/query/candidate.rs b/core/src/database/query/candidate.rs index a8b55521..72ef4248 100644 --- a/core/src/database/query/candidate.rs +++ b/core/src/database/query/candidate.rs @@ -41,7 +41,7 @@ mod tests { code: Set("test".to_string()), public_key: Set("test".to_string()), private_key: Set("test".to_string()), - personal_identification_number: Set("test".to_string()), + personal_identification_number_hash: Set("test".to_string()), created_at: Set(chrono::offset::Local::now().naive_local()), updated_at: Set(chrono::offset::Local::now().naive_local()), ..Default::default() diff --git a/entity/src/candidate.rs b/entity/src/candidate.rs index 2806e76d..81b7f72b 100644 --- a/entity/src/candidate.rs +++ b/entity/src/candidate.rs @@ -17,9 +17,9 @@ pub struct Model { pub email: Option, pub sex: Option, pub study: Option, - pub personal_identification_number: String, #[sea_orm(column_type = "Text", nullable)] - pub personal_identification_number_hash: Option, + pub personal_identification_number: Option, + pub personal_identification_number_hash: String, pub public_key: String, pub private_key: String, #[sea_orm(default_value = false)] diff --git a/migration/src/m20221024_121621_create_candidate.rs b/migration/src/m20221024_121621_create_candidate.rs index 87434289..1d0e9982 100644 --- a/migration/src/m20221024_121621_create_candidate.rs +++ b/migration/src/m20221024_121621_create_candidate.rs @@ -30,8 +30,8 @@ impl MigrationTrait for Migration { .col(ColumnDef::new(Candidate::Email).string()) .col(ColumnDef::new(Candidate::Sex).string()) .col(ColumnDef::new(Candidate::Study).string()) - .col(ColumnDef::new(Candidate::PersonalIdentificationNumber).string().not_null()) - .col(ColumnDef::new(Candidate::PersonalIdentificationNumberHash).text()) + .col(ColumnDef::new(Candidate::PersonalIdentificationNumber).string()) + .col(ColumnDef::new(Candidate::PersonalIdentificationNumberHash).text().not_null()) .col(ColumnDef::new(Candidate::PublicKey).string().not_null()) .col(ColumnDef::new(Candidate::PrivateKey).string().not_null()) .col(ColumnDef::new(Candidate::IsAdmin).boolean().not_null().default(false))