Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ced1a36d4 | ||
|
|
45fff34c4c | ||
|
|
c84fa4a692 | ||
|
|
eba3f56ba3 | ||
|
|
71ab588c16 | ||
|
|
195375c083 | ||
|
|
34dafcc23e | ||
|
|
507f86fcf1 |
6
client/src/components/auth.rs
Normal file
6
client/src/components/auth.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// src/components/form.rs
|
||||||
|
pub mod login;
|
||||||
|
pub mod register;
|
||||||
|
|
||||||
|
pub use login::*;
|
||||||
|
pub use register::*;
|
||||||
111
client/src/components/auth/login.rs
Normal file
111
client/src/components/auth/login.rs
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
// src/components/login/login.rs
|
||||||
|
use ratatui::{
|
||||||
|
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
|
||||||
|
style::Style,
|
||||||
|
text::{Line, Span, Text},
|
||||||
|
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||||
|
Frame,
|
||||||
|
};
|
||||||
|
use crate::config::colors::themes::Theme;
|
||||||
|
|
||||||
|
pub struct LoginState {
|
||||||
|
pub fields: Vec<String>,
|
||||||
|
pub values: Vec<String>,
|
||||||
|
pub selected_field: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LoginState {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
fields: vec!["Username".to_string(), "Password".to_string()],
|
||||||
|
values: vec![String::new(), String::new()],
|
||||||
|
selected_field: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn next_field(&mut self) {
|
||||||
|
self.selected_field = (self.selected_field + 1) % self.fields.len();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn previous_field(&mut self) {
|
||||||
|
self.selected_field = if self.selected_field == 0 {
|
||||||
|
self.fields.len() - 1
|
||||||
|
} else {
|
||||||
|
self.selected_field - 1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn render(&mut self, f: &mut Frame, area: Rect, theme: &Theme) {
|
||||||
|
let block = Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.border_type(BorderType::Rounded)
|
||||||
|
.border_style(Style::default().fg(theme.accent))
|
||||||
|
.style(Style::default().bg(theme.bg));
|
||||||
|
|
||||||
|
let inner_area = block.inner(area);
|
||||||
|
f.render_widget(block, area);
|
||||||
|
|
||||||
|
let chunks = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints([
|
||||||
|
Constraint::Length(3),
|
||||||
|
Constraint::Length(5),
|
||||||
|
Constraint::Min(1),
|
||||||
|
])
|
||||||
|
.split(inner_area);
|
||||||
|
|
||||||
|
// Title
|
||||||
|
let title = Line::from(Span::styled("Login", Style::default().fg(theme.highlight)));
|
||||||
|
let title_widget = Paragraph::new(title).alignment(Alignment::Center);
|
||||||
|
f.render_widget(title_widget, chunks[0]);
|
||||||
|
|
||||||
|
// Login form
|
||||||
|
let form_chunks = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints([
|
||||||
|
Constraint::Length(3),
|
||||||
|
Constraint::Length(3),
|
||||||
|
Constraint::Length(3),
|
||||||
|
])
|
||||||
|
.split(chunks[1]);
|
||||||
|
|
||||||
|
// Username field
|
||||||
|
let username_block = Block::default()
|
||||||
|
.title("Username")
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.border_style(if self.selected_field == 0 {
|
||||||
|
Style::default().fg(theme.highlight)
|
||||||
|
} else {
|
||||||
|
Style::default().fg(theme.border)
|
||||||
|
});
|
||||||
|
let username = Paragraph::new(self.values[0].as_str())
|
||||||
|
.block(username_block);
|
||||||
|
f.render_widget(username, form_chunks[0]);
|
||||||
|
|
||||||
|
// Password field
|
||||||
|
let password_block = Block::default()
|
||||||
|
.title("Password")
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.border_style(if self.selected_field == 1 {
|
||||||
|
Style::default().fg(theme.highlight)
|
||||||
|
} else {
|
||||||
|
Style::default().fg(theme.border)
|
||||||
|
});
|
||||||
|
let password = Paragraph::new("*".repeat(self.values[1].len()))
|
||||||
|
.block(password_block);
|
||||||
|
f.render_widget(password, form_chunks[1]);
|
||||||
|
|
||||||
|
// Submit button
|
||||||
|
let submit_block = Block::default()
|
||||||
|
.borders(Borders::ALL)
|
||||||
|
.border_style(if self.selected_field == 2 {
|
||||||
|
Style::default().fg(theme.highlight)
|
||||||
|
} else {
|
||||||
|
Style::default().fg(theme.border)
|
||||||
|
});
|
||||||
|
let submit = Paragraph::new("Submit")
|
||||||
|
.block(submit_block)
|
||||||
|
.alignment(Alignment::Center);
|
||||||
|
f.render_widget(submit, form_chunks[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
0
client/src/components/auth/register.rs
Normal file
0
client/src/components/auth/register.rs
Normal file
@@ -6,7 +6,7 @@ use ratatui::{
|
|||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use crate::config::colors::themes::Theme;
|
use crate::config::colors::themes::Theme;
|
||||||
use crate::ui::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::components::handlers::canvas::render_canvas;
|
use crate::components::handlers::canvas::render_canvas;
|
||||||
|
|
||||||
pub fn render_form(
|
pub fn render_form(
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use ratatui::{
|
|||||||
prelude::Alignment,
|
prelude::Alignment,
|
||||||
};
|
};
|
||||||
use crate::config::colors::themes::Theme;
|
use crate::config::colors::themes::Theme;
|
||||||
use crate::ui::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
|
|
||||||
pub fn render_canvas(
|
pub fn render_canvas(
|
||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// src/components/handlers/intro.rs
|
// src/components/intro/intro.rs
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||||
style::Style,
|
style::Style,
|
||||||
@@ -33,7 +33,7 @@ impl IntroState {
|
|||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Percentage(35),
|
Constraint::Percentage(35),
|
||||||
Constraint::Length(5),
|
Constraint::Length(7), // Increased to accommodate 3 buttons
|
||||||
Constraint::Percentage(35),
|
Constraint::Percentage(35),
|
||||||
])
|
])
|
||||||
.split(inner_area);
|
.split(inner_area);
|
||||||
@@ -48,10 +48,14 @@ impl IntroState {
|
|||||||
.alignment(Alignment::Center);
|
.alignment(Alignment::Center);
|
||||||
f.render_widget(title_para, chunks[1]);
|
f.render_widget(title_para, chunks[1]);
|
||||||
|
|
||||||
// Buttons
|
// Buttons - now with 3 options
|
||||||
let button_area = Layout::default()
|
let button_area = Layout::default()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
|
.constraints([
|
||||||
|
Constraint::Percentage(33),
|
||||||
|
Constraint::Percentage(33),
|
||||||
|
Constraint::Percentage(33),
|
||||||
|
])
|
||||||
.split(chunks[1].inner(Margin {
|
.split(chunks[1].inner(Margin {
|
||||||
horizontal: 1,
|
horizontal: 1,
|
||||||
vertical: 1
|
vertical: 1
|
||||||
@@ -71,6 +75,13 @@ impl IntroState {
|
|||||||
self.selected_option == 1,
|
self.selected_option == 1,
|
||||||
theme,
|
theme,
|
||||||
);
|
);
|
||||||
|
self.render_button(
|
||||||
|
f,
|
||||||
|
button_area[2],
|
||||||
|
"Login",
|
||||||
|
self.selected_option == 2,
|
||||||
|
theme,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_button(&self, f: &mut Frame, area: Rect, text: &str, selected: bool, theme: &Theme) {
|
fn render_button(&self, f: &mut Frame, area: Rect, text: &str, selected: bool, theme: &Theme) {
|
||||||
@@ -100,11 +111,23 @@ impl IntroState {
|
|||||||
f.render_widget(button, area);
|
f.render_widget(button, area);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next_option(&mut self) {
|
pub fn next_option(&mut self) {
|
||||||
self.selected_option = (self.selected_option + 1) % 2;
|
self.selected_option = (self.selected_option + 1) % 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn previous_option(&mut self) {
|
pub fn previous_option(&mut self) {
|
||||||
self.selected_option = if self.selected_option == 0 { 1 } else { 0 };
|
self.selected_option = if self.selected_option == 0 { 2 } else { self.selected_option - 1 };
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle_selection(&self, app_state: &mut crate::state::state::AppState) {
|
||||||
|
match self.selected_option {
|
||||||
|
0 => { /* Continue logic */ }
|
||||||
|
1 => { /* Admin logic */ }
|
||||||
|
2 => {
|
||||||
|
app_state.ui.show_intro = false;
|
||||||
|
app_state.ui.show_login = true;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ pub mod intro;
|
|||||||
pub mod admin;
|
pub mod admin;
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod form;
|
pub mod form;
|
||||||
|
pub mod auth;
|
||||||
|
|
||||||
pub use handlers::*;
|
pub use handlers::*;
|
||||||
pub use intro::*;
|
pub use intro::*;
|
||||||
pub use admin::*;
|
pub use admin::*;
|
||||||
pub use common::*;
|
pub use common::*;
|
||||||
pub use form::*;
|
pub use form::*;
|
||||||
|
pub use auth::*;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::config::binds::config::Config;
|
|||||||
use crate::tui::terminal::grpc_client::GrpcClient;
|
use crate::tui::terminal::grpc_client::GrpcClient;
|
||||||
use crate::tui::terminal::core::TerminalCore;
|
use crate::tui::terminal::core::TerminalCore;
|
||||||
use crate::tui::controls::commands::CommandHandler;
|
use crate::tui::controls::commands::CommandHandler;
|
||||||
use crate::ui::handlers::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest};
|
use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest};
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::tui::terminal::{
|
|||||||
grpc_client::GrpcClient,
|
grpc_client::GrpcClient,
|
||||||
};
|
};
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::ui::handlers::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::modes::canvas::common;
|
use crate::modes::canvas::common;
|
||||||
|
|
||||||
pub async fn handle_edit_event_internal(
|
pub async fn handle_edit_event_internal(
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use crossterm::event::{KeyEvent};
|
use crossterm::event::{KeyEvent};
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::ui::handlers::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::config::binds::key_sequences::KeySequenceTracker;
|
use crate::config::binds::key_sequences::KeySequenceTracker;
|
||||||
use crate::tui::terminal::grpc_client::GrpcClient;
|
use crate::tui::terminal::grpc_client::GrpcClient;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
||||||
use crate::tui::terminal::grpc_client::GrpcClient;
|
use crate::tui::terminal::grpc_client::GrpcClient;
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::ui::handlers::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::tui::controls::commands::CommandHandler;
|
use crate::tui::controls::commands::CommandHandler;
|
||||||
use crate::tui::terminal::core::TerminalCore;
|
use crate::tui::terminal::core::TerminalCore;
|
||||||
use crate::modes::{
|
use crate::modes::{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use crossterm::event::KeyEvent;
|
use crossterm::event::KeyEvent;
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
use crate::ui::handlers::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
|
|
||||||
pub async fn handle_navigation_event(
|
pub async fn handle_navigation_event(
|
||||||
key: KeyEvent,
|
key: KeyEvent,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crate::tui::terminal::{
|
|||||||
};
|
};
|
||||||
use crate::tui::controls::commands::CommandHandler;
|
use crate::tui::controls::commands::CommandHandler;
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::ui::handlers::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::ui::handlers::rat_state::UiStateHandler;
|
use crate::ui::handlers::rat_state::UiStateHandler;
|
||||||
use crate::modes::{
|
use crate::modes::{
|
||||||
common::{command_mode},
|
common::{command_mode},
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
// src/state/mod.rs
|
// src/state/mod.rs
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
pub mod pages;
|
||||||
|
|||||||
3
client/src/state/pages.rs
Normal file
3
client/src/state/pages.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// src/state/pages.rs
|
||||||
|
|
||||||
|
pub mod form;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// src/client/ui/handlers/form.rs
|
// src/state/pages/form.rs
|
||||||
use crate::config::colors::themes::Theme;
|
use crate::config::colors::themes::Theme;
|
||||||
use ratatui::layout::Rect;
|
use ratatui::layout::Rect;
|
||||||
use ratatui::Frame;
|
use ratatui::Frame;
|
||||||
@@ -11,6 +11,7 @@ pub struct UiState {
|
|||||||
pub show_intro: bool,
|
pub show_intro: bool,
|
||||||
pub show_admin: bool,
|
pub show_admin: bool,
|
||||||
pub show_form: bool,
|
pub show_form: bool,
|
||||||
|
pub show_login: bool,
|
||||||
pub intro_state: IntroState,
|
pub intro_state: IntroState,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +76,7 @@ impl Default for UiState {
|
|||||||
show_intro: true,
|
show_intro: true,
|
||||||
show_admin: false,
|
show_admin: false,
|
||||||
show_form: false,
|
show_form: false,
|
||||||
|
show_login: false,
|
||||||
intro_state: IntroState::new(),
|
intro_state: IntroState::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// src/client/ui/handlers.rs
|
// src/client/ui/handlers.rs
|
||||||
|
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
pub mod form;
|
|
||||||
pub mod render;
|
pub mod render;
|
||||||
pub mod rat_state;
|
pub mod rat_state;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use crate::components::{
|
|||||||
use crate::config::colors::themes::Theme;
|
use crate::config::colors::themes::Theme;
|
||||||
use ratatui::layout::{Constraint, Direction, Layout};
|
use ratatui::layout::{Constraint, Direction, Layout};
|
||||||
use ratatui::Frame;
|
use ratatui::Frame;
|
||||||
use super::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
|
|
||||||
pub fn render_ui(
|
pub fn render_ui(
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ use crate::tui::controls::CommandHandler;
|
|||||||
use crate::tui::terminal::EventReader;
|
use crate::tui::terminal::EventReader;
|
||||||
use crate::config::colors::themes::Theme;
|
use crate::config::colors::themes::Theme;
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::ui::handlers::{form::FormState, render::render_ui};
|
use crate::ui::handlers::render::render_ui;
|
||||||
|
use crate::state::pages::form::FormState;
|
||||||
use crate::modes::handlers::event::EventHandler;
|
use crate::modes::handlers::event::EventHandler;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
use crate::components::admin::{admin_panel::AdminPanelState};
|
use crate::components::admin::{admin_panel::AdminPanelState};
|
||||||
|
|||||||
51
server/src/auth/docs/reg_log.txt
Normal file
51
server/src/auth/docs/reg_log.txt
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
❯ grpcurl -plaintext -d '{
|
||||||
|
"username": "testuser3",
|
||||||
|
"email": "test3@example.com",
|
||||||
|
"password": "your_password",
|
||||||
|
"password_confirmation": "your_password"
|
||||||
|
}' localhost:50051 multieko2.auth.AuthService/Register
|
||||||
|
{
|
||||||
|
"id": "96d2fd35-b39d-4c05-916a-66134453d34c",
|
||||||
|
"username": "testuser3",
|
||||||
|
"email": "test3@example.com",
|
||||||
|
"role": "accountant"
|
||||||
|
}
|
||||||
|
❯ grpcurl -plaintext -d '{
|
||||||
|
"identifier": "testuser3"
|
||||||
|
}' localhost:50051 multieko2.auth.AuthService/Login
|
||||||
|
ERROR:
|
||||||
|
Code: Unauthenticated
|
||||||
|
Message: Invalid credentials
|
||||||
|
❯ grpcurl -plaintext -d '{
|
||||||
|
"identifier": "testuser3",
|
||||||
|
"password": "your_password"
|
||||||
|
}' localhost:50051 multieko2.auth.AuthService/Login
|
||||||
|
{
|
||||||
|
"accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI5NmQyZmQzNS1iMzlkLTRjMDUtOTE2YS02NjEzNDQ1M2QzNGMiLCJleHAiOjE3NDI5ODE2MTAsInJvbGUiOiJhY2NvdW50YW50In0.78VIR3X4QZohzeI5x3xmkmqcICTusOC6PELPohMV-k8",
|
||||||
|
"tokenType": "Bearer",
|
||||||
|
"expiresIn": 86400,
|
||||||
|
"userId": "96d2fd35-b39d-4c05-916a-66134453d34c",
|
||||||
|
"role": "accountant"
|
||||||
|
}
|
||||||
|
❯ grpcurl -plaintext -d '{
|
||||||
|
"username": "testuser4",
|
||||||
|
"email": "test4@example.com"
|
||||||
|
}' localhost:50051 multieko2.auth.AuthService/Register
|
||||||
|
{
|
||||||
|
"id": "413d7ecc-f231-48af-8c5a-566b1dc2bf0b",
|
||||||
|
"username": "testuser4",
|
||||||
|
"email": "test4@example.com",
|
||||||
|
"role": "accountant"
|
||||||
|
}
|
||||||
|
❯ grpcurl -plaintext -d '{
|
||||||
|
"identifier": "test4@example.com"
|
||||||
|
}' localhost:50051 multieko2.auth.AuthService/Login
|
||||||
|
{
|
||||||
|
"accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0MTNkN2VjYy1mMjMxLTQ4YWYtOGM1YS01NjZiMWRjMmJmMGIiLCJleHAiOjE3NDI5ODE3MDEsInJvbGUiOiJhY2NvdW50YW50In0.4Hzu3tTZRNGHnBSgeCbGy2tFTl8EzpPdXBhcW8kuIc8",
|
||||||
|
"tokenType": "Bearer",
|
||||||
|
"expiresIn": 86400,
|
||||||
|
"userId": "413d7ecc-f231-48af-8c5a-566b1dc2bf0b",
|
||||||
|
"role": "accountant"
|
||||||
|
}
|
||||||
|
╭─ ~/Doc/pr/multieko2/server auth ······ ✔
|
||||||
|
╰─
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
pub mod jwt;
|
pub mod jwt;
|
||||||
pub mod middleware;
|
pub mod middleware;
|
||||||
|
// TODO implement RBAC on all of the endpoints
|
||||||
|
// pub mod rbac;
|
||||||
|
|
||||||
pub use jwt::*;
|
pub use jwt::*;
|
||||||
pub use middleware::*;
|
pub use middleware::*;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub fn init_jwt() -> Result<(), AuthError> {
|
|||||||
pub fn generate_token(user_id: Uuid, role: &str) -> Result<String, AuthError> {
|
pub fn generate_token(user_id: Uuid, role: &str) -> Result<String, AuthError> {
|
||||||
let keys = KEYS.get().ok_or(AuthError::ConfigError("JWT not initialized".to_string()))?;
|
let keys = KEYS.get().ok_or(AuthError::ConfigError("JWT not initialized".to_string()))?;
|
||||||
|
|
||||||
let exp = OffsetDateTime::now_utc() + Duration::hours(24);
|
let exp = OffsetDateTime::now_utc() + Duration::days(365000);
|
||||||
let claims = Claims {
|
let claims = Claims {
|
||||||
sub: user_id,
|
sub: user_id,
|
||||||
exp: exp.unix_timestamp(),
|
exp: exp.unix_timestamp(),
|
||||||
|
|||||||
36
server/src/auth/logic/rbac.rs
Normal file
36
server/src/auth/logic/rbac.rs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
// src/auth/logic/rbac.rs
|
||||||
|
|
||||||
|
use tower::ServiceBuilder;
|
||||||
|
use crate::auth::logic::rbac;
|
||||||
|
|
||||||
|
pub async fn run_server(db_pool: sqlx::PgPool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
// ... existing setup code ...
|
||||||
|
|
||||||
|
// Create service layers
|
||||||
|
let adresar_layer = ServiceBuilder::new()
|
||||||
|
.layer(rbac::create_adresar_layer())
|
||||||
|
.into_inner();
|
||||||
|
|
||||||
|
let uctovnictvo_layer = ServiceBuilder::new()
|
||||||
|
.layer(rbac::create_uctovnictvo_layer())
|
||||||
|
.into_inner();
|
||||||
|
|
||||||
|
// Create services with layers
|
||||||
|
let adresar_service = AdresarServer::new(AdresarService { db_pool: db_pool.clone() })
|
||||||
|
.layer(adresar_layer);
|
||||||
|
|
||||||
|
let uctovnictvo_service = UctovnictvoServer::new(UctovnictvoService { db_pool: db_pool.clone() })
|
||||||
|
.layer(uctovnictvo_layer);
|
||||||
|
|
||||||
|
// ... repeat for other services ...
|
||||||
|
|
||||||
|
Server::builder()
|
||||||
|
.add_service(auth_server)
|
||||||
|
.add_service(adresar_service)
|
||||||
|
.add_service(uctovnictvo_service)
|
||||||
|
// ... other services ...
|
||||||
|
.serve(addr)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user