Skip to content

Commit

Permalink
fix: update hash, remove structs
Browse files Browse the repository at this point in the history
  • Loading branch information
EETagent committed Nov 5, 2022
1 parent 2bd112b commit 7bdec24
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion core/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
39 changes: 24 additions & 15 deletions core/src/database/mutation/candidate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Mutation, services::candidate_service::{AddUserDetailsForm, EncryptedAddUserData}};
use crate::{Mutation};

use ::entity::candidate::{self, Model};
use sea_orm::{*};
Expand All @@ -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::Model, DbErr> {
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),
Expand All @@ -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<candidate::Model, sea_orm::DbErr> {
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());

Expand Down
2 changes: 1 addition & 1 deletion core/src/database/query/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions entity/src/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pub struct Model {
pub email: Option<String>,
pub sex: Option<String>,
pub study: Option<String>,
pub personal_identification_number: String,
#[sea_orm(column_type = "Text", nullable)]
pub personal_identification_number_hash: Option<String>,
pub personal_identification_number: Option<String>,
pub personal_identification_number_hash: String,
pub public_key: String,
pub private_key: String,
#[sea_orm(default_value = false)]
Expand Down
4 changes: 2 additions & 2 deletions migration/src/m20221024_121621_create_candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 7bdec24

Please sign in to comment.