Add anyhow, Improve Auth token code
Moved test helper code to its own module.
This commit is contained in:
@@ -32,6 +32,7 @@ pub async fn login(
|
||||
user_dao: web::Data<Box<dyn UserDao>>,
|
||||
) -> HttpResponse {
|
||||
debug!("Logging in: {}", creds.username);
|
||||
|
||||
if let Some(user) = user_dao.get_user(&creds.username, &creds.password) {
|
||||
let claims = Claims {
|
||||
sub: user.id.to_string(),
|
||||
@@ -43,6 +44,7 @@ pub async fn login(
|
||||
&EncodingKey::from_secret(secret_key().as_bytes()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
HttpResponse::Ok().json(Token { token: &token })
|
||||
} else {
|
||||
error!(
|
||||
@@ -56,7 +58,7 @@ pub async fn login(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::database::testhelpers::{BodyReader, TestUserDao};
|
||||
use crate::testhelpers::{BodyReader, TestUserDao};
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_login_reports_200_when_user_exists() {
|
||||
|
||||
Reference in New Issue
Block a user