Auth using TUI
This commit is contained in:
parent
4e6ef75c06
commit
fdcec0f302
15
src/main.rs
15
src/main.rs
@ -1,10 +1,19 @@
|
|||||||
|
mod auth;
|
||||||
mod tui;
|
mod tui;
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
use std::io;
|
||||||
|
|
||||||
|
fn main() -> io::Result<()> {
|
||||||
let (username, password) = tui::run()?;
|
let (username, password) = tui::run()?;
|
||||||
|
|
||||||
println!("user = {username}");
|
match auth::authenticate(&username, &password) {
|
||||||
println!("pass = {password}");
|
Ok(()) => {
|
||||||
|
println!("authentication successful");
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
println!("authentication failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
11
src/tui.rs
11
src/tui.rs
@ -36,7 +36,7 @@ pub fn run() -> io::Result<(String, String)> {
|
|||||||
let user = Paragraph::new(username.as_str())
|
let user = Paragraph::new(username.as_str())
|
||||||
.block(Block::default().borders(Borders::ALL).title("User"))
|
.block(Block::default().borders(Borders::ALL).title("User"))
|
||||||
.style(if focus == 0 {
|
.style(if focus == 0 {
|
||||||
Style::new().fg(Color::from_u32(0x00235759))
|
Style::new().fg(Color::from_u32(0x00_235759))
|
||||||
} else {
|
} else {
|
||||||
Style::default()
|
Style::default()
|
||||||
});
|
});
|
||||||
@ -44,7 +44,7 @@ pub fn run() -> io::Result<(String, String)> {
|
|||||||
let pass = Paragraph::new(password.as_str())
|
let pass = Paragraph::new(password.as_str())
|
||||||
.block(Block::default().borders(Borders::ALL).title("Password"))
|
.block(Block::default().borders(Borders::ALL).title("Password"))
|
||||||
.style(if focus == 1 {
|
.style(if focus == 1 {
|
||||||
Style::new().fg(Color::from_u32(0x00235759))
|
Style::new().fg(Color::from_u32(0x00_235759))
|
||||||
} else {
|
} else {
|
||||||
Style::default()
|
Style::default()
|
||||||
});
|
});
|
||||||
@ -57,7 +57,12 @@ pub fn run() -> io::Result<(String, String)> {
|
|||||||
match key.code {
|
match key.code {
|
||||||
KeyCode::Esc => break,
|
KeyCode::Esc => break,
|
||||||
KeyCode::Tab => focus = (focus + 1) % 2,
|
KeyCode::Tab => focus = (focus + 1) % 2,
|
||||||
KeyCode::Enter => break,
|
KeyCode::Enter => {
|
||||||
|
if !username.is_empty() && !password.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KeyCode::Backspace => {
|
KeyCode::Backspace => {
|
||||||
if focus == 0 {
|
if focus == 0 {
|
||||||
username.pop();
|
username.pop();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user