refactor: use generate_candidate_token

This commit is contained in:
Sebastian Pravda 2022-10-25 22:00:48 +02:00
parent ad4fe123e4
commit a2d1447c2d
No known key found for this signature in database
GPG key ID: F3BC84F08EFA3F57

View file

@ -1,7 +1,7 @@
use jsonwebtoken::{Header, EncodingKey};
use sea_orm::DatabaseConnection;
use crate::{crypto, Query, token::candidate_token::CandidateToken, error::{ServiceError, USER_NOT_FOUND_ERROR, INVALID_CREDENTIALS_ERROR, JWT_ERROR, DB_ERROR}};
use crate::{crypto, Query, token::{candidate_token::CandidateToken, generate_candidate_token}, error::{ServiceError, USER_NOT_FOUND_ERROR, INVALID_CREDENTIALS_ERROR, JWT_ERROR, DB_ERROR}};
pub struct CandidateService;
@ -23,19 +23,8 @@ impl CandidateService {
return Err(INVALID_CREDENTIALS_ERROR)
}
let payload = CandidateToken::generate("candidate.name.unwrap()".to_owned(),
"candidate.surname.unwrap()".to_owned());
let jwt = jsonwebtoken::encode(
&Header::default(),
&payload,
&EncodingKey::from_secret(&[0])
).ok();
match jwt {
Some(jwt) => Ok(jwt),
None => Err(JWT_ERROR)
}
let jwt = generate_candidate_token(candidate); // TODO better error handling
Ok(jwt)
}
}