we compiled
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
// src/auth/handlers/register.rs
|
||||
|
||||
use bcrypt::{hash, DEFAULT_COST};
|
||||
use tonic::{Request, Response, Status};
|
||||
use uuid::Uuid;
|
||||
use crate::{auth::{models::{RegisterRequest, AuthResponse, AuthError}, db::PgPool}};
|
||||
use common::proto::multieko2::auth::{auth_service_server, RegisterRequest, AuthResponse};
|
||||
use crate::db::PgPool;
|
||||
use crate::auth::models::AuthError;
|
||||
|
||||
pub struct AuthService {
|
||||
pool: PgPool,
|
||||
@@ -14,11 +17,11 @@ impl AuthService {
|
||||
}
|
||||
|
||||
#[tonic::async_trait]
|
||||
impl multieko2::auth::auth_service_server::AuthService for AuthService {
|
||||
impl auth_service_server::AuthService for AuthService {
|
||||
async fn register(
|
||||
&self,
|
||||
request: Request<multieko2::auth::RegisterRequest>,
|
||||
) -> Result<Response<multieko2::auth::AuthResponse>, Status> {
|
||||
request: Request<RegisterRequest>,
|
||||
) -> Result<Response<AuthResponse>, Status> {
|
||||
let payload = request.into_inner();
|
||||
|
||||
// Validate passwords match
|
||||
@@ -51,10 +54,10 @@ impl multieko2::auth::auth_service_server::AuthService for AuthService {
|
||||
}
|
||||
})?;
|
||||
|
||||
Ok(Response::new(multieko2::auth::AuthResponse {
|
||||
Ok(Response::new(AuthResponse {
|
||||
id: user.id.to_string(),
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
email: user.email.unwrap_or_default(),
|
||||
role: user.role,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1,26 +1,19 @@
|
||||
// src/auth/models.rs
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Validate, Deserialize)]
|
||||
pub struct RegisterRequest {
|
||||
#[validate(length(min = 3, max = 30))]
|
||||
#[validate(length(min = 1, max = 30))]
|
||||
pub username: String,
|
||||
#[validate(email)]
|
||||
pub email: String,
|
||||
#[validate(length(min = 8))]
|
||||
#[validate(length(min = 1))]
|
||||
pub password: String,
|
||||
pub password_confirmation: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct AuthResponse {
|
||||
pub id: Uuid,
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub role: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum AuthError {
|
||||
#[error("Passwords do not match")]
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// src/db.rs
|
||||
use sqlx::postgres::{PgPool, PgPoolOptions};
|
||||
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
pub use sqlx::postgres::PgPool;
|
||||
use std::time::Duration;
|
||||
use tracing::info;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user