Start on the client module
This commit is contained in:
parent
20b214df10
commit
1c4894df9a
39
visions/ui/src/client.rs
Normal file
39
visions/ui/src/client.rs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
use gloo_net::http::Request;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
enum AuthResponse {
|
||||||
|
Ok(SessionId),
|
||||||
|
PasswordReset(SessionId),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct SessionId(String);
|
||||||
|
|
||||||
|
enum ClientError {
|
||||||
|
Unauthorized,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct UserId(String);
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct UserInfo {
|
||||||
|
id: UserId,
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
trait Client {
|
||||||
|
async fn auth(username: String, password: String) -> Result<AuthResponse, ClientError>;
|
||||||
|
async fn list_users(session_id: SessionId) -> Result<Vec<UserInfo>, ClientError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Client for Connection {
|
||||||
|
async fn auth(username: String, password: String) -> Result<AuthResponse, ClientError> {
|
||||||
|
let request = Request::post("http://localhost:8001")
|
||||||
|
.body().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn list_users(session_id: SessionId) -> Result<Vec<UserInfo>, ClientError> {
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,9 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
|
|
||||||
|
mod client;
|
||||||
|
pub use client::*;
|
||||||
|
|
||||||
struct AuthInfo {
|
struct AuthInfo {
|
||||||
session_id: Option<String>,
|
session_id: Option<String>,
|
||||||
}
|
}
|
||||||
@ -44,12 +47,12 @@ fn Login(LoginProps { on_click }: &LoginProps) -> Html {
|
|||||||
};
|
};
|
||||||
html! {
|
html! {
|
||||||
<div class="login-form">
|
<div class="login-form">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h1>{"Welcome to Visions VTT"}</h1>
|
<h1>{"Welcome to Visions VTT"}</h1>
|
||||||
<input type="text" name="username" placeholder="username" />
|
<input type="text" name="username" placeholder="username" />
|
||||||
<input type="password" name="password" placeholder="password" />
|
<input type="password" name="password" placeholder="password" />
|
||||||
<button onclick={on_click}>{"Login"}</button>
|
<button onclick={on_click}>{"Login"}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user