summaryrefslogtreecommitdiffstats
path: root/src/routes/auth.rs
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-09-03 10:10:20 +0000
committerSanto Cariotti <santo@dcariotti.me>2022-09-03 10:10:20 +0000
commit2c6434e0b89e93ab6bdddb28bcd059b48638cb0d (patch)
tree34844dc8d86780d25261c9082cf715226696c6ab /src/routes/auth.rs
parent6cda1b704d1c38fc116e59a2a206c2adebfb6d4d (diff)
Users has username and use it for login
Diffstat (limited to 'src/routes/auth.rs')
-rw-r--r--src/routes/auth.rs10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/routes/auth.rs b/src/routes/auth.rs
index 37c41b2..b667b97 100644
--- a/src/routes/auth.rs
+++ b/src/routes/auth.rs
@@ -1,7 +1,7 @@
use crate::errors::AppError;
use crate::models::{
- auth::{AuthBody, Claims},
- user::{User, UserCreate},
+ auth::{AuthBody, Claims, LoginCredentials},
+ user::User,
};
use axum::{routing::post, Json, Router};
@@ -12,14 +12,14 @@ pub fn create_route() -> Router {
/// Make login. Check if a user with the email and password passed in request body exists into the
/// database
-async fn make_login(Json(payload): Json<UserCreate>) -> Result<Json<AuthBody>, AppError> {
- let user = User::new(payload.email, payload.password);
+async fn make_login(Json(payload): Json<LoginCredentials>) -> Result<Json<AuthBody>, AppError> {
+ let user = User::new(String::new(), payload.username, payload.password);
match User::find(user).await {
Ok(user) => {
let claims = Claims::new(user.id);
let token = claims.get_token()?;
Ok(Json(AuthBody::new(token)))
}
- Err(_) => Err(AppError::NotFound),
+ Err(_) => Err(AppError::NotFound("User not found".to_string())),
}
}