- fix: issue where login failed to return the user if their role was null
- add: register route for api-service - update: spawn a thread for the rest api in the api service
This commit is contained in:
@@ -6,7 +6,7 @@ use crate::users::{hash_password, verify_user};
|
||||
use chrono::{Duration, Utc};
|
||||
use rand::Rng;
|
||||
use tonic::{Request, Response, Status};
|
||||
use tracing::{info, warn};
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
pub struct MyAuthService<T: DatabaseClientTrait + Clone> {
|
||||
pub db_client: T,
|
||||
@@ -62,11 +62,19 @@ impl<T: DatabaseClientTrait + Send + Sync + Clone + 'static> AuthService for MyA
|
||||
let hashed_password = hash_password(&req.password);
|
||||
|
||||
// Create user in the database
|
||||
let user = self.db_client.clone().create_user(&req.username, &req.email, &hashed_password)
|
||||
.await
|
||||
.map_err(|e| Status::internal(format!("Database error: {}", e)))?;
|
||||
let result = self.db_client.clone().create_user(&req.username, &req.email, &hashed_password)
|
||||
.await;
|
||||
|
||||
Ok(Response::new(RegisterResponse { user_id: user.user_id }))
|
||||
match result {
|
||||
Ok(user) => Ok(Response::new(RegisterResponse {
|
||||
user_id: user.user_id,
|
||||
message: "User registered successfully".into(),
|
||||
})),
|
||||
Err(e) => {
|
||||
error!("Failed to register user: {:?}", e);
|
||||
Err(Status::internal("Failed to register user"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn request_password_reset(
|
||||
|
||||
@@ -21,7 +21,6 @@ pub fn verify_password(password: &str, hash: &str) -> bool {
|
||||
|
||||
pub async fn verify_user<T: DatabaseClientTrait>(mut db_client: T,
|
||||
username: &str, password: &str) -> Option<String> {
|
||||
// Placeholder: Replace with a gRPC call to the Database Service
|
||||
let user = db_client.get_user_by_username(username).await.ok()?;
|
||||
|
||||
if verify_password(password, &user.hashed_password) {
|
||||
|
||||
Reference in New Issue
Block a user