fix: update hash, remove structs

This commit is contained in:
EETagent 2022-11-05 17:00:04 +01:00
parent 2bd112beb8
commit 7bdec2482e
5 changed files with 30 additions and 21 deletions

View file

@ -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())

View file

@ -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::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),
@ -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());

View file

@ -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()

View file

@ -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)]

View file

@ -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))